实用 Vim 配置
以下分两部分介绍了Vim 的配置,他们的配置内容大同小异,主要是由于用途的不同。
Mac
在Mac 上,我主要使用MacVim 进行Python 项目开发,所以侧重点是开发而不是写作和文本编辑
" -----------------------------------------
" Vundle
" -----------------------------------------
set nocompatible " be iMproved, required
filetype off " required
set rtp+=$HOME/.vim/bundle/Vundle.vim/
call vundle#begin('$HOME/.vim/bundle/')
Plugin 'VundleVim/Vundle.vim'
" 给选中的文本加分隔符 ()/[]/{}/''/""
Plugin 'https://github.com/tpope/vim-surround'
" 自动闭合:单引号、双引号、括号
Plugin 'https://github.com/Raimondi/delimitMate'
" 移动命令按键映射
Plugin 'https://github.com/tpope/vim-unimpaired'
" 增强.命令
Plugin 'https://github.com/tpope/vim-repeat'
" 有道词典
Plugin 'https://github.com/ianva/vim-youdao-translater.git'
" 文件查找
Plugin 'https://github.com/junegunn/fzf.vim'
" 可视模式
Plugin 'https://github.com/terryma/vim-expand-region'
" 跳转
Plugin 'https://github.com/easymotion/vim-easymotion'
Plugin 'https://github.com/justinmk/vim-sneak'
" 缓冲
Plugin 'https://github.com/vim-scripts/bufexplorer.zip'
" 语言拓展包
Plugin 'https://github.com/sheerun/vim-polyglot'
" 对齐线
Plugin 'https://github.com/Yggdroot/indentLine'
" 翻页更顺滑
Plugin 'https://github.com/terryma/vim-smooth-scroll'
" 状态行
Plugin 'https://github.com/itchyny/lightline.vim'
" 模板补全
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
" 代码补全
Plugin 'https://github.com/Valloric/YouCompleteMe'
" 格式化代码
Plugin 'junegunn/vim-easy-align'
call vundle#end() " required
filetype plugin indent on " required
" -----------------------------------------
" 基础设置
" -----------------------------------------
" 设置字体
set guifont=Source\ Code\ Pro\ for\ Powerline:h13
" 不产生备份文件
set nobackup
" 不产生交换文件
set noswapfile
" 历史命令数
set history=1000
"使用vim键盘
set nocompatible
"解决退格键无法使用
set backspace=indent,eol,start
" 窗口大小
set lines=50 columns=160
" 行号
set nu
" 语法高亮
syntax enable
" 主题
colorscheme vividchalk
" -----------------------------------------
" 缩进
" -----------------------------------------
set ai
set shiftwidth=4
set tabstop=4
set sts=4
set expandtab
" -----------------------------------------
" 命令行补全方式
" -----------------------------------------
set wildmenu
set wildmode=full
" -----------------------------------------
" 编码
" -----------------------------------------
"默认编码
set encoding=utf-8
"vim 自动识别UTF8和GB2312
set fencs=utf-8,gbk,cp936
"中文乱码
set fileencoding=utf-8
set termencoding=utf-8
set fileencodings=utf-8,cp936,gbk,gb18030,gk2312,latin-1,ucs-bom,gb2312
"菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"终端乱码
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
"consle乱码
language messages zh_CN.utf-8
" -----------------------------------------
" matchit - 增强 % 命令
" -----------------------------------------
runtime macros/matchit.vim
" -----------------------------------------
" easy-motion
" -----------------------------------------
let g:EasyMotion_leader_key='<Space>'
" -----------------------------------------
" 有道词典
" -----------------------------------------
vnoremap <silent> <C-T> :<C-u>Ydv<CR>
nnoremap <silent> <C-T> :<C-u>Ydc<CR>
noremap <leader>yd :<C-u>Yde<CR>
" -----------------------------------------
" lightline.vim
" -----------------------------------------
let g:lightline = {
\ 'colorscheme': 'one',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head'
\ },
\ }
set laststatus=2
if !has('gui_running')
set t_Co=256
endif
set noshowmode
" -----------------------------------------
" ultisnips
" -----------------------------------------
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-f>"
let g:UltiSnipsJumpBackwardTrigger="<c-b>"
" -----------------------------------------
" netrw
" -----------------------------------------
let g:netrw_banner = 1
" -----------------------------------------
" YouCompleteMe
" -----------------------------------------
" 设置补全框行为
set completeopt=longest,menu
" 修改默认行为
let g:ycm_key_list_select_completion=['<c-n>','<Down>']
let g:ycm_key_list_previous_completion=['<c-p>','<Up>']
let g:ycm_confirm_extra_conf=0 " 关闭加载.ycm_extra_conf.py提示
let g:ycm_complete_in_comments = 1 " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1 " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全
let g:ycm_seed_identifiers_with_syntax=1 " 语言关键字补全
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_min_num_of_chars_for_completion=2 " 从第2个键入字符就开始罗列匹配项
" 引入,可以补全系统,以及python的第三方包 针对新老版本YCM做了兼容
" old version
if !empty(glob("~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py"))
let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py"
endif
" new version
if !empty(glob("~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"))
let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"
endif
" 白名单
let g:ycm_filetype_whitelist = {
\ 'markdown': 1,
\ 'python': 1
\}
" 黑名单
let g:ycm_filetype_blacklist = {
\ 'tagbar': 1,
\ 'qf': 1,
\ 'notes': 1,
\ 'unite': 1,
\ 'text': 1,
\ 'vimwiki': 1,
\ 'pandoc': 1,
\ 'infolog': 1,
\ 'mail': 1
\}
" 使用方法
" nmap <leader>gd :YcmDiags<CR>
" nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR> " 跳转到申明处
" nnoremap <leader>gf :YcmCompleter GoToDefinition<CR> " 跳转到定义处
" nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
" -----------------------------------------
" vim-easy-align
" -----------------------------------------
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" -----------------------------------------
" indentLine
" -----------------------------------------
let g:indentLine_color_gui = '#A4E57E'
" -----------------------------------------
" fzf
" -----------------------------------------
set rtp+=/usr/local/opt/fzf
Windows
在Windows 上,我主要使用GVim 作为文本编辑的工具使用,例如:缩进、在开头和结尾添加字符、大小写转换等
" -----------------------------------------
" Vundle
" -----------------------------------------
set nocompatible " be iMproved, required
filetype off " required
set rtp+=$HOME/.vim/bundle/Vundle.vim/
call vundle#begin('$HOME/.vim/bundle/')
Plugin 'VundleVim/Vundle.vim'
" 给选中的文本加分隔符 ()/[]/{}/''/""
Plugin 'https://github.com/tpope/vim-surround'
" 增强.命令
Plugin 'https://github.com/tpope/vim-repeat'
" 文件查找
Plugin 'https://github.com/Yggdroot/LeaderF'
" 跳转
Plugin 'https://github.com/easymotion/vim-easymotion'
Plugin 'https://github.com/justinmk/vim-sneak'
" 缓冲
Plugin 'https://github.com/vim-scripts/bufexplorer.zip'
" 主题
Plugin 'https://github.com/joshdick/onedark.vim'
" 自动闭合:单引号、双引号、括号
Plugin 'https://github.com/Raimondi/delimitMate'
" Markdown
Plugin 'https://github.com/mzlogin/vim-markdown-toc'
Plugin 'https://github.com/majutsushi/tagbar'
Plugin 'https://github.com/jszakmeister/markdown2ctags'
Plugin 'https://github.com/dhruvasagar/vim-table-mode'
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
" 模板补全
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
" 有道词典
Plugin 'https://github.com/ianva/vim-youdao-translater.git'
" 状态行
Plugin 'https://github.com/itchyny/lightline.vim'
" A solid language pack for Vim.
Plugin 'https://github.com/sheerun/vim-polyglot'
" Make scrolling in Vim more pleasant
Plugin 'https://github.com/terryma/vim-smooth-scroll'
" 可视模式
Plugin 'https://github.com/terryma/vim-expand-region'
" Org
Plugin 'https://github.com/jceb/vim-orgmode'
" 格式化代码
Plugin 'junegunn/vim-easy-align'
" 补全
Plugin 'https://github.com/Valloric/YouCompleteMe'
call vundle#end() " required
filetype plugin indent on " required
" -----------------------------------------
" 基础设置
" -----------------------------------------
" 设置字体
" set guifont=Source\ Code\ Pro\ for\ Powerline:h10
set guifont=Consolas:h12
" 不产生备份文件
set nobackup
" 不产生交换文件
set noswapfile
" 历史命令数
set history=1000
"使用vim键盘
set nocompatible
"解决退格键无法使用
set backspace=indent,eol,start
" 窗口大小
set lines=40 columns=150
" 行号
set nu
" 语法高亮
syntax enable
" 主题
colorscheme onedark
" 隐藏工具栏
set guioptions-=T
" -----------------------------------------
" 缩进
" -----------------------------------------
set ai
set shiftwidth=4
set tabstop=4
set sts=4
set expandtab
" -----------------------------------------
" 命令行补全方式
" -----------------------------------------
set wildmenu
set wildmode=full
" -----------------------------------------
" 编码
" -----------------------------------------
"默认编码
set encoding=utf-8
"vim 自动识别UTF8和GB2312
set fencs=utf-8,gbk,cp936
"中文乱码
set fileencoding=utf-8
set termencoding=utf-8
set fileencodings=utf-8,cp936,gbk,gb18030,gk2312,latin-1,ucs-bom,gb2312
"菜单乱码
" set langmenu=zh_CN.UTF-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" language messages zh_CN.utf-8
"终端乱码
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
"consle乱码
language messages zh_CN.utf-8
" -----------------------------------------
" KeyBinding
" -----------------------------------------
" 可视模式下,C-C 复制所选的内容到系统剪切板
vmap <c-c> "*y
" 插入模式下,C-V 粘贴系统剪切板内容到光标处
imap <c-v> <c-r>*
" -----------------------------------------
" DelimitMate
" -----------------------------------------
" 关闭Markdown 括号自动补全
let delimitMate_autoclose = 0
au FileType markdown let b:delimitMate_autoclose = 0
" -----------------------------------------
" easy-motion
" -----------------------------------------
let g:EasyMotion_leader_key='<Space>'
" -----------------------------------------
" Tagbar with Toc of markdown
" -----------------------------------------
" vim-markdown-top
let g:vmt_auto_update_on_save = 0
" ctags
let g:tagbar_ctags_bin = 'D:\software\ctags58\ctags.exe'
" markdown2ctags
let g:tagbar_type_markdown = {
\ 'ctagstype': 'markdown',
\ 'ctagsbin' : '~/.vim/bundle/markdown2ctags/markdown2ctags.py',
\ 'ctagsargs' : '-f - --sort=yes',
\ 'kinds' : [
\ 's:sections',
\ 'i:images'
\ ],
\ 'sro' : '|',
\ 'kind2scope' : {
\ 's' : 'section',
\ },
\ 'sort': 0,
\ }
" -----------------------------------------
" markdown : vim-table-mode
" -----------------------------------------
" 使用方法:TableModeEnable
function! s:isAtStartOfLine(mapping)
let text_before_cursor = getline('.')[0 : col('.')-1]
let mapping_pattern = '\V' . escape(a:mapping, '\')
let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\')
return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$')
endfunction
inoreabbrev <expr> <bar><bar>
\ <SID>isAtStartOfLine('\|\|') ?
\ '<c-o>:TableModeEnable<cr><bar><space><bar><left><left>' : '<bar><bar>'
inoreabbrev <expr> __
\ <SID>isAtStartOfLine('__') ?
\ '<c-o>:silent! TableModeDisable<cr>' : '__'
" -----------------------------------------
" vim-markdown-mode
" -----------------------------------------
" 使用方法
" zr: reduces fold level throughout the buffer
" zR: opens all folds
" zm: increases fold level throughout the buffer
" zM: folds everything all the way
" za: open a fold your cursor is on
" zA: open a fold your cursor is on recursively
" zc: close a fold your cursor is on
" zC: close a fold your cursor is on recursively
" -----------------------------------------
" 有道词典
" -----------------------------------------
vnoremap <silent> <C-T> :<C-u>Ydv<CR>
nnoremap <silent> <C-T> :<C-u>Ydc<CR>
noremap <leader>yd :<C-u>Yde<CR>
" -----------------------------------------
" matchit - 增强 % 命令
" -----------------------------------------
runtime macros/matchit.vim
" -----------------------------------------
" lightline.vim
" -----------------------------------------
let g:lightline = {
\ 'colorscheme': 'one',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head'
\ },
\ }
set laststatus=2
if !has('gui_running')
set t_Co=256
endif
set noshowmode
" -----------------------------------------
" ultisnips
" -----------------------------------------
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-f>"
let g:UltiSnipsJumpBackwardTrigger="<c-b>"
" -----------------------------------------
" netrw
" -----------------------------------------
let g:netrw_banner = 1
" -----------------------------------------
" YouCompleteMe
" -----------------------------------------
" 设置补全框行为
set completeopt=longest,menu
" 修改默认行为
let g:ycm_key_list_select_completion=['<c-n>','<Down>']
let g:ycm_key_list_previous_completion=['<c-p>','<Up>']
let g:ycm_confirm_extra_conf=0 " 关闭加载.ycm_extra_conf.py提示
let g:ycm_complete_in_comments = 1 " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1 " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全
let g:ycm_seed_identifiers_with_syntax=1 " 语言关键字补全
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_min_num_of_chars_for_completion=2 " 从第2个键入字符就开始罗列匹配项
" 引入,可以补全系统,以及python的第三方包 针对新老版本YCM做了兼容
" old version
if !empty(glob("~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py"))
let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py"
endif
" new version
if !empty(glob("~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"))
let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"
endif
" 白名单
let g:ycm_filetype_whitelist = {
\ 'markdown': 1,
\ 'python': 1
\}
" 黑名单
let g:ycm_filetype_blacklist = {
\ 'tagbar': 1,
\ 'qf': 1,
\ 'notes': 1,
\ 'unite': 1,
\ 'text': 1,
\ 'vimwiki': 1,
\ 'pandoc': 1,
\ 'infolog': 1,
\ 'mail': 1
\}
" 使用方法
" nmap <leader>gd :YcmDiags<CR>
" nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR> " 跳转到申明处
" nnoremap <leader>gf :YcmCompleter GoToDefinition<CR> " 跳转到定义处
" nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
" -----------------------------------------
" vim-easy-align
" -----------------------------------------
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" -----------------------------------------
" indentLine
" -----------------------------------------
let g:indentLine_color_gui = '#A4E57E'
if executable("vimtweak.dll")
autocmd guienter * call libcallnr("vimtweak","SetAlpha",200)
endif
网友评论