查看原文
其他

TaoBeier 的 Vim 配置,支持 Python、Javascript、Golang 等

2017-01-08 作者:TaoBeier Linux中国
每一个 Vimer 都有一个用 Vim 打造一个完美帝国的梦想,总是会有沉迷于 Vim 及林林总总的插件中不可自拔的一段青葱岁月。让我们来看看 TaoBeier 是如何编织自己的 Vim 幻境的。
-- TaoBeier

转载自: 
作者: TaoBeier


编者按:每一个 Vimer 都有一个用 Vim 打造一个完美帝国的梦想,总是会有沉迷于 Vim 及林林总总的插件中不可自拔的一段青葱岁月。让我们来看看 TaoBeier 是如何编织自己的 Vim 幻境的。

本文略有修改,欢迎大家到 [1] 上反馈和加入对此配置的贡献。

这是 TaoBeier 精心打造的 Vim 环境配置,支持 Python、Javascript、Vue.js、Golang 和 Markdown。

安装

你需要一个有 Python 支持的 Vim 版本。请使用 vim --version | grep +python 来检查确认。

依赖

Debian/Ubuntu 平台

  1. sudo apt-get install python vim exuberant-ctags git

  2. sudo pip install dbgp pep8 flake8 pyflakes isort

RedHat/CentOS 平台

CentOS 6.7 的 yum 源自带的 Python 版本较旧,推荐自行安装 Python2.7。

  1. sudo yum install python vim ctags git

  2. sudo pip install dbgp pep8 flake8 pyflakes isort

Mac OS 平台

  1. brew install python vim git

  2. wget http://tenet.dl.sourceforge.net/project/ctags/ctags/5.8/ctags-5.8.tar.gz && tar -zxvf ctags-5.8.tar.gz && cd ctags-5.8 && ./configure && make && sudo make install

  3. sudo pip install dbgp pep8 flake8 pyflakes isort

下载 vimrc 文件到用户主目录

  1. wget https://raw.githubusercontent.com/tao12345666333/vim/master/vimrc -O $HOME/.vimrc

安装插件

打开 Vim,它将会自动安装插件。请耐心等待它完成。或者你可以使用下面的命令来自行安装。

  1. vim -E -u $HOME/.vimrc +qall

享受你的 Vim 并个性化它吧!

支持特性

插件管理(Vundle)

在这份配置中,使用了 [2] 作为插件管理器。Vundle 会自动接管 .vim 文件夹,所有配置好的插件将默认下载至~/.vim/bundle/, 在使用之前请确保.vim文件夹干净。 Vundle 的插件安装需要触发 git clone 操作,搜索需要 curl 支持。

配置(截取了部分)

  1. " let Vundle manage Vundle

  2. Plugin 'gmarik/vundle'

  3. " ============================================================================

  4. " Active plugins

  5. " You can disable or add new ones here:

  6. " Plugins from github repos:

  7. " Better file browser

  8. Plugin 'scrooloose/nerdtree'

  9. " Code commenter

  10. Plugin 'scrooloose/nerdcommenter'

  11. " Class/module browser

  12. Plugin 'majutsushi/tagbar'

  13. " Code and files fuzzy finder

  14. Plugin 'kien/ctrlp.vim'

  15. " Extension to ctrlp, for fuzzy command finder

  16. Plugin 'fisadev/vim-ctrlp-cmdpalette'

  17. " Zen coding

  18. Plugin 'mattn/emmet-vim'

  19. " Git integration

  20. Plugin 'motemen/git-vim'

  21. " Tab list panel

  22. Plugin 'kien/tabman.vim'

支持操作

命令解释
:PluginList列出所有插件
:PluginInstall(!)安装/更新插件
:PluginSearch(!) foo搜索 foo 相关的插件
:PluginClean(!)清理未使用的插件
:PluginUpdate更新插件

工程文件浏览(NERDTree)

在这份配置中, 使用了 [3] 查看文件列表。你可以在 NERDTree 中浏览和打开你文件系统中的目录或文件。还可以进行文件隐藏和过滤,设置添加书签等。在 NERDTree 窗口输入?可获得操作指南。这份配置中默认过滤掉了 .pyc.git.hg、 .svn等文件或文件夹的显示。

