Block Inserting and Deleting Text in VIM

September 6, 2012 by
Filed under: HowTo, linux, web development, windows 

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.

VIM Block Select

Affiliate Link

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.

VIM Inserting Text

When you're done, hit <Esc> and you'll see the text get added to the rest of selected lines.

VIM Block Inserted Text

Deleting  text

To delete text from several lines, again, use [Ctrl]+[v] and the navigation keys to block select the text to remove.

VIM Block Select

Now use the [x] key to delete the selected text.

VIM Block Delete

Other options

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/

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>