Vim column with increasing number

I usually deal with files that look like this:

0.98 3.45 2.45 3.90 . . . 4.56 8.45 

allows you to talk with 100 lines. I would like to get something like this:

 1 0.98 3.45 2 2.45 3.90 . . . 100 4.56 8.45 

with the first column of integers. Usually I do this column file with numbers 1,2 ... 100, and then select this block and paste it into a file with two columns. Since the number of rows is almost always my approach seems very slow.

Do you have any suggestions?

Thanks.

+6
source share
3 answers
 :%s/^/\=printf('%-3d ', line('.')) 

Additional Information:

 :help :s\= :help printf() :help line() 
+6
source
 :%!cat -n 

- fast decision. Followed by

 :%s/^\s*//g 

he gives you what you want pretty fast.

+3
source

I find VisIncr invaluable for such operations (here is the GitHub version for those using Vundle or NeoBundle). The plugin "makes it easy to create a column to increase or decrease the number, dates or days." The following is an example of adding line numbers:

Select the first column of the file in visual block mode:

 gg<Cv>G 

Insert the start number (1 in this case) and the column separator (I accept Tab here):

 I1<Tab><Esc> 

Re-select the first column of the file:

 gv 

Run the VisIncr command to increase the number:

 :I<CR> 

You can rightfully justify numbers using another command:

 :II<CR> 

Incrementing dates, letters, hexadecimal and roman numbers is just as easy.

+2
source

Source: https://habr.com/ru/post/951675/


All Articles