配置

  1. " auto open or close NERDTree

  2. autocmd vimenter * if !argc() | NERDTree | endif

  3. autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

  4. " NERDTree -----------------------------

  5. " toggle nerdtree display

  6. map <F3> :NERDTreeToggle<CR>

  7. " open nerdtree with the current file selected

  8. nmap ,t :NERDTreeFind<CR>

  9. " don;t show these file types

  10. let NERDTreeIgnore = ['\.pyc$', '\.pyo$']

支持操作

快捷键解释
F3打开/关闭 NERDTree
,t打开 NERDTree 并选中当前文件

语法检查(Syntastic)

在这份配置中,使用 [4] 插件进行语法静态检查. 包括但不限于C/C++/Go/Python/Haskell/Ruby/JavaScript等 。在本配置中对 JavaScript 的静态检查使用eslint,可以支持 ES6 及 JSX 等,细节可以参考 [5],想要切换检查工具只要修改对应位置即可。

配置

  1. " Syntastic ------------------------------

  2. " show list of errors and warnings on the current file

  3. nmap <leader>e :Errors<CR>

  4. " turn to next or previous errors, after open errors list

  5. nmap <leader>n :lnext<CR>

  6. nmap <leader>p :lprevious<CR>

  7. " check also when just opened the file

  8. let g:syntastic_check_on_open = 1

  9. " syntastic checker for javascript.

  10. " eslint is the only tool support JSX.

  11. " If you don't need write JSX, you can use jshint.

  12. " And eslint is slow, but not a hindrance

  13. " let g:syntastic_javascript_checkers = ['jshint']

  14. let g:syntastic_javascript_checkers = ['eslint']

  15. " don't put icons on the sign column (it hides the vcs status icons of signify)

  16. let g:syntastic_enable_signs = 0

  17. " custom icons (enable them if you use a patched font, and enable the previous

  18. " setting)

  19. let g:syntastic_error_symbol = ''

  20. let g:syntastic_warning_symbol = ''

  21. let g:syntastic_style_error_symbol = ''

  22. let g:syntastic_style_warning_symbol = ''

特性

保存时自动进行语法静态检查,方便的错误提示及灵活的可扩展性。

支持操作

快捷键解释
\e打开错误列表
\n移动到下一个错误位置
\p移动到上一个错误位置

Git 支持(vim-fugitive 和 vim-signify)

在这份配置中,使用 [6] 和 [7] 做 Git 方面的支持。可以进行常用的 Git 操作及优雅的状态提示等(目前支持githg)。

配置

  1. " Signify ------------------------------

  2. " this first setting decides in which order try to guess your current vcs

  3. " UPDATE it to reflect your preferences, it will speed up opening files

  4. let g:signify_vcs_list = [ 'git', 'hg' ]

  5. " mappings to jump to changed blocks

  6. nmap <leader>sn <plug>(signify-next-hunk)

  7. nmap <leader>sp <plug>(signify-prev-hunk)

  8. " nicer colors

  9. highlight DiffAdd           cterm=bold ctermbg=none ctermfg=119

  10. highlight DiffDelete        cterm=bold ctermbg=none ctermfg=167

  11. highlight DiffChange        cterm=bold ctermbg=none ctermfg=227

  12. highlight SignifySignAdd    cterm=bold ctermbg=237  ctermfg=119

  13. highlight SignifySignDelete cterm=bold ctermbg=237  ctermfg=167

  14. highlight SignifySignChange cterm=bold ctermbg=237  ctermfg=227

支持操作

快捷键解释
:Git [args]类似执行git命令一样
:Gstatus类似git status。在列表中使用-添加/移除文件
:Gcommit [args]类似 git commit
:Gmerge [args]类似 git merge
:Gpull [args]类似 git pull
:Gpush [args]类似 git push
:Gvdiff [revision]类似 git push 但是会切分窗口

更多详细的操作可以使用 :help fugitive

Tag 支持(Tagbar)

