About vim
Vim command
| Command | function |
|---|---|
| :w | Save 保存文件 |
| :q | Exit 退出vim |
| :q! | Forcefully exit Vim without saving 强制退出vim,不保存文件 |
| :wq | Save and exit 保存并退出 |
| gg | Navigate to the beginning of the file. ‘:1’ the same thing 跳到文件的第一行 |
| :10 | Navigate to line 10 in the file 跳到文件的第10行 |
| shift + g | Navigate to the last line in the file 跳到文件的最后一行 |
| shift + d | Erase the text from the cursor position to the end of the line 删除当前光标到行尾的内容 |
| gd | Navigate to the definition of the variable at the cursor (function) 跳到光标所在变量的定义(函数内) |
| gD | Navigate to the initial appearance of the variable at the cursor position 跳到光标所在变量第一次出现的地方 |
| gf | Modify the file corresponding to the cursor’s location 编辑光标所在位置对应的文件 |
| gF | Edit the file corresponding to the current cursor position and navigate to the line number following the file name 编辑光标所在位置对应的文件,并跳到文件名后的行号 |
| dd | Delete the current line 删除当前行 |
| :10,20d | Delete the content from line 10 to line 20 in the file 删除文件的第10行到第20行的内容 |
| :%d | Clear the contents of the file 清空文件内容 |
| yy | Copy the current line 复制当前行 |
| p | Paste the copied content to the next line 粘贴复制的内容到下一行 |
| shift + P | Paste the copied content to the next line 粘贴复制的内容到下一行 |
| u | Undo 回退修改 |
| ctrl + r | Back 撤销回退 |
| i | Insert at the cursor position 光标位置插入 |
| a | Append at the cursor position 光标位置追加 |
| o | Move to the next line 向下换行 |
| shift + o | Move to the previous line 向上换行 |
| ctrl + o, ctrl + o | Open the most recently edited file 打开最近一次编辑的文件 |
| :e xxx | Edit 编辑文件xxx |
| :f | View the filename of the current file 查看当前文件的文件名 |
| :pwd | View the absolute path of the current file 查看当前文件的绝对路径 |
| :shell | Enter the command line 进入控制台界面执行shell命令,exit返回vim |
| /xxx | Find characters downward 向下匹配xxx字符,N向下查找,shift + N向上查找 |
| ?xxx | Find characters upward 向上匹配xxx字符,N向上查找,shift + N向下查找 |
| :set hls | Enable search highlighting 设置高亮搜索 |
| :set nohls | Disable search highlighting 取消高亮搜索 |
| :set nu | Show line numbers 设置显示行号 |
| :set nonu | Hide line numbers 取消显示行号 |
| :set paste | Paste mode, do not format copied content 粘贴模式,不格式化拷贝的内容 |
| :%s/xxx/yyy/g | Search and replace 全局匹配替换,将xxx全部替换为yyy |
| :bro ol | View recently opened files 查看最近打开的文件 |
| :set ff | Fileformat,查看文件格式 |
| :set ff=unix | Set the file format to unix 设置文件格式为unix |
| :sp | Splitting vertically 上下分屏 |
| :vsp | Splitting horizontally 左右分屏 |
| ctrl + w | Switching between splits 切换分屏 |
| ctrl + e | Scrolling down 向下滚屏 |
| ctrl + y | Scrolling up 向上滚屏 |
| ctrl + x, ctrl + i | Keyword completion 关键字补全,只匹配当前文件中的关键字及include指定头文件中的关键字 |
| ctrl + x, ctrl + f | File name completion 文件名补全 |
| ctrl + x, ctrl + ] | Keyword completion 关键字补全,匹配ctags文件中的关键字 |
| :!ctags -R . | Generate a tags file recursively in the current directory 当前目录下递归生成tags文件 |
| :set tags=xxx | To use ‘xxx’ as the tag file in Vim 使用xxx作为vim使用tag文件 |
| ctrl + ] | Jump to the first matching tag 跳转到第一个匹配的tag |
| :tn | Tag next,多个tag匹配中时,跳转到下一个tag |
| :ts | Tag select,列出匹配中的tag列表 |
| =G | Auto-indent the current line to the end of the file 自动缩进当前行至文件最后一行的内容 |
| == | Auto-indent the current line 自动缩进当前行 |
| 10== | Auto-indent the current line and the next 10 lines 自动缩进当前行后面的10行(包括当前行) |
| h/j/k/l | Left/down/up/right 左/下/上/右 |
| w | Move to the next word’s initial letter 行内跳字(跳到字首)(从左往右) |
| shift + w | Move to the next word’s initial letter 行内跳字(跳到字首)(从左往右),只以空格为分隔符 |
| b | Move to the next word’s initial letter 行内跳字(跳到字首)(从右往左) |
| shift + b | Move to the next word’s initial letter 行内跳字(跳到字首)(从右往左),只以空格为分隔符 |
This post is licensed under CC BY 4.0 by the author.