Re: Number Changes

2007-02-27 Thread Charles E Campbell Jr

Mike Blonder wrote:


Hi.

I periodically need to make changes to a script built with tab  
delimited values.  What I need to do is, from time to time, to either  
add 1 to a value or to subtract 1 from the same value.  Typically the  
script looks like:


ln 1 $10 !="" { printf "((moodlook " $10 }
ln 2 $11 !="" { printf "((feeloil " $11 }
ln 3 $12 !="" { printf "((eyeflavor " $12 }
.  .  .

Is there an alternative to manually CTRL-A'ing each line twice to  
change ln 1, for example, to


#11 !="" { printf "((moodlook " $11 }



If these numbers are in columns (and you did say tab-delimited, so 
perhaps they are), then visincr.vim may be helpful.

With the visincr.vim plugin:

 Change number in upper left hand corner to what you want it to be.
  ctrl-v  to begin visual block mode with the upper left hand corner of 
column of numbers

  move cursor to lower right hand corner of column
 :I

This process will change one column of numbers.  You can get visincr from:

   http://mysite.verizon.net/astronaut/vim/index.html#VISINCR
or from
   http://vim.sourceforge.net/scripts/script.php?script_id=670

Quick overview:
  :I[#]   left justified incremented list
  :II   [# [zfill]]   right justified incremented list
  :IO   [#]   left justified octal incremented list
  :IIO  [# [zfill]]   right justified octal incremented list
  :IX   [#]   left justified hex. incremented lsit
  :IIX  [# [zfill]]   right justified hex. incremented lsit
  :IYMD [# [zfill]]   year/month/day incremented list
  :IMDY [# [zfill]]   month/day/year incremented list
  :IDMY [# [zfill]]   day/month/year incremented list
  :IA   [#]   alphameric incremented list
  :ID   [#]   dayname incremented list
  :IM   [#]   monthname incremented list

And, if your "columns" of numbers aren't aligned, but you'd like them to 
be, check out Align.vim (available at my website, too).


Regards,
Chip Campbell



Re: Number Changes

2007-02-18 Thread Tim Chase
> I periodically need to make changes to a script built with tab  
> delimited values. 

Looking at your script sample, I must be missing the tab delims...

> What I need to do is, from time to time, to either  
> add 1 to a value or to subtract 1 from the same value.  Typically the  
> script looks like:
> 
> ln 1 $10 !="" { printf "((moodlook " $10 }
> ln 2 $11 !="" { printf "((feeloil " $11 }
> ln 3 $12 !="" { printf "((eyeflavor " $12 }
> .  .  .
> 
> Is there an alternative to manually CTRL-A'ing each line twice to  
> change ln 1, for example, to
> 
> #11 !="" { printf "((moodlook " $11 }


I think you could get away with something like this one-liner
(broken into several lines for clarity)

:%s
/$\(\d\+\)\( !="" { printf "((\w* " $\)\(\d\+\)
/\=(submatch(1)+1).submatch(2).(submatch(3)+1)
/g

It should find any matches of the pattern defined in the first
line and increment each of the two numbers by 1.  Change the two
instances of "+1" to "-1" or whatever math you want to perform on
them.  If you want to ensure consistency, you can change it to

:%s
/$\(\d\+\)\( !="" { printf "((\w* " $\)\1
/\=(submatch(1)+1).submatch(2).(submatch(1)+1)
/g

This will refuse to change lines where, for some reason the first
variable is different from the second one.

If you have problems with it, or something is making you scratch
your head, write the list back with questions and I can 'splain it.

HTH,

-tim





Number Changes

2007-02-18 Thread Mike Blonder

Hi.

I periodically need to make changes to a script built with tab  
delimited values.  What I need to do is, from time to time, to either  
add 1 to a value or to subtract 1 from the same value.  Typically the  
script looks like:


ln 1 $10 !="" { printf "((moodlook " $10 }
ln 2 $11 !="" { printf "((feeloil " $11 }
ln 3 $12 !="" { printf "((eyeflavor " $12 }
.  .  .

Is there an alternative to manually CTRL-A'ing each line twice to  
change ln 1, for example, to


#11 !="" { printf "((moodlook " $11 }

.  .  .

Thanks,

Mike