Post

About vim

Vim command

Commandfunction
:wSave 保存文件
:qExit 退出vim
:q!Forcefully exit Vim without saving 强制退出vim,不保存文件
:wqSave and exit 保存并退出
ggNavigate to the beginning of the file. ‘:1’ the same thing 跳到文件的第一行
:10Navigate to line 10 in the file 跳到文件的第10行
shift + gNavigate to the last line in the file 跳到文件的最后一行
shift + dErase the text from the cursor position to the end of the line 删除当前光标到行尾的内容
gdNavigate to the definition of the variable at the cursor (function) 跳到光标所在变量的定义(函数内)
gDNavigate to the initial appearance of the variable at the cursor position 跳到光标所在变量第一次出现的地方
gfModify the file corresponding to the cursor’s location 编辑光标所在位置对应的文件
gFEdit the file corresponding to the current cursor position and navigate to the line number following the file name 编辑光标所在位置对应的文件,并跳到文件名后的行号
ddDelete the current line 删除当前行
:10,20dDelete the content from line 10 to line 20 in the file 删除文件的第10行到第20行的内容
:%dClear the contents of the file 清空文件内容
yyCopy the current line 复制当前行
pPaste the copied content to the next line 粘贴复制的内容到下一行
shift + PPaste the copied content to the next line 粘贴复制的内容到下一行
uUndo 回退修改
ctrl + rBack 撤销回退
iInsert at the cursor position 光标位置插入
aAppend at the cursor position 光标位置追加
oMove to the next line 向下换行
shift + oMove to the previous line 向上换行
ctrl + o, ctrl + oOpen the most recently edited file 打开最近一次编辑的文件
:e xxxEdit 编辑文件xxx
:fView the filename of the current file 查看当前文件的文件名
:pwdView the absolute path of the current file 查看当前文件的绝对路径
:shellEnter the command line 进入控制台界面执行shell命令,exit返回vim
/xxxFind characters downward 向下匹配xxx字符,N向下查找,shift + N向上查找
?xxxFind characters upward 向上匹配xxx字符,N向上查找,shift + N向下查找
:set hlsEnable search highlighting 设置高亮搜索
:set nohlsDisable search highlighting 取消高亮搜索
:set nuShow line numbers 设置显示行号
:set nonuHide line numbers 取消显示行号
:set pastePaste mode, do not format copied content 粘贴模式,不格式化拷贝的内容
:%s/xxx/yyy/gSearch and replace 全局匹配替换,将xxx全部替换为yyy
:bro olView recently opened files 查看最近打开的文件
:set ffFileformat,查看文件格式
:set ff=unixSet the file format to unix 设置文件格式为unix
:spSplitting vertically 上下分屏
:vspSplitting horizontally 左右分屏
ctrl + wSwitching between splits 切换分屏
ctrl + eScrolling down 向下滚屏
ctrl + yScrolling up 向上滚屏
ctrl + x, ctrl + iKeyword completion 关键字补全,只匹配当前文件中的关键字及include指定头文件中的关键字
ctrl + x, ctrl + fFile name completion 文件名补全
ctrl + x, ctrl + ]Keyword completion 关键字补全,匹配ctags文件中的关键字
:!ctags -R .Generate a tags file recursively in the current directory 当前目录下递归生成tags文件
:set tags=xxxTo use ‘xxx’ as the tag file in Vim 使用xxx作为vim使用tag文件
ctrl + ]Jump to the first matching tag 跳转到第一个匹配的tag
:tnTag next,多个tag匹配中时,跳转到下一个tag
:tsTag select,列出匹配中的tag列表
=GAuto-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/lLeft/down/up/right 左/下/上/右
wMove to the next word’s initial letter 行内跳字(跳到字首)(从左往右)
shift + wMove to the next word’s initial letter 行内跳字(跳到字首)(从左往右),只以空格为分隔符
bMove to the next word’s initial letter 行内跳字(跳到字首)(从右往左)
shift + bMove to the next word’s initial letter 行内跳字(跳到字首)(从右往左),只以空格为分隔符
This post is licensed under CC BY 4.0 by the author.