Startup options: vi -r filename enters the buffered file lost after a crash. if filename is omitted, vi shows a list of buffered files if the -r switch is supplied. The following list of commands is not exhaustive. There are many good books that teach the others. These will get most users by quite nicely, however.
| <esc> | return to command mode; used by most change commands |
| h, j, k, l | move the cursor around. h=left, j=down, k=up, l=right |
| ^F | move forward full screen |
| ^B | move back full screen |
| ^U | move up half screen |
| ^D | move down half screen |
| ^L | clear and redraw screen (^R) |
| w | move forward to beginning of next word |
| W | move forward to beginning of next word after space |
| e | move cursor to end of word |
| E | move cursor to next space |
| $ | move cursor to end of line (3$ moves to end of third line) |
| b | move cursor to beginning of word |
| B | move cursor to previous space |
| 0 (zero) | move cursor to beginning of line |
| K | invokes the man page for the word under the cursor (may only work in VI-improved which is available for most operating systems, including MS windows). |
| [[ | goto beginning of section (use (, { or < pairs also) |
| ]] | reverse of [[ |
| G | go to indicated line # (enter number first) |
| / | search (enter string after / at bottom of screen) |
| n | find next search instance |
| N | reverse of n |
| % | find matching (, ), [, ], {, or } |
| i | insert text from current cursor position; <esc> |
| I | insert text at start of line; <esc> |
| o | opens a new line below cursor |
| O | opens a new line above cursor |
| J | joins next line to end of current line |
| r | replace character under cursor |
| R | enters replace (typeover) mode; <esc> |
| s | substitute character under cursor with one or many; <esc> |
| S | substitute whole line; <esc> |
| a | appends after cursor; <esc> |
| A | appends after current line; <esc> |
| cw | change current word starting at cursor; <esc> |
| C | change to end of line; <esc> |
| dw | delete current word starting at cursor |
| dd | delete current line; delete 3 lines (3dd) |
| D | delete to end of line |
| yy | yank data: yank 1 line (yy), yank 3 lines (3yy), yank lines below the cursor (yy) or above the cursor (yk), words (yw), from thecursor position to the end of the line (y$) or the beginning of the line(y0), characters to the right of the cursor (yl) or to the left (yh) |
| p | put data yanked with y |
| u | undo most recent change |
| . | repeat most recent change-producing command |
| ZZ | write and quit |
| Q | quit to : (ex editor prompt) |
| vi | at : to re-enter document (vi -r filename after crash) |
| wq, x | write and quit; from : prompt |
| q! | quit, ignore changes |
| wq! | force write; force quit |
| :1,$s///g :%s///g |
Search and Replace at the':' prompt
I.e.: 1,$s/search_for/replace_with/g or to replace those DOS ^M things: :1,$s/CTRL-V CTRL-M//g Don't forget the \ or CTRL-V for special characters. For easier sed syntax, use: %s///g or, as above, %s/CTRL-V CTRL-M//g |