These days most of the editors have some sort of facility to make same edit in multiple lines. With Visual Studio it is
Alt + down-arrow, similarly other decent text editors (sublime-text, atom and brackets) have some built-in support for multiple-cursors.
I was wondering if
vim has something of this goodness. Well vim has this support, you just need to check if your copy of
vim was built with
visualextra option or not.
1 2 3 4 5 6 7 8 9
We are looking for presence of
+visualextra option here, if present you can go into visual mode and add multiple cursors. To get this going open a file in vim, and position the cursor from where you want to start doing multiline edits. I would my cursor over to
< at first line and then press
Ctrl+V (assuming it is not mapped to paste) to move to block selection mode. Then press
10 times (i want to comment 10 lines) or press
down-arrow key so many times. While doing all this
vim will show that i am in
VISUAL BLOCK selecion mode:
1 2 3 4 5 6 7 8 9 10 11 12 13
Once you have 10 lines highlighted, press
I character to go into insert mode (
-- VISUAL BLOCK -- should change to
-- INSERT --) and enter
# character and then hit
Esc key. All lines will be commented out, now you can do multiline comment in ruby with
=end, so this was contrived example- but there are many situations where you want to append or prepend some text to existing variable- there it comes handy.
Note: vim can insert multiple cursors anywhere (as you specify with motion commands). That’s all for now
StackOverflow and Vim Wikia are generally pretty handy about such things.