分类: LINUX
2007-07-21 14:59:34
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.
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