Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65065
  • 博文数量: 17
  • 博客积分: 673
  • 博客等级: 中士
  • 技术积分: 150
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 16:48
文章分类

全部博文(17)

文章存档

2012年(5)

2011年(12)

分类: LINUX

2012-08-18 22:19:15



  1> n1,n2 w !Cmd 

  2> Recording
     qa            : record keystrokes to register a
     your commands
     q             : quit recording
     ([0-9]+)@a    : execute commands (with times)
     @@            : repeat

  3> CTRL-W        : delete the word in INSERT mode

  4> CTRL-A,编辑器就把你上次在插入模式下输入的文本再输入一次

  5> CTRL-Y 命令插入光标上方的字符, CTRL-E 命令操作起来跟 CTRL-Y 一样,只不过它插入光标下方的字符。

  6>   : word completion in insert mode
        : Line complete SUPER USEFUL

  7> . 重复执行上次命令 

  8> or : lodate the editing position

  9>  input special character
      CTRL-K {char1} {char2}
  
  10> in insert mode exec execute command 
      CTRL-O CMD
      用 CTRL-O {command} 你可以在插入模式下执行任何普通模式命令。
      CTRL-O D

  11> get output from shell command 
      :r !
      :r file
      :r!ls                      : reads in output of ls (use dir on Windows)
      :r !grep "^ebay" file.txt  : read output of grep
      :20,25 !rot13              : rot13 lines 20 to 25
      :r!date                    : insert date (use  date /T on Windows)
      :.!sh                      : execute contents of current line in buffer and capture the output

  12> q:
      edit then implement the CMD from history

  13> search global: [i, ]I, ]i
      [i : Display the first line that contains the keyword under the cursor. The search starts at the beginning of the file.
      ]i : like "[i", but start at the current cursor position.
      [I : Display all lines that contain the keyword under the cursor. Filenames and line numbers are displayed for the found lines.


      macro definition: [d

  14> gD, gd
      search local

  15> /  
      Pull onto search/command line
      
      :%s///g
      / will be replaced by my previous search regular expression.

  16> To change from (DOS) to just (Unix):
      :set fileformat=unix
      :w
      
      Or to change back the other way:
      :set fileformat=dos
      :w
      
      It also works for Apple land:
      :set fileformat=mac
      :w 
  
  17> # Get output from other commands
      :r!ls.exe        : reads in output of ls
      !!date           : same thing
      :%!sort -u       : use an external program to filter content

  18> #use register to copy
      #put the thing into a, then get the thing in register
      "ay
      a
      
  19> in visual mode
      select the text and put in a register by: "ay
      then copy the content in a register by: "ap

  20>
  
  21> :r foo.txt        inserts the file foo.txt below the cursor
      :0r foo.txt       inserts the file foo.txt above the first line
      :r !ls            inserts a listing of your directory below the cursor
      :$r !pwd          inserts the current working directory below the last line 

  22> NB: Lowercase marks (a-z) are valid within one file.
      Uppercase marks (A-Z), also called file marks, are valid between files.

  23> learn the ascii value of a character by pressing g and a keys.(ga)!
      There is an ascii table in the vim-help files: :help digraph-table

  24> Basic calculations can done within vim easily by typing (insert-mode):
      STRG (=CTRL) + R followed by =

  25> delete all lines containing "profile":
      :g/profile/d
  
  26> gd, gf ...
  
  27> to search the cmd history 
      'q:' and 'his: cmd'

  28> Scrolling synchronously
      :set scrollbind

  29> Buffer Management
      :b to complete to an open buffer

  30> yank two lines into clipboard:
      "*2yy
      paste them with: "*p OR in insert mode: *

  31> remove unwanted empty lines
      :%g/^$/d
      Well, if the line contains and
      :g/^\s*$/d
      ==================
      If the line contains and and chinese character , which takes two bytes, and the ASCII is 0xA1 0xA1.
      :g/^\(\s\| \)*$/d
      
      Herein after the | I paste the ` as a chinese character'.
      :g/^[ \t|?]*$/d
      
      Note the `|?' represents a single character which ascii is 0xA1, and inputed by CTRL-VxA1
      
  32>
      {    ----  For going to the blank line above the paragraph
      }    ----  For going to the blank line below the paragraph

  33> To get rid of those ^M use:
      1,$ s/^M//gc
      or
      % s/^M//gc
      To type ^M hit ctrl+v first and then M.

      Eliminate empty lines: v/\S/d
      Eliminate spaces at the beginning of each line: %s/\s\+$//
      Eliminate spaces at the end of the each line:%s/\s\+$//
     
      change the file style by:
      :set fileformat=mac
      :set fileformat=unix

  34> decrement number: X

  35> Substitution
      :%s/fred/joe/igc           : general substitute command
      :%s/\r//g                  : delete DOS Carriage Returns (^M)
      :%s/^M$//g                 : deletr ^M
      :'a,'bg/fred/s/dick/joe/gc : VERY USEFUL
      :s/\(.*\):\(.*\)/\2 : \1/  : reverse fields separated by :

       # non-greedy matching \{-}
      :%s/^.\{-}pdf/new.pdf/     : to first pdf)
      :s/fred/a/g           : substitute "fred" with contents of register "a"
      :%s/^\(.*\)\n\1/\1$/       : delete duplicate lines
      :help /\{-}

       # multiple commands
      :%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/
      :%s/suck\|buck/loopy/gc       : ORing
      :s/__date__/\=strftime("%c")/ : insert datestring
      
      Lowercase the entire file: 
      :%s/.*/\L&/g

      Uppercase all words that are preceded by a < (i.e. opening HTML tag names):
      :%s/<\(\w*\)/<\U\1/g

  36> spell check: set spell/nospell
      [s, ]s, z=

  37> Press v to begin character-based visual selection
      or upper case V to select whole lines,
      or Ctrl-V for a vertical block.

  38> write the file with the name suffix '.new' comparing to current file
      :w %.new

  39> Global command:

      :g/one\|two/     : list lines containing "one" or "two"
      :g/^\s*$/d       : delete all blank lines
      :g/green/d       : delete all lines containing "green"
      :v/green/d       : delete all lines NOT containing "green"
      :g/one/,/two/d   : not line based
      :v/./.,/./-1join : compress empty lines

      execute shell on lines to
      :,!

      on all lines within , range and matching , execute .
      :,g//

  40> :%g/[a-z0-9]$/s/boo/table/
      on all lines in buffer that end with a lowercase letter or a digit, replace "boo" with "table"

  41> Theory: Ctrl-O in insert mode switches to normal mode for one command and then switches back to insert mode.

  42> ":e!" 
  if you messed up the buffer and want to start all over again.

  43> Instead of using "/" to search, use "?" then paste.
  You don't need to escape the frontslashes, so no need to edit the pattern.
  If you wish to search forward, just hit "/" and Enter.
  If you want to use it again, use the "?" history, not the "/".
   
  44> 
  " Fast update/reload vimrc
    To count the words in a file: g
    To count the words in a block, select the block and once again g

  45>
  Searching a word with ' * ' or ' # '
  yank whole line or some text with 'yy' or 'y$', type '/' and press

  46>
  check the file status: words, lines, ...
  g     

  47>
  1 + Ctrl-G get the edit file name with buffer.

  48> ga : Print the ascii value of the character under the cursor in decimal, hexadecimal and octal.  
     e.g.  82,  Hex 52,  Octal 122 

  49> '.       : jump to last modification line (SUPER)
      `.       : jump to exact spot in last modification line
         : retrace your movements in file (backward)
         : retrace your movements in file (forward)
      :ju(mps) : list of your movements {{help|jump-motions}}

  50> :b    : edit the buffer

  51> newline character (line ending)
       \_s   a whitespace (space or tab) or newline character
       \_^   the beginning of a line (zero width)
       \_$   the end of a line (zero width)
       \_.   any character including a newline

  52> :se[t] no{option} Toggle option: Refoo, switch it off.
      set list: Same as :print, but display unprintable characters with '^'.

  53> use \(\) and \1 like sed when substitute to avoid typos
  
  54> :set paste
  Put Vim in Paste mode.
  This is useful if you want to cut or copy some text from one window and paste it in Vim.
  This will avoid unexpected effects.

  55> Vim  ask before replace

               :%s/\/3/gc

  
  56>
  \c  #ignore case
     \C  #no ignore case
      

  
<==============================================================================>
Here Document 在vim里的妙用

vim iWork/aaa.log < 

> :%s/.*/AAAAA/g

> :wq

> EOF

当然也可以把这个here document 放进for loop里面进行复杂的文本处理。


阅读(1376) | 评论(0) | 转发(0) |
0

上一篇:awk exp

下一篇:find exp

给主人留下些什么吧!~~