在这份配置中,使用了 [8] 做 Tag 支持,可以显示当前文件中定义的类/变量等。

配置

  1. " Tagbar -----------------------------

  2. " toggle tagbar display

  3. map <F4> :TagbarToggle<CR>

  4. " autofocus on tagbar open

  5. let g:tagbar_autofocus = 1

支持操作

快捷键解释
F4打开 Tag 列表

超全自动补全(Neocomplcache)

在这份配置中, 使用了 [9] 作为主要的自动补全插件。

配置

  1. " NeoComplCache ------------------------------

  2. " most of them not documented because I'm not sure how they work

  3. " (docs aren't good, had to do a lot of trial and error to make

  4. " it play nice)

  5. " Disable AutoComplPop.

  6. let g:acp_enableAtStartup = 0

  7. " Use neocomplcache.

  8. let g:neocomplcache_enable_at_startup = 1

  9. let g:neocomplcache_enable_ignore_case = 1

  10. " Use smartcase.

  11. let g:neocomplcache_enable_smart_case = 1

  12. let g:neocomplcache_enable_auto_select = 1

  13. let g:neocomplcache_enable_fuzzy_completion = 1

  14. let g:neocomplcache_enable_camel_case_completion = 1

  15. let g:neocomplcache_enable_underbar_completion = 1

  16. let g:neocomplcache_fuzzy_completion_start_length = 1

  17. let g:neocomplcache_auto_completion_start_length = 1

  18. let g:neocomplcache_manual_completion_start_length = 1

  19. " Set minimum syntax keyword length.

  20. let g:neocomplcache_min_keyword_length = 1

  21. let g:neocomplcache_min_syntax_length = 1

  22. let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'

  23. " complete with workds from any opened file

  24. let g:neocomplcache_same_filetype_lists = {}

  25. let g:neocomplcache_same_filetype_lists._ = '_'

  26. " <TAB>: completion.

  27. inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"

  28. " Define keyword.

  29. if !exists('g:neocomplcache_keyword_patterns')

  30.    let g:neocomplcache_keyword_patterns = {}

  31. endif

  32. let g:neocomplcache_keyword_patterns['default'] = '\h\w*'

  33. " Plugin key-mappings.

  34. inoremap <expr><C-g>     neocomplcache#undo_completion()

  35. inoremap <expr><C-l>     neocomplcache#complete_common_string()

  36. " <C-h>, <BS>: close popup and delete backword char.

  37. inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"

  38. inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"

  39. inoremap <expr><C-y>  neocomplcache#close_popup()

  40. inoremap <expr><C-e>  neocomplcache#cancel_popup()

支持操作

快捷键解释
<Tab>使用 Tab 键进行待提示项目选择
<C-g>取消补全
<C-l>完成待补全项中共同的字符串
<C-h>关闭待选项
<C-y>关闭待选项
<C-e>退出待选项
<BS>关闭待选项

类 Tmux 的窗口选择(vim-choosewin)

在这份配置中,使用了 [10] 进行窗口管理器。支持类 Tmux 的操作。

配置

  1. " Window Chooser ------------------------------

  2. " mapping

  3. nmap  -  <Plug>(choosewin)

  4. " show big letters

  5. let g:choosewin_overlay_enable = 1

支持操作

快捷键解释
-开启窗口选择
- [选择上一个 tab 的窗口
- ]选择下一个 tab 的窗口

更多操作可以使用 :help choosewin

灵活的 Tab 管理(TabMan)

在这份配置中使用了 [11] 进行 Tab 管理,可以进行灵活切换与管理。

配置

  1. " TabMan ------------------------------

  2. " mappings to toggle display, and to focus on it

  3. let g:tabman_toggle = 'tl'

  4. let g:tabman_focus  = 'tf'

支持操作

快捷键解释
tl开启/关闭 tab 管理
tf将光标移动到 tab 管理窗口

优雅的状态栏(Airline)

在这份配置中,使用了 [12] 提供更多状态栏支持。

