JohnBeckett (talk | contribs) m (Reverted edits by 24.29.94.205 (talk | block) to last version by Cec) |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {{review}} |
||
{{TipImported |
{{TipImported |
||
|id=150 |
|id=150 |
||
|previous=149 |
|previous=149 |
||
|next=153 |
|next=153 |
||
− | |created= |
+ | |created=2001 |
|complexity=intermediate |
|complexity=intermediate |
||
|author=Charles E. Campbell, Jr. |
|author=Charles E. Campbell, Jr. |
||
− | |version= |
+ | |version=6.0 |
|rating=63/25 |
|rating=63/25 |
||
|category1=Usage |
|category1=Usage |
||
|category2= |
|category2= |
||
}} |
}} |
||
− | You can use the |
+ | You can use the [http://www.drchip.org/astronaut/vim/index.html#VISINCR Visual Incrementing script] to convert a block of numbers selected via Ctrl-v (visual block) into a column of increasing integers. Select the column then enter <code>:I</code> to replace the selection. The first line's number is used as a starting value, and the number in each subsequent line is incremented by one. |
− | If the |
+ | If the Ctrl-v block is "ragged right", which can happen when "$" is used to select the right hand side, the block will have spaces appended as needed to straighten it out. If the strlen of the count exceeds the visual-block allotment of spaces, then additional spaces will be inserted. |
− | Example: Put cursor on topmost zero, select column with |
+ | Example: Put cursor on topmost zero, select column with Ctrl-v, then enter <code>:I</code> |
<pre> |
<pre> |
||
vector[0] = 1; vector[0] = 1; |
vector[0] = 1; vector[0] = 1; |
||
Line 25: | Line 24: | ||
</pre> |
</pre> |
||
+ | ==See also== |
||
− | This script works with both Vim 5.7 (<tt>:so visincr.vim</tt>) or Vim 6.0 (source it as for Vim 5.7 or drop it into the .vim/plugin directory). |
||
+ | *[[Increasing or decreasing numbers]] |
||
+ | *[[Making a list of numbers]] |
||
==Comments== |
==Comments== |
||
+ | The vis.vim script at [http://www.drchip.org/astronaut/vim/index.html#VIS Visual Block Commands] can apply a substitute to a visual-block. |
||
− | <pre> |
||
− | " another way of generating incremented numbers |
||
− | "============================================================================= |
||
− | " File: increment.vim |
||
− | " Author: Stanislav Sitar |
||
− | " Put increment.vim into a plugin directory. |
||
− | " Use in replacement strings |
||
− | " :let I=0 |
||
− | " :%s/my_token_word_to_be_replaced_by_the_auto_incremented_numbers/\=INC(1)/ |
||
− | " or |
||
− | " :let I=95 |
||
− | " :%s/@/\=INC(5)/ |
||
− | " to replace each occurrence of character @ with numbers starting with 100 and |
||
− | " growing by 5 (100, 105, 110, ...) |
||
− | " |
||
− | " Instalation: save this text as increment.vim in your plugins directory |
||
− | "========================================================================= |
||
− | let g:I=0 |
||
− | function INC(increment) |
||
− | let g:I = g:I + a:increment |
||
− | return g:I |
||
− | endfunction |
||
− | </pre> |
||
---- |
---- |
||
⚫ | |||
− | Visincr.vim has been improved -- it now uses virtual column calculations which avoids problems with leading tabs -- you may even mix leading tabs and spaces, incrementing only the visually selected column. |
||
− | |||
− | ---- |
||
− | Other methods/scripts for incrementing scripts are available as: |
||
− | * Srinath Avadhanula {{script|id=156}} |
||
− | * Stanislav Sitar {{script|id=145}} |
||
− | |||
− | If you're interested in using substitute based approaches, you might wish to consider Stefan Roemer's <vis.vim>, which allows one to apply a substitute to just a visual-block. You can get a copy of his script at |
||
− | http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs -- see "Visual Block Commands". |
||
− | |||
− | ---- |
||
⚫ | |||
− | |||
<pre> |
<pre> |
||
− | :I<CR> will use the first line's number as a starting point, incrementing by 1 |
+ | :I<CR> will use the first line's number as a starting point, incrementing by 1 |
− | :I #<CR> like :I, but will increment by given number; negative numbers work fine |
+ | :I #<CR> like :I, but will increment by given number; negative numbers work fine |
− | :II<CR> will pad on left as needed, otherwise like :I |
+ | :II<CR> will pad on left as needed, otherwise like :I |
:II #<CR> like :II, but will increment by given number |
:II #<CR> like :II, but will increment by given number |
||
</pre> |
</pre> |
||
---- |
---- |
||
− | + | An additional script, calutil.vim, adds some calendrical date to/from Julian day conversion functions. With those, visincr.vim now has new commands: |
|
− | * |
+ | *<code>IMDY [incr]</code> : make a column of month/day/year dates |
− | * |
+ | *<code>IYMD [incr]</code> : make a column of year/month/day dates |
− | * |
+ | *<code>IDMY [incr]</code> : make a column of day/month/year dates |
− | * |
+ | *<code>ID [incr]</code> : make a column of day names |
− | + | The optional incr (default value is 1) can be positive or negative. Both scripts are available at [http://www.drchip.org/astronaut/vim/index.html#VimFuncs Vim Functions]. |
|
---- |
---- |
Latest revision as of 05:17, 13 July 2012
created 2001 · complexity intermediate · author Charles E. Campbell, Jr. · version 6.0
You can use the Visual Incrementing script to convert a block of numbers selected via Ctrl-v (visual block) into a column of increasing integers. Select the column then enter :I
to replace the selection. The first line's number is used as a starting value, and the number in each subsequent line is incremented by one.
If the Ctrl-v block is "ragged right", which can happen when "$" is used to select the right hand side, the block will have spaces appended as needed to straighten it out. If the strlen of the count exceeds the visual-block allotment of spaces, then additional spaces will be inserted.
Example: Put cursor on topmost zero, select column with Ctrl-v, then enter :I
vector[0] = 1; vector[0] = 1; vector[0] = 1; vector[1] = 1; vector[0] = 1; --> vector[2] = 1; vector[0] = 1; vector[3] = 1; vector[0] = 1; vector[4] = 1;
See also[]
Comments[]
The vis.vim script at Visual Block Commands can apply a substitute to a visual-block.
visincr.vim supports:
:I<CR> will use the first line's number as a starting point, incrementing by 1 :I #<CR> like :I, but will increment by given number; negative numbers work fine :II<CR> will pad on left as needed, otherwise like :I :II #<CR> like :II, but will increment by given number
An additional script, calutil.vim, adds some calendrical date to/from Julian day conversion functions. With those, visincr.vim now has new commands:
IMDY [incr]
: make a column of month/day/year datesIYMD [incr]
: make a column of year/month/day datesIDMY [incr]
: make a column of day/month/year datesID [incr]
: make a column of day names
The optional incr (default value is 1) can be positive or negative. Both scripts are available at Vim Functions.