usually I deal with files that look like this:
0.98 3.45
2.45 3.90
.
.
.
4.56 8.45
lets say 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 a first column of integers. What I usually do is to generate a column file with just the numbers 1,2...100 and then select that block and paste it into the file with two columns. As the number of rows is almost always different my approach seems to be very slow.
Do you have any suggestions?
Thanks.
Here's an alternative vim-only Normal mode version. With your cursor in the first column, on the first row:
<C-v>GI0 <ESC>gvg<C-a>
<C-v>
visual block mode (:help visual-block
)G
is select to the bottom of the screen (:help G
)I
starts insert mode on line 1 (:help v_b_I
)0
enter a literal zero and a literal space<ESC>
go back to normal modegv
reselect the last visual selection (all of column 1) (:help gv
)g<C-a>
increment sequentially all numbers in the selection (:help v_g_CTRL-A
)Turns this
0.98 3.45
2.45 3.90
4.56 8.45
into this
1 0.98 3.45
2 2.45 3.90
3 4.56 8.45
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With