Showing posts with label vi. Show all posts
Showing posts with label vi. Show all posts

Sunday, 22 May 2011

Comment multiple lines in VI

Instead of counting lines ( using: .,+N ) one could also use a search ( .,/WORDONTHELASTLINE/ ),

so:
this is line 1
this is line 2
this is line three
this is line 4
could be commented by putting the cursor on line 1 and using
:.,/three/ s/^/#/g

Possibly Related Posts

Vi: Search and Replace

Change to normal mode with <ESC>.

Search (Wraped around at end of file):

Search STRING forward :

/ STRING
Search STRING backward:

? STRING
Repeat search:

n
Repeat search in opposite direction:

N (SHIFT-n)
Replace: Same as with sed, Replace OLD with NEW:

First occurrence on current line:

:s/OLD/NEW
Globally (all) on current line:

:s/OLD/NEW/g
Between two lines #,#:

:#,#s/OLD/NEW/g
Every occurrence in file (global):
:%s/OLD/NEW/g 

Possibly Related Posts