Chinaunix首页 | 论坛 | 博客
  • 博客访问: 134448
  • 博文数量: 51
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 540
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-21 12:33
文章分类

全部博文(51)

文章存档

2011年(1)

2010年(5)

2009年(1)

2008年(12)

2007年(32)

我的朋友

分类: LINUX

2007-07-21 14:59:34

VIM basic commands

  1. Cursor command

  (1). cusor move:
     k: up
     j: down
     h: left
     l: right
     w: move forward a word
     b: move backward a word
     G: move to the end of a file
 
  (2). nG: move the cursor to nth line.

  (3). Ctrl-G: report the lines and columns 
               of cusor location 
       
  (4). Ctrl-d: move down one screen

  (5). Ctrl-u: move up one screen

  2. Edit command
     i: insert before cursor
     a: insert after cursor
     r: modify current char
     cw: modify current word
     dw: delete current word.
     d$: delete from cursor to the end of line
     dd: delete whole line
     d55d: delete 55 lines
     o: begin a new line

  3. search and replace

     /: search from the begining
     n: find the next after using '/'

     ?: seach from the end
     N: find the prev after using '?'

     s: replace
     
     :set ic
     (ignore case-sensitive)
     note: after this, search will include upper-case
           and lower case

     ex:

     :2,$s/hello/he/g
     (use he to replace hello from 2th line
      to the end of file).
     :1,$s/\/usr\/bin/\/bin/g
     (/usr/bin was replaced by /bin)
     :%s/^/hello/g
     add hello at beginning of each line

     :%s/$/hello/g
     add hello at end of each line

  4. copy and paste

     yy: yank current line (copy)
     y22y: yank 22 lines
     p: paste

  5. File Commands:
   
     r: read a file and insert it info current buffer
     w: write a file
     e: edit another file

     ex:
     
     :3r file (read a file from 3rd line)
     :20,59w file ( write from 20 to 59 line to file)

  6. Esc-u: undo

  7. %: find matched bracket 

  8. display line number
     :set nu

  9. how to input ^M
      ctrl-v ctrl-m

     ex: :1,$s/^M//g(remove the ^M at the end of line)

  10. :!command: executes an external command.
      ex:
      :!ls

  11. q: quit vim
      wq: save changes before quitting.
      q!: discard all changes.

VIM advanced commands

  1. enable syntax highlight
     :syntax on(or enable)

     note: can change .vimrc for color customization.

  2. [[: go to the begining of a function
     ]]: go to the end of a function


  3. copy a region.

     press "v" then move the cursor select a region
     then use "yy" to yank this region
     then use "p" to copy   

  4. multiple windows operation(like emacs)

     split window: 
     
     :sp - split into two horizontal
     :vs - split into two vertical
     
     use Ctrl+w l(j, k, h) to switch between windows.

     :files - list all the buffers

     :bn - switch to the nth buffer
   
     :only - make the current window the only one
    
     :q - quit current buffer
     
   5. :shell - enter shell, "exit" to quit shell

   6. :make - compile(need makefile)
      :copen - check errors
 
阅读(605) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~