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.
$ vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 9 2014 17:36:18) Included patches: 1-488 Modified by firstname.lastname@example.org Compiled by buildd@ Huge version without GUI. Features included (+) or not (-): -text trimmmed- +conceal +libcall +profile +visualextra -text trimmmed-
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:
<book id="bk111"> <author>O'Brien, Tim</author> <title>MSXML3: A Comprehensive Guide</title> <genre>Computer</genre> <price>36.95</price> <publish_date>2000-12-01</publish_date> <description>The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.</description> </book> ~ ~ -- VISUAL BLOCK -- 1,1 All
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
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