Wikia

Vim Tips Wiki

Changes: Generating a column of increasing numbers

Edit

Back to page

(Clean.)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
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 <tt>:I</tt> 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.
+
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 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.
 
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 <tt>:I</tt>
+
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 42: Line 42:
 
----
 
----
 
An additional script, calutil.vim, adds some calendrical date to/from Julian day conversion functions. With those, visincr.vim now has new commands:
 
An additional script, calutil.vim, adds some calendrical date to/from Julian day conversion functions. With those, visincr.vim now has new commands:
*<tt>IMDY [incr]</tt> : make a column of month/day/year dates
+
*<code>IMDY [incr]</code> : make a column of month/day/year dates
*<tt>IYMD [incr]</tt> : make a column of year/month/day dates
+
*<code>IYMD [incr]</code> : make a column of year/month/day dates
*<tt>IDMY [incr]</tt> : make a column of day/month/year dates
+
*<code>IDMY [incr]</code> : make a column of day/month/year dates
*<tt>ID [incr]</tt> : make a column of day names
+
*<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].
 
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, July 13, 2012

Tip 150 Printable Monobook Previous Next

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 alsoEdit

CommentsEdit

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 dates
  • IYMD [incr] : make a column of year/month/day dates
  • IDMY [incr] : make a column of day/month/year dates
  • ID [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.


Around Wikia's network

Random Wiki