init.vim 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. " Show number line
  2. set number
  3. set relativenumber
  4. " TAB width
  5. set tabstop=4
  6. set shiftwidth=4
  7. set expandtab
  8. set softtabstop=4
  9. " Activate mouse
  10. set mouse=a
  11. " Cusor style (block)
  12. set guicursor=n-v-c:block-Cursor
  13. syntax on
  14. " COC OPTIONS
  15. " Set internal encoding of vim, not needed on neovim, since coc.nvim using some
  16. " unicode characters in the file autoload/float.vim
  17. set encoding=utf-8
  18. " TextEdit might fail if hidden is not set.
  19. set hidden
  20. " Some servers have issues with backup files, see #649.
  21. set nobackup
  22. set nowritebackup
  23. " Give more space for displaying messages.
  24. set cmdheight=2
  25. " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
  26. " delays and poor user experience.
  27. set updatetime=300
  28. " Don't pass messages to |ins-completion-menu|.
  29. set shortmess+=c
  30. " Always show the signcolumn, otherwise it would shift the text each time
  31. " diagnostics appear/become resolved.
  32. if has("nvim-0.5.0") || has("patch-8.1.1564")
  33. " Recently vim can merge signcolumn and number column into one
  34. set signcolumn=number
  35. else
  36. set signcolumn=yes
  37. endif
  38. " Use tab for trigger completion with characters ahead and navigate.
  39. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
  40. " other plugin before putting this into your config.
  41. inoremap <silent><expr> <TAB>
  42. \ pumvisible() ? "\<C-n>" :
  43. \ <SID>check_back_space() ? "\<TAB>" :
  44. \ coc#refresh()
  45. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  46. function! s:check_back_space() abort
  47. let col = col('.') - 1
  48. return !col || getline('.')[col - 1] =~# '\s'
  49. endfunction
  50. " Use <c-space> to trigger completion.
  51. if has('nvim')
  52. inoremap <silent><expr> <c-space> coc#refresh()
  53. else
  54. inoremap <silent><expr> <c-@> coc#refresh()
  55. endif
  56. " Make <CR> auto-select the first completion item and notify coc.nvim to
  57. " format on enter, <cr> could be remapped by other vim plugin
  58. inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
  59. \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  60. " Use `[g` and `]g` to navigate diagnostics
  61. " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
  62. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  63. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  64. " GoTo code navigation.
  65. nmap <silent> gd <Plug>(coc-definition)
  66. nmap <silent> gy <Plug>(coc-type-definition)
  67. nmap <silent> gi <Plug>(coc-implementation)
  68. nmap <silent> gr <Plug>(coc-references)
  69. " Use K to show documentation in preview window.
  70. nnoremap <silent> K :call <SID>show_documentation()<CR>
  71. function! s:show_documentation()
  72. if (index(['vim','help'], &filetype) >= 0)
  73. execute 'h '.expand('<cword>')
  74. elseif (coc#rpc#ready())
  75. call CocActionAsync('doHover')
  76. else
  77. execute '!' . &keywordprg . " " . expand('<cword>')
  78. endif
  79. endfunction
  80. " Highlight the symbol and its references when holding the cursor.
  81. autocmd CursorHold * silent call CocActionAsync('highlight')
  82. " Symbol renaming.
  83. nmap <leader>rn <Plug>(coc-rename)
  84. " Formatting selected code.
  85. xmap <leader>f <Plug>(coc-format-selected)
  86. nmap <leader>f <Plug>(coc-format-selected)
  87. augroup mygroup
  88. autocmd!
  89. " Setup formatexpr specified filetype(s).
  90. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  91. " Update signature help on jump placeholder.
  92. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  93. augroup end
  94. " Applying codeAction to the selected region.
  95. " Example: `<leader>aap` for current paragraph
  96. xmap <leader>a <Plug>(coc-codeaction-selected)
  97. nmap <leader>a <Plug>(coc-codeaction-selected)
  98. " Remap keys for applying codeAction to the current buffer.
  99. nmap <leader>ac <Plug>(coc-codeaction)
  100. " Apply AutoFix to problem on the current line.
  101. nmap <leader>qf <Plug>(coc-fix-current)
  102. " Run the Code Lens action on the current line.
  103. nmap <leader>cl <Plug>(coc-codelens-action)
  104. " Map function and class text objects
  105. " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
  106. xmap if <Plug>(coc-funcobj-i)
  107. omap if <Plug>(coc-funcobj-i)
  108. xmap af <Plug>(coc-funcobj-a)
  109. omap af <Plug>(coc-funcobj-a)
  110. xmap ic <Plug>(coc-classobj-i)
  111. omap ic <Plug>(coc-classobj-i)
  112. xmap ac <Plug>(coc-classobj-a)
  113. omap ac <Plug>(coc-classobj-a)
  114. " Remap <C-f> and <C-b> for scroll float windows/popups.
  115. if has('nvim-0.4.0') || has('patch-8.2.0750')
  116. nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  117. nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  118. inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  119. inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  120. vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  121. vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  122. endif
  123. " Use CTRL-S for selections ranges.
  124. " Requires 'textDocument/selectionRange' support of language server.
  125. nmap <silent> <C-s> <Plug>(coc-range-select)
  126. xmap <silent> <C-s> <Plug>(coc-range-select)
  127. " Add `:Format` command to format current buffer.
  128. command! -nargs=0 Format :call CocAction('format')
  129. " Add `:Fold` command to fold current buffer.
  130. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  131. " Add `:OR` command for organize imports of the current buffer.
  132. command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
  133. " Add (Neo)Vim's native statusline support.
  134. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  135. " provide custom statusline: lightline.vim, vim-airline.
  136. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  137. " Mappings for CoCList
  138. " Show all diagnostics.
  139. nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
  140. " Manage extensions.
  141. nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
  142. " Show commands.
  143. nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
  144. " Find symbol of current document.
  145. nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
  146. " Search workspace symbols.
  147. nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
  148. " Do default action for next item.
  149. nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
  150. " Do default action for previous item.
  151. nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
  152. " Resume latest coc list.
  153. nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
  154. " Plugins will be downloaded under the specified directory.
  155. call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
  156. " Declare the list of plugins.
  157. " Status line
  158. Plug 'itchyny/lightline.vim'
  159. " File explorer
  160. Plug 'scrooloose/nerdtree'
  161. " For web dev
  162. Plug 'mattn/emmet-vim'
  163. " Golang support
  164. Plug 'fatih/vim-go'
  165. " C/C++ support
  166. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  167. " Automatically close pairs
  168. Plug 'cohama/lexima.vim'
  169. " Icons
  170. Plug 'ryanoasis/vim-devicons'
  171. " Start screen
  172. Plug 'mhinz/vim-startify'
  173. " List ends here. Plugins become visible to Vim after this call.
  174. call plug#end()