在我看来,一个靠谱的开发工具应该具有以下几点功能:
- 基本的语法高亮;
- 基本的自动补全;
- 方便查找、替换、修改;
借微软LSP的东风,在出现了支持LSP的插件之后,vim已经非常完美的满足了我以上提到的三点需求。下面是我日常使用的vim配置,供参考。
基础插件、设置
以下配置中使用的插件管理器是vim-plug
, 使用的核心插件是coc.nvim
. 以下是我使用的插件列表。
" {{{ Plugs
call plug#begin(plug_path)
" {{{ Dev
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" }}}
" {{{ Tools
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" git
Plug 'tpope/vim-fugitive'
Plug 'voldikss/vim-floaterm'
" convert between camelCase and underscoreCase. usage: :Underscore :Camel
Plug 'flyoverGu/cu.vim'
" Format markdown typesetting when mixed chinese and english
Plug 'hotoo/pangu.vim'
" this is a life saver. align everything.
Plug 'junegunn/vim-easy-align'
Plug 'jiangmiao/auto-pairs'
" move or ui enhancements
Plug 'luochen1990/rainbow'
Plug 'easymotion/vim-easymotion'
" }}}
" {{{
" Theme
Plug 'sainnhe/gruvbox-material'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" }}}
true color settings for neovim or vim
"{{{ neovim specific settings && true color config
if has("termguicolors")
set termguicolors
endif
" enable italic support for vim when use xterm-256color in zsh when use tmux
if !has('nvim')
" Note: ^[ are Ctrl-v ESC, but plain text.
set t_ZH=[3m
set t_ZR=[23m
" fix bug for vim, Note: ^[ are Ctrl-v ESC, but plain text.
set t_8f=[38;2;%lu;%lu;%lum
set t_8b=[48;2;%lu;%lu;%lum
endif
" }}}
用到的coc插件
" {{{ coc
let g:coc_global_extensions = [
\ 'coc-explorer',
\ 'coc-floaterm',
\ 'coc-git',
\ 'coc-go',
\ 'coc-highlight',
\ 'coc-html',
\ 'coc-json',
\ 'coc-lists',
\ 'coc-python',
\ 'coc-rls',
\ 'coc-rust-analyzer',
\ 'coc-swagger',
\ 'coc-tsserver',
\ 'coc-yaml',
\ 'coc-yank'
\]
" }}}
### 自定义快捷键和设置
```vimscript
" {{{ custom hot-key
nnoremap <leader><CR> :so ~/.config/nvim/init.vim<CR>
" move between window easier
nnoremap <leader>h :wincmd h<CR>
nnoremap <leader>j :wincmd j<CR>
nnoremap <leader>k :wincmd k<CR>
nnoremap <leader>l :wincmd l<CR>
nnoremap <leader>d :r! date "+\%Y-\%m-\%d \%H:\%M:\%S"<cr>
" move to end or beggning within insert mode.
inoremap <C-a> <C-o>0
inoremap <C-e> <C-o>$
" }}}
配置文件太长,完整版见:github
最终效果图: