- [a] 编辑模式 [v] 视觉行模式 [esc] 命令模式 : 末行模式
基本操作
[esc] y 复制一行
:10,20y 复制多行 (10~20 行)
[v] 选择内容 y 复制
[esc] p 粘贴
[esc] ggdG 删除所有内容
[esc] wq 保存退出
搜索
:set hlsearch 打开高亮显示
:highlight search ctermfg=black ctermbg=white 设置高亮的前景色和背景色
:noh 关闭高亮显示
[esc] /str 指定要搜索的字符串
[esc] shift + * 选中要搜索的字符串为当前光标所在的单词,并高亮
[esc] g d 对光标所在的符号进行高亮显示,并跳到定义处
[esc] n 搜索下一处
[esc] shift + n 搜索上一处
分割窗口
:split file2 水平分割窗口 (可简写为 sp)
:vsplit file2 垂直分割窗口 (可简写为 vsp)
[esc] ctrl + w + w 切换到下一个窗口
:only 只保留当前窗口,关闭其它窗口
:close 关闭当前窗口
:qa 退出所有窗口
函数跳转
apt-get install exuberant-ctags
ctags -R 生成 tags 文件
vim <代码文件>
:set tags=./tags,./TAGS,tags,TAGS
[esc] ctrl + ] 跳到代码定义
[esc] ctrl + t 往回跳
[esc] ctrl + o 往回跳
浏览文件
:Explore 打开目录文件列表
:echo expand('%:p') 显示当前文件路径
显示行号
:set nu 打开行号显示
:set nonu 关闭行号显示
查看命令历史
[esc] q:
:history
粘贴格式乱了
运行如下命令,进入 paste 模式
:set paste 进入 paste 模式后,按 i 键进入插入模式,然后再粘帖,文本格式不会错乱了
:set nopaste 取消 paste 模式
切换主题颜色
:colorscheme default
:colorscheme morning
:colorscheme evening