Vim配置

Abstract here

Vim

大名鼎鼎的vim相比没有人没听说过吧。

环境配置

博主采用的vim方案是基于The Ultimate vimrc的 脚手架,其中包括了一组常用vim插件,如bufexplorer.vim, NERD Tree, vim-fugitive等。

1
2
git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh

然后$HOME/.vim_runtime成为vim插件的目录,你可以用脚手架中自带的pathogen.vim包来管理插件,但我更推荐更轻量也更流行 的vim-plug包管理器。安装好vim-plug后,新增插件只需要在~/.vim_runtime/my_configs.vim中找到vim-plug的部分,我 在脚手架项目之外额外安装的插件有

1
2
3
4
5
6
7
8
9
10
11
12
13
call plug#begin('~/.vim_runtime/my_plugins')
Plug 'python-mode/python-mode', { 'for': 'python', 'branch': 'develop' }
Plug 'preservim/tagbar'
Plug 'ycm-core/YouCompleteMe'
Plug 'Yggdroot/indentLine'
Plug 'christoomey/vim-tmux-navigator'
Plug 'wakatime/vim-wakatime'
Plug 'xavierd/clang_complete'
Plug 'fatih/vim-go'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'github/copilot.vim'
call plug#end()
  • python-mode: 提供了Python的intellisense, linting等功能
  • YouCompleteMe: 这个就不用多少吧,知名的自动补全插件,也提供了cursor hover时预览__doc__的功能
  • tagbar: 类似vscode的大纲
  • indentLine: 对于Python这类语法依赖缩进而不是大括号的语言(游标卡尺), 不可或缺的插件
  • vim-wakatime: WakaTime的vim插件,可以统计写代码的时间等数据,也有vscode插件
  • clang_complete: C++的补全插件,个人觉得比YCM的C++功能要好
  • vim-go: Golang的vim插件,功能十分强大,最大的特点是支持代码跳转
  • fzf和fzf.vim: 项目全局搜索,基于:Ag命令
  • copilot.vim: Github Copilot项目的vim适配

关于Github Copilot不用多介绍了吧,博主从preview阶段就开始试用了,现在Github Copilot已经转为付费了,但不知道为何在我的 账户的订阅界面还是显示可以免费使用。。需要vim 9.0以上,Ubuntu自带的vim应该是8.0版本的,升级到9.0最推荐的方法是直接 从源码编译。

1
2
3
4
5
git clone git@github.com:vim/vim.git
# /vim/src/Makefile里把CONF_OPT_PYTHON3的部分uncomment掉
make reconfig
make install
/usr/local/bin/vim --version

确认vim版本是VIM - VI Improved 9.0 (...)或更高,且有+python3的编译支持,然后使用vim-plug安装插件即可,在vim

1
:Copilot setup

验证登陆

1
:Copilot status

确认Github Copilot正常运行。

:set list显示whitespace字符,这个对于debug一些缩进语言的Tab和Space导致的问题非常有用 :set list& resets a vim option

书签(markers)

  • mk place a marker called k
  • 'k to marker k
  • d'k delete marker k

Lower letters (a-z) are for same-file navigation. Capital letters (A-Z) are for global navigation.

Copy-Paste

select some text (with yank or delete)

| yiw | yank inner word | viwp | select inner word, replace

You can replace any visual selected text with yanked text by pressing p

Split Panes

| :split | horizontal split (windows are side-by-side) | :vsplit | vertical split (windows are stacked vertically) | Ctrl-w-+ | increate current split size (by one row) | Ctrl-w-10-+ | increase current split size (by 10 rows)

NERDTree customization

NERDTree is a popular navigation plugin of vim. It looks like the file navigation manager in IDEs where you can quickly find the source file you want to view and edit. However its functioning logic is quite different from its counterparts in IDEs. For example, NERDTree’s windows are not synced across vim tabs!

Buffer操作

关闭除了当前的其他所有buffer

:%bd|#e

%bd是关闭所有buffer,e#是打开最后一个buffer