Reputation: 186
I want to edit multiple lines in VIM.I know there exists Visual block editing(i.e CTRL+V ----> I -----> <Make required change> -----> ESC). But Surprisingly it is not working for the case of entering a new line.
For example I want to make the following code
if(i==1):
if(i==2):
to something like
if(i==1):
print("say Hello")
if(i==2):
print("say Hello")
Hoping for a way to do it without too many commands. Thanks in advance. :)
Upvotes: 1
Views: 480
Reputation: 196476
The simplest approach is to use :help .
…
Open a new line below the first line and type what you need:
o print("say Hello")
Leave insert mode:
<Esc>
Move the cursor down by one line:
j
And repeat the last edit:
.
In short:
o print("say Hello")<Esc>j.
If you absolutely want to use visual mode, here is another way:
Select the lines:
vj
Press :
to enter command-line mode, with the range corresponding to the visual selection automatically inserted for you:
:'<,'>
Use :help :s
to substitute the EOL with a newline followed by the desired text on each line in the range:
:'<,'>s/$/\r print("say Hello")<CR>
Upvotes: 1