配置

  1. " Airline ------------------------------

  2. let g:airline_powerline_fonts = 1

  3. let g:airline_theme = 'bubblegum'

  4. "let g:airline#extensions#tabline#enabled = 1

  5. "let g:airline#extensions#tabline#left_sep = ' '

  6. "let g:airline#extensions#tabline#left_alt_sep = '|'

  7. let g:airline#extensions#whitespace#enabled = 1

  8. " to use fancy symbols for airline, uncomment the following lines and use a

  9. " patched font (more info on the README.rst)

  10. if !exists('g:airline_symbols')

  11.   let g:airline_symbols = {}

  12. endif

  13. let g:airline_left_sep = ''

  14. let g:airline_left_alt_sep = ''

  15. let g:airline_right_sep = ''

  16. let g:airline_right_alt_sep = ''

  17. let g:airline_symbols.branch = ''

  18. let g:airline_symbols.readonly = ''

  19. let g:airline_symbols.linenr = ''

支持特性

可以显示分支,语法静态检查结果等。

自动插入头部

在这份配置中写了个小函数根据新建的不同类型的文件,自动插入头部,支持pythonruby、 bash等。

Markdown 实时预览(vim-instant-markdown 和 vim-markdown)

在这份配置中,使用了 [13] 和 [14] 做 Markdown 格式的支持,可以支持实时预览等特性。

此功能需要有 node 环境支持,可以执行 npm -g install instant-markdown-d 进行安装。

配置

  1. " Vim-markdown ------------------------------

  2. " Disabled automatically folding

  3. let g:vim_markdown_folding_disabled=1

  4. " LeTeX math

  5. let g:vim_markdown_math=1

  6. " Highlight YAML frontmatter

  7. let g:vim_markdown_frontmatter=1

  8. " Vim-instant-markdown -----------------

  9. " If it takes your system too much, you can specify

  10. " let g:instant_markdown_slow = 1

  11. " if you don't want to manually control it

  12. " you can open this setting

  13. " and when you open this, you can manually trigger preview

  14. " via the command :InstantMarkdownPreview

  15. let g:instant_markdown_autostart = 0

支持操作

快捷键解释
:InstantMarkdownPreview手动触发 markdown 文件的预览

多游标选择、编辑等

在这份配置中,可以在高亮某单词时,通过使用 Ctrl-n 或者 Ctrl-p 进行多游标选择,然后进行编辑或修改等操作。

快速文件查找

在这份配置中,可以通过使用,R进行全文查找或者,r进行快速查找,或者在当前字符串上使用,wR以及,wr来进行全文查找或者快速查找。

快速注释

使用 [15] 插件完成快速注释,可以通过\ci进行快速注释。

Python 支持

完备的 Python 支持,可以自动识别当前是系统环境或虚拟环境,使用:Isort可智能对导入包进行排序,使用:PymodeLintAuto可自动格式化。

总结

除了上述列出的功能以外,还有很多方便的特性,可以大大提升效率,在使用中慢慢体会吧!有问题可以在[16] on github 提 issue 。


推荐文章

滑动查看更多

输入文章 ID 或长按二维码直达


[1]: https://github.com/tao12345666333/vim
[2]: https://github.com/VundleVim/Vundle.vim
[3]: https://github.com/scrooloose/nerdtree
[4]: https://github.com/scrooloose/syntastic
[5]: http://moelove.info/2015/11/28/JSLint-JSHint-ESLint%E5%AF%B9%E6%AF%94%E5%92%8CVim%E9%85%8D%E7%BD%AE/
[6]: https://github.com/tpope/vim-fugitive
[7]: https://github.com/mhinz/vim-signify
[8]: http://github.com/majutsushi/tagbar
[9]: https://github.com/Shougo/neocomplcache.vim
[10]: https://github.com/t9md/vim-choosewin
[11]: https://github.com/kien/tabman.vim
[12]: https://github.com/vim-airline/vim-airline
[13]: https://github.com/suan/vim-instant-markdown
[14]: https://github.com/plasticboy/vim-markdown
[15]: https://github.com/scrooloose/nerdcommenter
[16]: https://github.com/tao12345666333/vim


您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存