2009年5月7日星期四

Summary on Eleutian's vim tutorial

Eleutian gave a series of vim screencast tutorials , which I think it's good for beginners.

Here's summaries on the key points in his tutorials:

Tutorial 1

1. Vim is a modal editor. There are a lot of modes:
  • Normal mode: Press ESC or CRTL+[
  • Insert mode: Press i in normal mode
  • Command mode: Press : in normal mode
  • Visual mode: Press v in normal mode
  • Append mode: Press a in normal mode
2. In command mode, "e" means opening a file and "w" means saving a file.
  • :e filename : open a file whose name is "filename"
  • :e! : reopen the current file; all changes are lost
  • :w : save the current file
  • :w filename : save the current file as filename; primarily used when a file is to be saved for the first time
3. Stay in normal mode, unless you're actively typing text.
4. To move around in a most efficient way use "h", "j", "k", "l" as left, down, up, right respectively.
5. Move more quickly:
  • ^: Home; move to the head of the current line
  • $: End; move to the end of the current line
  • CRTL + D: Pagedown
  • CRTL + U: Pageup
  • w: Move to the next word
  • b: Move to the previous word
Tutorial 2
1. Move the beginning or the end of a document:
  • gg: Move to the beginning of the document
  • GG: Move to the end of the document
  • XGG: Move the Xth line of the document, like 10G(move to the 10th line)
2. Copy(yank), Cut(delete) and Paste
  • yy: Copy the whole line
  • yw: Copy the next word
  • y$: Copy till the end of line
  • x: cut the current letter
  • dd: Delete the whole line
  • dw: Delete the next word
  • p: Paste the text that just deleted or yanked
3. Change
  • cw: Change the next word
  • cb: Change the previous word
  • c$: Change till the end of line
  • ct: Change till , like ctD(change till the first occurence of letter D)
4. Swap two consecutive letter: xp

Tutorial 3
1. Search
  • :/<Pattern> : Search forward according to the <Pattern>
  • :?<Pattern> : Search backward
  • n: Go to the next occurence <Pattern>
  • p or N: Go to the previous occurence <Pattern>
2. Find
  • f<Symbol> : Find the first occurence of <Symbol>
  • ; : Go to the next occurence of the <Symbol>
  • , : Go to the previous occurence of the <Symbol>
3. Replace
  • %s/<TargetString>/<SubstituteBy>/g : % means the range is the whole text, % means substitution, is what we are looking for, is the substitution for . Don't forget the /g. For example, %s/Good/Bad/g will substitute all ocurrences of "Good" by "Bad" in the whole document.
4. Find occurences of the word under the cursor
  • # : Go to the previous occurence of the word under cursor
  • * : Go to the next occurence of the word under cursor

没有评论: