最近学习Ubuntu,时常需要用Vim来查看和编辑文件,整理出下列常用的命令作为备忘录。
完整版的Vim Manual可以在 这里 找到, 也可以在打开vim之后输入命令 “:help” 来查看。
左侧是命令,右侧是简单的命令说明,在左侧的命令中 N一般都代表输入命令前可以输入的数字。
Move Command
| N h | Move to left |
| N l | Move to right |
| 0 | Move to line start |
| ^ | Move to first non-blank character in the line |
| $ | Move to line end |
| gm | Move to the middle of the screen line |
| N | | Move to column N, default to column 1 |
| N k | Move to N lines up |
| N j | Move to N lines down |
| G | Move to the last line |
| gg | Move to the first line |
| N % | Move N percentage down in the file, N must be given |
| CTRL-F | Page downwards |
| CTRL-B | Page upwards |
| z<CR> | redraw, current line at top of window |
| z. | redraw, current line at center of window |
| z- | redraw, current line at bottom of window |
Search Command
| /{pattern} | Search forward for the {pattern} |
| ?{pattern} | Search backward for the {pattern} |
| n | Repeat last search |
| N | Repeat last search in opposite direction |
| * | Search forward for the identifier under the cursor |
| # | Search backward for the identifier under the cursor |
Insert Command
| a | append text after the cursor |
| A | append text at the end of the line |
| i | insert text before the cursor |
| I | insert text before the first non-blank in the line |
| N o | open a new line below the current line, append text N times |
| N O | open a new line above the current line, append text N timesjj |
Undo and Redo
| u | undo last change |
| CTRL-R | redo last undone changes |
| U | restore last changed line |
Other
| CTRL-G | show current file name with path and cursor position |
| ga | show ascii value of character under cursor in decimal, hex and octal |
| g8 | show utf-8 encoding: show byte sequence for character under cursor in hex |
| g CTRL-G | show cursor column, line and character position |
| CTRL-C | during searches: Interrupt the search |
| CTRL-W s | split to two window |
| CTRL-W j | move to window below |
| CTRL-W k | move to window above |
| q! | quit vim and discard all changes |
| wq | quit vim and save all changes |
| w | save changes |
1929

被折叠的 条评论
为什么被折叠?



