tags:

views:

94

answers:

2

I want to know how to do some operations on highlighted lines (with v operator) like providing tab to selected line, comment those line, etc. using vi/vim.

+5  A: 

Most standard operations that require a motion also work in visual mode, so if you select something in one of the visual modes (v, shift-v or ctrl-v), you can indent a line with the > key, comment those lines by pressing :s@^@# @ (which will show :'<,'>s@^@# @ on the command line as the visual range is entered automatically).

Another way of commenting out blocks is to select them with the column visual select (ctrl-v) and press I to insert at the start of the line.

:help v_>
:help visual-start
:help :s
:help I

There are also a couple of plugins here and here that help with commenting. If you want any more specific information, please can you make your question a bit more detailed as it's difficult to tell what you really want at the moment.

Al
Thanx for the help Al...
Abhimanyu
these kind of extra trik which will reduce the work effort using VI and make it easy for you to work.
Abhimanyu
+4  A: 

For indenting the selected portion of code, you can use the = command to do it automatically, or you can use the >> and << commands to increment or decrement the indenting.

Also another useful command, gv, you can use it to recover your last selection.

CMS
+1: gv is one I didn't know: very good, thanks. You can also just use :'<,'>s again and it will remember the last selection.
Al