For example, suppose you have the following files:
0,foo
0,bar
0, hoge
0, fuga
For this first number (in this case, 0), I would like to assign an ascending number instead.To be more specific, I would like the following text:
1,foo
2,bar
3, hoge
4, fuga
As expected, editing little by little by hand seems inefficient.If there is a good way, please let me know.
vim
For Vim 7.4.765 or later, g<C-a>
after selecting the target in visual mode generates a serial number.
Just in case, I'll write down other methods.
Number == line number is acceptable:
:%s/^\d\+/\=line(".")
If you want to start over from 1 in the selected range in visual mode:
(Shift+v and press : to automatically enter :'<,'>
)
: '<, '>s/^\d\+/\=line(".")-line("'<")+1
It's a little complicated, but it's a macro version.
<CTRL-A>:%s/^0//
ggqqyw+P<CTRL-A>0q2@q
<CTRL-A>
:%s/^0//
ggqyw+P<CTRL-A>0q
gg
) Start recording to register q (qq
)yw
) Go to the beginning of the next line (+
) Paste to the left of the cursor (P
) <C-A>
) to the cursor position number (pasted previous line number)0
)q
)2@q
@q
gg
) Start recording to register q (qq
)yw
) Go to the beginning of the next line (+
) Paste to the left of the cursor (P
) <C-A>
) to the cursor position number (pasted previous line number)0
)q
)@q
925 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
615 GDB gets version error when attempting to debug with the Presense SDK (IDE)
574 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.