Block Selecting, The Killer Feature of Vim

Without any doubts Vim is one of the best and most efficient text editors, which comes with a lot of features.

The block selecting feature of Vim is one of the many features Vim has to offer that you cannot find in most GUI based text editors as far as I know. You can use Ctrl+v to select a block of text. Using this feature not only you can remove a block of text, but also to add certain text to the selected block. For example, suppose you need to remove "django", "HTTPSS", and "webint" from all 6 lines of the following piece of code and replace them by "django_new".

from django.http import HttpResponseRedirect
from HTTPSS.core.mail import send_mail
from django.core import serializers
from webint.http import Http404
from django.http import HttpResponse

All you have to do is to place the cursor on line 1, column 6, and press Ctrl+v and select your block. By pressing x, you can delete that block from your code. In order to add "django_new" to every single line of that block, again you have to go to line 1, column 6, press Ctrl+v, select that block you want to add your new word to, press "I" and type your new word (in this case "django_new") and finally press Escape to see the magic. If you want to add a new word to the end of a selected block, you can press "A" after selecting the block instead of "I".

To me this is the killer feature of Vim that I haven't seen in other text editors, yet. I just thought someone would probably find this technique useful. Please let me know what other features of Vim you find interesting by commenting on this article.

Published On: Dec. 26, 2010 --- Views: 3285

Tags: vim block selecting

If you found this article helpful, I strongly recommend reading this article:

How to work with tabs in vim


There are 2 comment(s):

On Dec. 26, 2010, asdf says:

Or you could just select the block once with ctrl+v and press 's' to substitute, rather than selecting, deleting, selecting, inserting.

On Feb. 27, 2011, ts says:

Good article. And, this feature existed in quite a lot of editors, such as notepad++/ultraedit/visual studio....


| More

Back To The Blog Page

All Rights Reserved
Powered By Mohammad Mohtasham