Skip to content

Instantly share code, notes, and snippets.

@Luoyayu
Last active January 11, 2022 11:31
Show Gist options
  • Save Luoyayu/d15570dd0e511697a6fd5a8f857e193d to your computer and use it in GitHub Desktop.
Save Luoyayu/d15570dd0e511697a6fd5a8f857e193d to your computer and use it in GitHub Desktop.
coc init.vim
" Plugin Manager
call plug#begin(expand('~/.vim/plugged'))
" 主题
Plug 'arcticicestudio/nord-vim'
Plug 'tpope/vim-sensible'
Plug 'liuchengxu/space-vim-theme'
" 格式工具
Plug 'Yggdroot/indentLine' " 缩进显示
Plug 'scrooloose/nerdcommenter' " 注释工具
Plug 'luochen1990/rainbow' " 嵌套括号高亮
Plug 'mg979/vim-visual-multi', {'branch': 'master'} " 多游标控制
Plug 'mbbill/undotree' " 撤销树
Plug 'tmsvg/pear-tree' " 括号配对
" 状态栏
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" 状态栏插件
" Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " 文件浏览器
" Plug 'Xuyuanp/nerdtree-git-plugin' " 文件浏览器的Git插件
Plug 'ryanoasis/vim-devicons' " 图标
" 语言
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'pappasam/coc-jedi', { 'do': 'yarn install --frozen-lockfile && yarn build', 'branch': 'main' }
Plug 'cdelledonne/vim-cmake'
Plug 'bfrg/vim-cpp-modern'
Plug 'habamax/vim-asciidoctor'
Plug 'jackguo380/vim-lsp-cxx-highlight'
" 界面
Plug 'rafi/vim-sidemenu' " 右侧栏目菜单
Plug 'itchyny/vim-cursorword' " 相同单词下划线高亮
Plug 'norcalli/nvim-colorizer.lua' " high-performance color highlighter
" ~/.config/nvim/after/plugin/colorizer.vim
Plug 'vimwiki/vimwiki' " 个人 Wiki 插件
Plug 'mhinz/vim-startify' " VIM 开屏
Plug 'voldikss/vim-floaterm'
Plug 'majutsushi/tagbar' " ctags侧边栏
" 导航
Plug 'rhysd/accelerated-jk' " J-K 导航加速
Plug 'haya14busa/vim-edgemotion' " 边缘移动
Plug 'terryma/vim-expand-region' " 选区扩张
" 测试
Plug 'dstein64/vim-startuptime'
call plug#end()
" Set Right-Left as Meta in Iterm2 Profile Keys
let mapleader=','
let maplocalleader='\'
set rtp+=/usr/local/opt/fzf " :FZF
" Theme/colorscheme Setting
" -----------------------------------------------------------------------------
syntax enable
colorscheme space_vim_theme
let output = system("defaults read -g AppleInterfaceStyle")
if v:shell_error != 0
set background=light
"colorscheme lightcolorscheme
else
set background=dark
"colorscheme darkcolorschema
endif
"colorscheme nord
"set background=light
"let g:nord_italic = 1
"let g:nord_bold = 1
"let g:nord_italic_comments = 1
"let g:nord_underline = 1
"let g:nord_cursor_line_number_background = 1
"let g:nord_bold_vertical_split_line = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set nowrap " <leader>w to toggle
set wrap
set showbreak=↪
nnoremap <silent> <leader>w :set wrap! wrap?<CR>
set number " <leader>n to toggle
nnoremap <silent> <leader>n :set number! number?<CR>
set ruler
set cursorline
set laststatus=2 " 两行状态行+一行命令行
set noshowmode " 隐藏状态栏模式
set report=2
set colorcolumn=80
filetype on
filetype plugin on
filetype indent on
syntax on
set ts=4
set magic
set nospell
set history=2000
set mouse=a
set clipboard+=unnamed
set confirm
set autowriteall
set autochdir
set wildmenu wildmode=full
set noexpandtab " Don't expand tabs to spaces
set tabstop=2 " The number of spaces a tab is
set shiftwidth=2 " Number of spaces to use in auto(indent)
set backspace=2 " 使用 backspace 回删
set softtabstop=-1 " Automatically keeps in sync with shiftwidth
set smarttab " Tab insert blanks according to 'shiftwidth'
set autoindent " Use same indenting on new lines
set smartindent " Smart autoindenting on new lines
set shiftround " Round indent to multiple of 'shiftwidth'
set ignorecase " Search ignoring case
set smartcase " Keep case when searching with *
set infercase " Adjust case in insert completion mode
set incsearch " Incremental search
set wrapscan " Searches wrap around the end of the file
" 回到上次编辑的地方
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" Enables 24-bit RGB color in the terminal
if has('termguicolors')
if empty($COLORTERM) || $COLORTERM =~# 'truecolor\|24bit'
set termguicolors
endif
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: Yggdroot/indentLine "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" use conceal color with colorscheme
let g:indentLine_setColors = 0
let g:indentLine_char_list = ['|', '¦', '┆', '┊']
let g:indent_guides_guide_size = 1 " 指定对齐线的尺寸
let g:indent_guides_start_level = 2 " 从第二层开始可视化显示缩进
let g:indentLine_fileTypeExclude = [ 'startify', 'coc-explorer']
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: NERDTree "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let g:NERDCreateDefaultMappings = 1
"let g:NERDTreeGitStatusUseNerdFonts = 1
"let g:NERDTreeGitStatusIndicatorMapCustom = {
" \ 'Modified' :'✹',
" \ 'Staged' :'✚',
" \ 'Untracked' :'✭',
" \ 'Renamed' :'➜',
" \ 'Unmerged' :'═',
" \ 'Deleted' :'✖',
" \ 'Dirty' :'✗',
" \ 'Ignored' :'☒',
" \ 'Clean' :'✔︎',
" \ 'Unknown' :'?',
" \ }
"
"let g:NERDTreeDirArrowExpandable = ''
"let g:NERDTreeDirArrowCollapsible = ''
" 当NERDTree为剩下的唯一窗口时自动关闭
"autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"let NERDTreeIgnore = ['\.pyc$'] " 过滤所有.pyc文件不显示
"let g:NERDTreeShowLineNumbers=0 " 是否显示行号
"let g:NERDTreeHidden=0 " 不显示隐藏文件
"-----------------------------------------------------------------------------"
" toggle NERDTree
"nnoremap<silent> <leader>e :NERDTreeToggle<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: vim-floaterm "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:floaterm_keymap_new = '<Leader>ft'
nnoremap <silent> <F12> :FloatermToggle<CR>
tnoremap <silent> <F12> <C-\><C-n>:FloatermToggle<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: pear-tree "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:pear_tree_repeatable_expand=0
let g:pear_tree_map_special_keys = 0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: coc-explorer "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <leader>ce <Cmd>CocCommand explorer --sources buffer+,file+<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: startify "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:startify_lists = [
\ { 'type': 'files', 'header': [' * Most Recently Used'] },
\ { 'type': 'dir', 'header': [' * Most Recently Used in'. getcwd()] },
\ { 'type': 'sessions', 'header': [' * Sessions'] },
\ { 'type': 'bookmarks', 'header': [' * Bookmarks'] },
\ { 'type': 'commands', 'header': [' * Commands'] },
\ ]
let g:ascii_art = [
\' ',
\' ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗',
\' ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║',
\' ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║',
\' ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║',
\' ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║',
\' ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝',
\]
let g:startify_custom_header = startify#pad(ascii_art)
function! StartifyEntryFormat()
return 'WebDevIconsGetFileTypeSymbol(absolute_path) ." ". entry_path'
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: airline "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#tabline#buffer_idx_mode = 1
let g:airline_theme = 'solarized'
let g:airline_powerline_fonts = 1
"-----------------------------------------------------------------------------"
" 设置切换tab的快捷键 <leader> + <-> 切换到前一个 tab
nmap <leader>- <Plug>AirlineSelectPrevTab
" 设置切换tab的快捷键 <leader> + <+> 切换到后一个 tab
nmap <leader>= <Plug>AirlineSelectNextTab
" 设置切换tab的快捷键 <leader> + <bq> 退出当前的 tab
nmap <leader>bq :bp<cr>:bd #<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: VIM-EXPAND-REGION "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 扩大选择区域
xmap v <Plug>(expand_region_expand)
" 缩小选择区域
xmap V <Plug>(expand_region_shrink)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: accelerated-jk
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap j <Plug>(accelerated_jk_gj)
nmap k <Plug>(accelerated_jk_gk)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: vim-sidemenu "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <Leader>l <Plug>(sidemenu)
xmap <Leader>l <Plug>(sidemenu-visual)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: EdgeMotion "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <C-j> <Plug>(edgemotion-j)
map <C-k> <Plug>(edgemotion-k)
xmap <C-j> <Plug>(edgemotion-j)
xmap <C-k> <Plug>(edgemotion-k)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: Tagbar "
nnoremap <silent> <leader>b :TagbarToggle<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: undotree
nnoremap <Leader>gu :UndotreeToggle<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Customed Key Mappings "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <silent> <leader>q :q<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Clipboard "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has('mac') && has('vim_starting')
let g:clipboard = {
\ 'name': 'macOS-clipboard',
\ 'copy': {
\ '+': 'pbcopy',
\ '*': 'pbcopy',
\ },
\ 'paste': {
\ '+': 'pbpaste',
\ '*': 'pbpaste',
\ },
\ 'cache_enabled': 0,
\ }
endif
if has('clipboard') && has('vim_starting')
" set clipboard& clipboard+=unnamedplus
set clipboard& clipboard^=unnamed,unnamedplus
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: vim-cmake "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:cmake_link_compile_commands=1
let g:cmake_generate_options=["-G Ninja"]
let g:cmake_root_markers=["CMakeLists.txt"]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: vimwiki "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Almost cann't wirte with Coc.vim becasuse of the default <CR> behavior.
nmap <silent> <leader>w<CR> <Plug>VimwikiFollowLink
vmap <silent> <leader>w<CR> <Plug>VimwikiFollowLink
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin: Coc.vim settings "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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 column 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 <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nnoremap <silent><nowait> <leader>gd :call CocAction('jumpDefinition', v:false)<CR>
nnoremap <silent><nowait> <leader>gy :call CocAction('jumpTypeDefinition', v:false)<CR>
nnoremap <silent><nowait> <leader>gi :call CocAction('jumpImplementation', v:false)<CR>
nnoremap <silent><nowait> <leader>gr :call CocAction('jumpReference', v:false)<CR>
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(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
inoremap <silent> ,s <c-r>=CocActionAsync('showSignatureHelp')<CR>
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Run the Code Lens action on the current line.
nmap <leader>cl <Plug>(coc-codelens-action)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
nmap <silent><M-c> :call CocAction('format')<CR>
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" 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 <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
inoremap <silent><expr> <TAB>
\ pumvisible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <silent><expr> <S-TAB>
\ pumvisible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ <SID>check_back_space() ? "\<S-TAB>" :
\ coc#refresh()
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'
let g:coc_snippet_prev = '<s-tab>'
@Luoyayu
Copy link
Author

Luoyayu commented Jan 11, 2022

  • ✓ coc-clangd Current version 0.18.2 is up to date.
  • ✓ coc-cmake Current version 0.2.0 is up to date.
  • ✓ coc-explorer Current version 0.20.2 is up to date.
  • ✓ coc-floaterm Current version 0.2.2 is up to date.
  • ✓ coc-git Current version 2.4.4 is up to date.
  • ✓ coc-go Current version 1.1.0 is up to date.
  • ✓ coc-highlight Current version 1.2.8 is up to date.
  • ✓ coc-json Current version 1.4.0 is up to date.
  • ✓ coc-sh Current version 0.6.1 is up to date.
  • ✓ coc-snippets Current version 2.4.7 is up to date.
  • ✓ coc-solargraph Current version 1.2.3 is up to date.
  • ✓ coc-syntax Current version 1.2.4 is up to date.
  • ✓ coc-texlab Current version 3.2.0 is up to date.
  • ✓ coc-vimlsp Current version 0.12.5 is up to date.
  • ✓ coc-yaml Current version 1.6.1 is up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment