我用过vim、emacs,以及WebStorm和VS Code。我认为工具应当用其所长。
用他的优点,有缺点用其他工具补充。vim性能好,编辑快捷。有段时间,我工作的电脑是一台MacBook Air,用IDE吃力,操作起来不流畅。用vim做Web前端开发够用。Web前端很简单,我大概用没有安装额外的插件的vim工作了三年。现在想来,未免觉得鲁莽可笑。
这里插件和配置的取舍的原则是:便捷优先,尽量简洁。要简洁,airline这样装饰性的插件,弃用。格式化和lint之类的插件,个人体验了一下,不如IDE,这部分功能使用IDE的功能即可。同样,重构代码的功能,以目前的配置,也不如WebStorm,涉及这部分功能就用WebStorm替代。
文本编辑非常重要的点:
- 搜索
- 编辑
找到要编辑的文件,然后找到要编辑的文本字符。这是一个从大到小的过程。查找主要是搜索,目录、文件和字符搜索。定位到具体编辑的稳步,依赖光标的移动。
:ls查看缓冲区,可以看到编号以及其稳健,按回车不能进入对应文件,buffer列表会消失。buffer num切换到num编号对应的文件,buffer dir/filename也可以切换buffer,按tab键可以补全。也可以用缩写buf。
| command | 用途 |
|---|---|
bnext bn |
下一个缓冲区 |
bprevious bp |
上一个 |
blast bl |
最后一个 |
bfirst bf |
第一个个 |
快捷键,取代 CtrlP 插件
Ctrl + p 查看文件列表 Ctrl + e 查看当前 Buffer,两次 Ctrl + e 快速切换上次打开的 Buffer
nmap <C-p> :Files<CR>
nmap <C-e> :Buffers<CR>
let g:fzf_action = { 'ctrl-e': 'edit' }按键绑定: Ctrl-p
提示面板操作:
- tab: 自动补全提示面板中的当前工作路径的目录名
- ctrl-d: 全路径搜索和文件名搜索间切换。文件名搜索模式的提示符是'>d>',而非'>>>'
- ctrl-r: 字符串搜索和正则搜索切换。正则模式提示符是'r>>',而不是'>>>'
选择搜索结果:
- ctrl-j ctrl-k: 向下与向上移动
- ctrl-a ctrl-e: 移动到提示面板的开头和结尾
浏览输入历史:
- ctrl-n ctrl-p: 搜索历史中的下一个字符串和上一个字符串
打开文件:
- ctrl-r(current): 当前窗口打开选择的文件
- ctrl-t: 新tab打开
- ctrl-v: 竖直分割窗口
- ctrl-s: 水平分割窗口
- Enter:当前窗口打开文件,o:新建窗口打开文件
- R:重命名
- D:删除
- /: 文件列表查找
- gf: 打开光标所在的文件名对应的文件
自定义按键绑定: F3
-
在NerdTree窗口中,按
m,底部出现菜单。选择a,添加子节点。如果输入目录,在最后添加/,否则将创建文件。支持添加不存在的目录和文件,如dir/fileName.md -
h更新目录。在未使用vim新建文件的情况刷新列表。
zz当前行居中gd查找当前单词Ctrl-o光标返回以前的位置,相当于光标移动的撤销Ctrl-i光标返回后来的位置,相当于光标移动的恢复
手动设置的mark:
| command | 用途 |
|---|---|
| m | 标记 |
| ``m` | 跳转到标记 |
:marks |
列出所有标记 |
:delmarks mark_name |
删除对应的标记 |
delmakrs! |
删除所有标记 |
自带特殊的mark(作用存疑,待验证):
| command | 用途 |
|---|---|
. |
最近编辑位置 |
| 0-9 | 最近使用文件 |
^ |
最近插入位置 |
| ``` | 上一次跳转前位置 |
" |
上一次退出文件位置 |
[ |
上一次修改开始处 |
] |
上一次修改结束处 |
自定义按键绑定: prefix为f,ff为easymotion-s2,根据两个字符搜索定位,大部分场景下能快速定位
g;和g,在changelist中来回跳转
- ctrl-o ctrl-i在jumplist中来回跳转
- ctrl-O ctrl-I在文件中trace光标
- gd比
/与?更方便
自定义按键绑定: leader键为空格,undotree绑定在u(undo)上
- ctrl-d,ctrl-t 左右缩进
- ctrl-w 删除
- ctrl-u 重新编辑
- 撤销补全,按
Ctrl-p到最初的,即没有补全的状态。或者,Ctrl-u撤销所有此次的输入(不止含有这个单词的输入,危险操作) Ctrl-n,在insert模式下,vim会搜索这个目录下的代码,显示一个下拉列表Ctrl-x Ctrl-l,整行补齐,常用于import等,补齐之后修改即可Ctrl-x Ctrl-f,文件名补齐,用于import等。默认为全局目录,可以使用./开始,使之定位到当前目录Ctrl-x Ctrl-pCtrl-x Ctrl-n,当前文件中的关键字Ctrl-x Ctrl-o基于语义的补全
- 只读
view - 可编辑
e或e!
:f filename重命名当前文件
- 切换到其他目录
cd dir - 回到上一个工作目录
cd -
Te全称Texplore。
gt下一页gT上一页{i}gt到指定页tabs查看tab情况tabclose [i]有数字,关闭指定页;无数据,关闭当前页vim -p 1.cpp 2.cppvim的-p参数可以用tab的方式打开多个文件bufdo tab split把buffer中全部文件转成tab
Ctrl-w c关闭当前窗口Ctrl-w o关闭其他分屏,只保留当前分屏Ctrl-w q关闭当前窗口,如果只剩最后一个,则退出
Ctrl-w L/H/K/J向右左上下移动分屏。如果我们想在水平分屏和垂直分屏间切换,可以使用这些指令。
Ctrl-w l/h/k/j
- 所有屏幕一样的高度
Ctrl-w = - 增加高度
Ctrl-w + - 减少高度
Ctrl-w -
-
HeHexplore上下分屏,下面进行目录浏览 -
He!上下分屏,上面进行目录浏览 -
VeVexpore左右分屏,左边目录 -
Ve!左右分屏,右边目录 -
垂直分割窗口
Sex -
水平分割
vs
- zc:折叠,zC:递归折叠
- zo:取消折叠,zO:递归取消
- zM:折叠全文件
- zR:取消全文件折叠
自定义按键绑定:
let g:minimap_show='<leader>ms'
let g:minimap_update='<leader>mu'
let g:minimap_close='<leader>gc'
let g:minimap_toggle='<leader>gt'
- leader键为空格
- w:保存文件
| command | 用途 |
|---|---|
:set spell |
启用拼写检查 |
:set nospell |
关闭 |
]s |
移动到下一个拼写错误 |
[s |
移动到上一个 |
z= |
选择正确拼写 |
zg |
添加用户拼写 |
zw |
删除用户拼写 |
:terminalterm命令打开新的终端窗口。:exit退出终端,只关闭窗口时我们无法使用:qa退出vim。vert term横向切分出终端窗口,tab term新标签页打开终端窗口。- 终端也有normal模式和insert模式。按
Ctrl-\ Ctrl-n切换到normal模式,此时才能想vim的buffer一样移动光标,切换窗口。按i进入插入模式。
GeditView any blob, tree, commit, or tag in the repository with :Gedit (and :Gsplit, :Gvsplit, :Gtabedit, ...). Edit a file in the index and write to it to stage the changes.:Gdiffto bring up the staged version of the file side by side with the working tree version and use Vim's diff handling capabilities to stage a subset of the file's changes.:GstatusBring up an enhanced version of git status with :Gstatus. Press - to add/reset a file's changes, or = to expand an inline diff and operate on individual hunks.:Gcommit %to commit the current file, editing the commit message inside the currently running Vim.:Gblamebrings up an interactive vertical split with git blame output. Press enter on a line to edit the commit where the line changed, or o to open it in a split. When you're done, use :Gedit in the historic buffer to go back to the work tree version.:Glog(不好用,用gv.vim替代) loads all previous revisions of a file into the quickfix list so you can iterate over them and watch the file evolve!
:GVto open commit browser- You can pass
git logoptions to the command, e.g.:GV -S foobar.
- You can pass
:GV!will only list commits that affected the current file:GV?fills the location list with the revisions of the current file
:GV or :GV? can be used in visual mode to track the changes in the
selected lines.
oor<cr>on a commit to display the content of itoor<cr>on commits to display the diff in the rangeOopens a new tab insteadgbfor:Gbrowse]]and[[to move between commits.to start command-line with:Git [CURSOR] SHAà la fugitiveqto close
- vim和shell切换:Ctrl-z vim后台运行,跳转到shell,在shell输入fg,切回vim
- junegunn/goyo.vim 沉浸模式
- ag
- fzf
- 2019/3/19之前,初步整理
- 2019/3/19,更新补全的操作,tab操作,buffer的操作。删除冗余的vim前言,去掉啰嗦带鼓吹性质的语言
- 2019/3/22,新增git相关插件,git操作是高频操作,避免频繁切到终端
- 2019/4/3,删除ctrlp,新增fzf