Chinaunix首页 | 论坛 | 博客
  • 博客访问: 150745
  • 博文数量: 52
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 490
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-05 12:05
文章分类

全部博文(52)

文章存档

2013年(1)

2010年(3)

2009年(6)

2008年(25)

2007年(17)

我的朋友

分类: LINUX

2007-11-15 12:41:52

Tips of VI
 
Here I won’t introduce basic of VI but Tips
Command 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.
 
 
阅读(607) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~