vimrc配置
“===============================
“设置basic setting
“===============================
set nocompatible “设置非兼容模式
set nobackup “设置不备份,不生成临时缓存文件
“ 设置 Backspace 键模式
set bs=eol,start,indent
“ Windows 禁用 ALT 操作菜单(使得 ALT 可以用到 Vim里)
set winaltkeys=no
“ 关闭自动换行
set nowrap
“ 打开功能键超时检测(终端下功能键为一串 ESC 开头的字符串)
set ttimeout
“ 功能键超时检测 50 毫秒
set ttimeoutlen=50
“设置主体颜色为molakai
colorscheme molokai
let g:molokai_original = 1
let g:rehash256 = 1
set t_Co=256
set background=dark
set cursorline “突出显示当前行
“set cursorcolumn “突出显示当前列
set showmatch “输入右括号时自动显示匹配的左括号
set showcmd “显示输入的指令
autocmd BufWritePost MYVIMRC “保存vimrc的时候自动执行
set noerrorbells “错误时候不响铃
set visualbell “错误时候显示成视觉效果
set number “显示行号
set relativenumber “换的不是文件的字符,而是屏幕上占据的位置。见enumber “显示相对行号
set wrap “自动换行
“———————————————————————-
“ 搜索设置
“———————————————————————-:
set ignorecase “搜索时忽略大小写
set smartcase “搜索时包含大写字母时,忽略上一条。
set hlsearch “搜索结果高亮
set incsearch “搜索结果自动模糊匹配,光标自动跳转
set wildmenu “命令行自动补齐
set scrolloff =5 “ 光标移动到窗口上下边缘时保留的行数
set lazyredraw “延时绘制,增加性能
“———————————————————————-
“ 缩进相关设置
“———————————————————————-
set autoindent “自动缩进,继承前一行的缩进方式,适用于多行注释
set smartindent “智能缩进
set tabstop=4 “设置 tab 制表符所占宽度为 4
set softtabstop=4 “设置按 tab 时缩进的宽度为 4
set shiftwidth=4 “设置自动缩进宽度为 4
set expandtab “缩进时将 tab 制表符转换为空格
“set go=
filetype on “开启文件类型检测
syntax on “开启语法高亮
“autocmd InsertLeave * se nocul “ 用浅色高亮当前行
“autocmd InsertEnter * se cul “ 用浅色高亮当前行
“———————————————————————-
“ 设置代码折叠
“———————————————————————-
if has(‘folding’)
“ 允许代码折叠
set foldenable
“ 代码折叠默认使用缩进
set fdm=indent
“ 默认打开所有缩进
set foldlevel=99
endif
:set mouse=a “设置开启鼠标功能,如:选中代码块,移动光标位置,打开文件等
“———————————————————————-
“ 显示中文帮助
“———————————————————————-
if version >= 603
set helplang=cn
set encoding=utf-8
endif
“===============================
“vim插件管理
“安装新插件命令为:PluginInsttall
“===============================
noremap pi :PlugInstall
let fmt = get(g:, ‘klug_url_format’, ‘git::@hub.fastgit.org/%s.git')
call plug#begin(‘~/.vim/plugged’)
Plug ‘scrooloose/nerdtree’, { ‘on’: ‘NERDTreeToggle’ }
Plug ‘vim-airline/vim-airline’ | Plug ‘vim-airline/vim-airline-themes’
Plug ‘yianwillis/vimcdoc’
Plug ‘jiangmiao/auto-pairs’
Plug ‘neoclide/coc.nvim’, {‘branch’: ‘release’}
call plug#end()
“===============================
“映射快捷键map
“查看映射之后的快捷键可以用:verbose imap 来检查配置的是否正确。
“===============================
“插件快捷键,NERDTree快捷键
map :NERDTreeToggle
“ - 快速移动
“ - 标签切换
“ - 窗口切换
“ - 终端支持
“ - 编译运行
“ - 符号搜索
“———————————————————————-
“EMACS 键位与一些个人使用习惯
“———————————————————————-
inoremap jj
inoremap
inoremap
inoremap
inoremap
inoremap
inoremap
inoremap
inoremap “输入二合字符,如:日语◊ќ♢等等,一般用不到
noremap I
noremap A
“———————————————————————-
“” 设置 CTRL+HJKL 移动光标(INSERT 模式偶尔需要移动的方便些)
“ “———————————————————————-
noremap
noremap
inoremap
inoremap
inoremap
inoremap
“———————————————————————-
“ 窗口切换:ALT+SHIFT+hjkl
“———————————————————————-
noremap h
noremap l
noremap j
noremap k
inoremap h
inoremap l
inoremap j
inoremap k
“===============================
“如果用的不是neovim,需要进行如下配置:
“更改终端访问vim的时候的meta/alt键映射
“===============================
if !has(‘nvim’)
function! s:metacode(key)
execute “set <m-“.a:key.”>=\e”.a:key
endfunc
for i in range(10)
call s:metacode(nr2char(char2nr(‘0’)+i))
endfor
for i in range(26)
call s:metacode(nr2char(char2nr(‘a’)+i))
call s:metacode(nr2char(char2nr(‘A’)+i))
endfor
for c in [‘,’,’.’,’/‘,’;’,’{‘,’}’,’?’,’:’,’-‘,’_’]
call s:metacode(c)
endfor
set ttimeoutlen=50
endif
“===============================
“coc配置
“===============================
“ Set internal encoding of vim, not needed on neovim, since coc.nvim using some
“ unicode characters in the file autoload/float.vim
set encoding=utf-8
“ TextEdit might fail if hidden is not set.
set hidden
“ Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
“ Give more space for displaying messages.
set cmdheight=2
“ Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
“ delays and poor user experience.
set updatetime=300
“ Don’t pass messages to |ins-completion-menu|.
set shortmess+=c
“ Always show the signcolumn, otherwise it would shift the text each time
“ diagnostics appear/become resolved.
if has(“nvim-0.5.0”) || has(“patch-8.1.1564”)
“ Recently vim can merge signcolumn and number colmn into one
set signcolumn=number
else
set signcolumn=yes
endif
“ Use tab for trigger completion with characters ahead and navigate.
“ NOTE: Use command ‘:verbose imap ‘ to make sure tab is not mapped by
“ other plugin before putting this into your config.
inoremap
\ pumvisible() ? “” :
\ check_back_space() ? “” :
\ coc#refresh()
inoremap pumvisible() ? “” : “”
function! s:check_back_space() abort
let col = col(‘.’) - 1
return !col || getline(‘.’)[col - 1] =~# ‘\s’
endfunction
“ Use to trigger completion.
if has(‘nvim’)
inoremap coc#refresh()
else
inoremap <c-@> coc#refresh()
endif
“ Make auto-select the first completion item and notify coc.nvim to
“ format on enter, could be remapped by other vim plugin
inoremap pumvisible() ? coc#_select_confirm()
: “u=coc#on_enter()”
“ Use [g and ]g to navigate diagnostics
“ Use :CocDiagnostics to get all diagnostics of current buffer in location list.
nmap [g (coc-diagnostic-prev)
nmap ]g (coc-diagnostic-next)
“ GoTo code navigation.
nmap gd (coc-definition)
nmap gy (coc-type-definition)
nmap gi (coc-implementation)
nmap gr (coc-references)
“ Use K to show documentation in preview window.
nnoremap K :call show_documentation()
function! s:show_documentation()
if (index([‘vim’,’help’], &filetype) >= 0)
execute ‘h ‘.expand(‘‘)
elseif (coc#rpc#ready())
call CocActionAsync(‘doHover’)
else
execute ‘!’ . &keywordprg . “ “ . expand(‘‘)
endif
endfunction
“ Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync(‘highlight’)
“ Symbol renaming.
nmap rn (coc-rename)
“ Formatting selected code.
xmap f (coc-format-selected)
nmap f (coc-format-selected)
augroup mygroup
autocmd!
“ Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction(‘formatSelected’)
“ Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync(‘showSignatureHelp’)
augroup end
“ Applying codeAction to the selected region.
“ Example: <leader>aap for current paragraph
xmap a (coc-codeaction-selected)
nmap a (coc-codeaction-selected)
“ Remap keys for applying codeAction to the current buffer.
nmap ac (coc-codeaction)
“ Apply AutoFix to problem on the current line.
nmap qf (coc-fix-current)
“ Run the Code Lens action on the current line.
nmap cl (coc-codelens-action)
“ Map function and class text objects
“ NOTE: Requires ‘textDocument.documentSymbol’ support from the language server.
xmap if (coc-funcobj-i)
omap if (coc-funcobj-i)
xmap af (coc-funcobj-a)
omap af (coc-funcobj-a)
xmap ic (coc-classobj-i)
omap ic (coc-classobj-i)
xmap ac (coc-classobj-a)
omap ac (coc-classobj-a)
“ Remap and for scroll float windows/popups.
if has(‘nvim-0.4.0’) || has(‘patch-8.2.0750’)
nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : “”
nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : “”
inoremap coc#float#has_scroll() ? “=coc#float#scroll(1)” : “”
inoremap coc#float#has_scroll() ? “=coc#float#scroll(0)” : “”
vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : “”
vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : “”
endif
“ Use CTRL-S for selections ranges.
“ Requires ‘textDocument/selectionRange’ support of language server.
nmap (coc-range-select)
xmap (coc-range-select)
“ Add :Format command to format current buffer.
command! -nargs=0 Format :call CocActionAsync(‘format’)
“ Add :Fold command to fold current buffer.
command! -nargs=? Fold :call CocAction(‘fold’, )
“ Add :OR command for organize imports of the current buffer.
command! -nargs=0 OR :call CocActionAsync(‘runCommand’, ‘editor.action.organizeImport’)
“ Add (Neo)Vim’s native statusline support.
“ NOTE: Please see :h coc-status for integrations with external plugins that
“ provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,’coc_current_function’,’’)}
“ Mappings for CoCList
“ Show all diagnostics.
nnoremap a :CocList diagnostics
“ Manage extensions.
nnoremap e :CocList extensions
“ Show commands.
nnoremap c :CocList commands
“ Find symbol of current document.
nnoremap o :CocList outline
“ Search workspace symbols.
nnoremap s :CocList -I symbols
“ Do default action for next item.
nnoremap j :CocNext
“ Do default action for previous item.
nnoremap k :CocPrev
“ Resume latest coc list.
nnoremap p :CocListResume
“coc插件配置完毕
“===============================