There are times in my work where I need to edit large text files. My text editor of choice for editing large files is VIM. One of the things that I sometimes need to do is to comment out a group of lines from a file. VIM can make short work of tasks like this.
Block selecting in VIM
The first step is to make a block selection. This is where you'll choose where to insert text. I'll use an example file that looks like this:
This is line 1
This is line 2
This is line 3
Position the cursor at the beginning of the first line and hit [Ctrl]+[v] to enter Visual Select mode. Now use the arrow keys or the home row navigation keys to select the beginning character of each line.
Inserting the text
Now hit [Shift]+[I] to enter Insert Mode. You'll see the cursor jump to the first line of your selection. Enter the text you want to insert. You'll only see it get added to that first line.
When you're done, hit <Esc> and you'll see the text get added to the rest of selected lines.
To delete text from several lines, again, use [Ctrl]+[v] and the navigation keys to block select the text to remove.
Now use the [x] key to delete the selected text.
Now that you know how to block select with VIM, you can also use it to append or replace text too.
This content was originally published at http://tuxtweaks.com/2012/09/block-inserting-and-deleting-text-in-vim/