You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
6.6 KiB

3 years ago
8 years ago
3 years ago
8 years ago
3 years ago
8 years ago
3 years ago
3 years ago
8 years ago
3 years ago
3 years ago
7 years ago
3 years ago
3 years ago
  1. "------------------------------------------------
  2. " Plugins START
  3. call plug#begin()
  4. Plug 'airblade/vim-gitgutter'
  5. Plug 'cespare/vim-toml'
  6. Plug 'editorconfig/editorconfig-vim'
  7. Plug 'itchyny/lightline.vim'
  8. Plug 'junegunn/vim-easy-align'
  9. Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
  10. Plug 'junegunn/fzf.vim'
  11. Plug 'mengelbrecht/lightline-bufferline'
  12. Plug 'lifepillar/vim-gruvbox8'
  13. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  14. Plug 'tpope/vim-commentary'
  15. call plug#end()
  16. " Plugins END
  17. "------------------------------------------------
  18. "------------------------------------------------
  19. " Settings START
  20. let mapleader = "\<Space>"
  21. filetype plugin on
  22. set completeopt=menuone
  23. set mouse=a
  24. set nobackup
  25. set nocompatible
  26. set noswapfile
  27. set nowritebackup
  28. set number
  29. set signcolumn=yes
  30. set title
  31. set wrap
  32. setlocal wrap
  33. " Settings END
  34. "------------------------------------------------
  35. "------------------------------------------------
  36. " persist START
  37. set undofile " Maintain undo history between sessions
  38. set undodir=~/.vim/undodir
  39. " Persist cursor
  40. autocmd BufReadPost *
  41. \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
  42. \ | exe "normal! g`\""
  43. \ | endif
  44. " persist END
  45. "------------------------------------------------
  46. "------------------------------------------------
  47. " Theme START
  48. syntax on
  49. set termguicolors
  50. colorscheme gruvbox8
  51. set background=dark
  52. set cursorline
  53. set hidden
  54. set cmdheight=1
  55. set laststatus=2
  56. let g:gruvbox_transp_bg = 1
  57. let g:gruvbox_italicize_strings = 0
  58. set list
  59. set listchars=tab:»·,trail
  60. " let buffers be clickable
  61. let g:lightline#bufferline#clickable=1
  62. let g:lightline#bufferline#shorten_path=1
  63. let g:lightline#bufferline#min_buffer_count=1
  64. let g:lightline = {
  65. \ 'colorscheme': 'jellybeans',
  66. \ 'active': {
  67. \ 'left': [ [], [], [ 'relativepath' ] ],
  68. \ 'right': [ [], [], [ 'lineinfo', 'percent' ] ]
  69. \ },
  70. \ 'inactive': {
  71. \ 'left': [ [], [], [ 'relativepath' ] ],
  72. \ 'right': [ [], [], [ 'lineinfo', 'percent' ] ]
  73. \ },
  74. \ 'subseparator': {
  75. \ 'left': '', 'right': ''
  76. \ },
  77. \ 'tabline': {
  78. \ 'left': [ ['buffers'] ],
  79. \ 'right': [ [] ]
  80. \ },
  81. \ 'tabline_separator': {
  82. \ 'left': "", 'right': ""
  83. \ },
  84. \ 'tabline_subseparator': {
  85. \ 'left': "", 'right': ""
  86. \ },
  87. \ 'component_expand': {
  88. \ 'buffers': 'lightline#bufferline#buffers'
  89. \ },
  90. \ 'component_raw': {
  91. \ 'buffers': 1
  92. \ },
  93. \ 'component_type': {
  94. \ 'buffers': 'tabsel'
  95. \ }
  96. \}
  97. " Theme END
  98. "------------------------------------------------
  99. "------------------------------------------------
  100. " Remaps START
  101. " Align GitHub-flavored Markdown tables
  102. au FileType markdown vmap <Leader><Bslash> :EasyAlign*<Bar><Enter>
  103. " Toggle between buffers
  104. nmap <Leader>bn :bn<CR>
  105. nmap <Leader>bp :bp<CR>
  106. nnoremap <C-p> :Rg<Cr>
  107. nnoremap <C-e> :Files<Cr>
  108. nmap <Leader>bl :Buffers<CR>
  109. nmap <Leader>g :GFiles<CR>
  110. nmap <Leader>e :Files<CR>
  111. nmap <Leader>p :Rg<CR>
  112. nmap <Leader>g? :GFiles?<CR>
  113. nmap <Leader>h :History<CR>
  114. " Remaps END
  115. "------------------------------------------------
  116. "------------------------------------------------
  117. " Coc START
  118. " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
  119. " delays and poor user experience.
  120. set updatetime=300
  121. " Don't pass messages to |ins-completion-menu|.
  122. set shortmess+=c
  123. " Use tab for trigger completion with characters ahead and navigate.
  124. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
  125. " other plugin before putting this into your config.
  126. inoremap <silent><expr> <TAB>
  127. \ pumvisible() ? "\<C-n>" :
  128. \ <SID>check_back_space() ? "\<TAB>" :
  129. \ coc#refresh()
  130. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  131. function! s:check_back_space() abort
  132. let col = col('.') - 1
  133. return !col || getline('.')[col - 1] =~# '\s'
  134. endfunction
  135. " Use <c-space> to trigger completion.
  136. if has('nvim')
  137. inoremap <silent><expr> <c-space> coc#refresh()
  138. else
  139. inoremap <silent><expr> <c-@> coc#refresh()
  140. endif
  141. " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
  142. " position. Coc only does snippet and additional edit on confirm.
  143. " <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
  144. if exists('*complete_info')
  145. inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
  146. else
  147. inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
  148. endif
  149. " Use `[g` and `]g` to navigate diagnostics
  150. " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
  151. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  152. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  153. " GoTo code navigation.
  154. nmap <silent> gd <Plug>(coc-definition)
  155. nmap <silent> gy <Plug>(coc-type-definition)
  156. nmap <silent> gi <Plug>(coc-implementation)
  157. nmap <silent> gr <Plug>(coc-references)
  158. " Use K to show documentation in preview window.
  159. nnoremap <silent> K :call <SID>show_documentation()<CR>
  160. function! s:show_documentation()
  161. if (index(['vim','help'], &filetype) >= 0)
  162. execute 'h '.expand('<cword>')
  163. else
  164. call CocActionAsync('doHover')
  165. endif
  166. endfunction
  167. " Highlight the symbol and its references when holding the cursor.
  168. autocmd CursorHold * silent call CocActionAsync('highlight')
  169. " Symbol renaming.
  170. nmap <leader>rn <Plug>(coc-rename)
  171. " Formatting selected code.
  172. xmap <leader>f <Plug>(coc-format-selected)
  173. nmap <leader>f <Plug>(coc-format-selected)
  174. augroup mygroup
  175. autocmd!
  176. " Setup formatexpr specified filetype(s).
  177. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  178. " Update signature help on jump placeholder.
  179. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  180. augroup end
  181. " Remap keys for applying codeAction to the current buffer.
  182. nmap <leader>ga <Plug>(coc-codeaction)
  183. " Apply AutoFix to problem on the current line.
  184. nmap <leader>qf <Plug>(coc-fix-current)
  185. " Add `:Format` command to format current buffer.
  186. command! -nargs=0 Format :call CocAction('format')
  187. " Add `:Fold` command to fold current buffer.
  188. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  189. " Add `:OR` command for organize imports of the current buffer.
  190. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  191. " Mappings for CoCList
  192. " Show all diagnostics.
  193. nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
  194. " Show commands.
  195. nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
  196. " Find symbol of current document.
  197. nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
  198. " Search workspace symbols.
  199. nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
  200. " Do default action for next item.
  201. nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
  202. " Do default action for previous item.
  203. nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>