分类: LINUX
2007-11-15 12:41:52
Tips of VI Here I won’t introduce basic of VI but TipsCommand line mode------------
'%s/\n*\(\n\)/\1/g delete all blank lines‘:%s/^/> /’ place a '> ' at the front of every line in the buffer.‘:r /etc/passwd’ append /etc/password to the current cursor
‘:%s/:.*//g’ substitute “: to end of line” with blank ‘:3r /etc/passwd’ append /etc/password to the third line of current file‘:%s#/usr/bin#/bin#g’ substitute /usr/bin to /bin‘:g/s1/s/s2/s3/g’ substitute s2 to s3 in those lines which contain s1‘:400,500s/^/#/g’ place # at beginning of lines from 400 to 500‘%s/s1/s2/g’ substitute s1 to s2 in file‘:400,500y’ yank lines 400-500‘:400,500d’ delete lines 400-500:set nu set line number:set nonu cancel line number:syntax on high light:!shell-command execute shell command
:set ignorecase in-casesenstive when searching
:set noignorecase
ESC mode-------------Join two lines ‘J’ Change to upper case ‘~’Move to beginning of the line ‘^’Move to end of the line ‘$’Move to the bottom of the file with 'G'.Move to the top of the file with '1G 'Move to the top of the screen with 'H' or Move to the middle of the screen with 'M'Move to the end of the screen with 'L'------------'dw' deletes a word'dG' deletes to bottom of file'd)' deletes a sentence. Sentences are delimited by TWO spaces.'d%' deletes to the matching bracket, brace, or paren. Works forwards or backwards.'d''' (that's d with 2 single quotes) Deletes to the last place we jumped from. For example, find the first line to delete, place the curser on that line. Jump using a '/pattern' search. Type 'd''', the lines between those points will be deleted.'d]]' deletes the rest of the buffer'dtp' deletes through the letter p, but leaves the p'dfp' deletes to and including the letter p The search operation may be used as well:'d/pattern' deletes up to the pattern, but leaves the pattern.This principle applies to most other VI commands, such as 'y' yank, and 'c' change. Re-format text using the '!}fmt' command. This one will re-format a paragraph.'!]]fmt' does the rest of the buffer. '!)fmt' does a sentence.