I wanted to add a line after every 3 lines in a file (having about 1000 lines) using vim editor. Can someone help me out?
Thanks, Alisha
in my . vimrc for years. Press Enter to insert a blank line below current, Shift + Enter to insert it above.
Press Esc . This will cause you to go back to command mode, and the text you typed will be repeated on each line before the start of your visual block selection (in this case, at the start of each line, since that's where you began the selection).
Go to the line from which you want to start commenting. Then, press ctrl + v , this will enable the visual block mode. use the down arrow to select multiple lines that you want to comment. Now, press SHIFT + I to enable insert mode.
there is a vim-specific regular expression to do that
:%s/.*\n.*\n.*\n/\0\r/g
Edit: if you want anything else than a new line, just put the text in front of the \r (properly regex escaped, if it contains some regex characters)
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