2005-06-02

vi 'ed

I've been using vi for quite a while now, however, never really bothered to trawl through the man pages to learn its more esoteric capabilities. Besides, the usage wasn't very high, and I resorted to the usual 'copy over to windows, modify in Word' strategy.

Now that I had some time, I've been able to explore a few things:

Search and Replace

Search: as we probably all know, a pattern can be searched by:
/search_string

Replace: (This was the tricky one for me, since I could never get it to work in the past)

:s/search_string/replace_string - replaces the first occurence of 'search_string' with 'replace_string' on the current line
:s/search_string/replace_string/g - replaces all occurences of 'search_string' with 'replace_string' on the current line
:1,$s/search_string/replace_string/g or :%s/search_string/replace_string/g - will replace all occurences of the 'search_string' with 'replace_string' in the entire file

Moving Around
h move the cursor one character to the left
j move the cursor one character down
k move the cursor one character up
l move the cursor one character to the right
0 move to the beginning of a line
$ move to the end of a line
G move to the end of a file
1G move to the first line of a file
Ctrl+F move down one screen
Ctlr+B move up one screen

No comments:

Post a Comment