Sunday, September 4, 2011

5. Sum useful commands in vim editor:


Where grep came from (RE being Regular Expression):
:g/RE/p

Delete lines 10 to 20 inclusive:
:10,20d
or with marks a and b:
:'a,'bd

Delete lines that contain pattern:
:g/pattern/d

Delete all empty lines:
:g/^$/d

Delete lines in range that contain pattern:
:20,30/pattern/d
or with marks a and b:
:'a,'b/pattern/d

Substitute all lines for first occurance of pattern:
:%s/pattern/new/
:1,$s/pattern/new/

Substitute all lines for pattern globally (more than once on the line):
:%s/pattern/new/g
:1,$s/pattern/new/g

Find all lines containing pattern and then append -new to the end of each line:
:%s/\(.*pattern.*\)/\1-new/g

Substitute range:
:20,30s/pattern/new/g
with marks a and b:
:'a,'bs/pattern/new/g



More info can be found in these "website1" and "website2".

No comments:

Post a Comment