Skip to content

Commit 018e013

Browse files
author
Andreas Pataki
committed
Make vim ready for modern software development by using coc.nvim
1 parent d428497 commit 018e013

File tree

5 files changed

+185
-86
lines changed

5 files changed

+185
-86
lines changed

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
1. `git clone http://github.com/code2k/dot_vim.git .vim` into your home
66
folder.
77
2. `cd .vim`
8-
3. `./bootstap.sh` (ignore the initial vim error)
8+
3. `./bootstap.sh`
9+
4. Vim plugins will be installed on the first start.
910

1011
If you need to modify this configuration just add a `.vimrc.local` and/or
1112
`.gvimrc.local` in your home directory.
@@ -18,19 +19,19 @@ If you need to modify this configuration just add a `.vimrc.local` and/or
1819
- [vim-airline](https://github.com/vim-airline/vim-airline)
1920
- [vim-airline-themes](https://github.com/vim-airline/vim-airline-themes)
2021
- [ctrlp.vim](https://github.com/ctrlpvim/ctrlp.vim)
21-
- [delimitMate](https://github.com/Raimondi/delimitMate)
22-
- [neocomplcache](https://github.com/Shougo/neocomplcache)
22+
- [coc.nvim](https://github.com/neoclide/coc.nvim)
23+
- [vim-textobj-user](https://github.com/kana/vim-textobj-user)
24+
- [vim-textobj-indent](https://github.com/kana/vim-textobj-indent)
25+
- [vim-textobj-line](https://github.com/kana/vim-textobj-line)
26+
- [vim-textobj-entire](https://github.com/kana/vim-textobj-entire)
27+
- [vim-expand-region](https://github.com/terryma/vim-expand-region)
2328
- [tabular](https://github.com/godlygeek/tabular)
2429
- [vim-indexed-search](https://github.com/henrik/vim-indexed-search)
2530
- [vim-snippets](https://github.com/honza/vim-snippets)
2631
- [emmet-vim](https://github.com/mattn/emmet-vim)
2732
- [ack.vim](https://github.com/mileszs/ack.vim)
28-
- [syntastic](https://github.com/scrooloose/syntastic)
29-
- [ultisnips](https://github.com/sirver/ultisnips)
3033
- [gundo.vim](https://github.com/sjl/gundo.vim)
31-
- [vim-space](https://github.com/spiiph/vim-space)
3234
- [vim-commentary](https://github.com/tpope/vim-commentary)
33-
- [vim-endwise](https://github.com/tpope/vim-endwise)
3435
- [vim-eunuch](https://github.com/tpope/vim-eunuch)
3536
- [vim-fugitive](https://github.com/tpope/vim-fugitive)
3637
- [vim-repeat](https://github.com/tpope/vim-repeat)
@@ -39,6 +40,16 @@ If you need to modify this configuration just add a `.vimrc.local` and/or
3940
- [vim-vinegar](https://github.com/tpope/vim-vinegar)
4041
- [ZoomWin](https://github.com/vim-scripts/ZoomWin)
4142

43+
## coc.nvim
44+
45+
Initially there are only a few essential coc.nvim extensions installed.
46+
47+
For a better more VSCode like experience, install the following extensions:
48+
49+
```
50+
:CocInstall coc-css coc-eslint coc-html coc-json coc-prettier coc-tailwindcss coc-tsserver coc-tslint-plugin coc-yaml
51+
```
52+
4253
## Credits
4354

4455
This vim configuration is a mix from these excellent configurations:

coc-settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"coc.preferences.formatOnSaveFiletypes": [
3+
"css",
4+
"html",
5+
"jascriptreact",
6+
"javascript",
7+
"json",
8+
"markdown",
9+
"typescript",
10+
"typescriptreact"
11+
],
12+
"diagnostic-languageserver.filetypes": {
13+
"sh": "shellcheck"
14+
}
15+
}
16+

gvimrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ if has("autocmd")
2222
autocmd VimResized * wincmd =
2323
endif
2424

25-
set lines=60
25+
set linespace=1
26+
set lines=56
2627
set columns=140
2728

2829
set mousemodel=popup

plugins.vim

Lines changed: 142 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,150 @@
11
" ---------------
2-
" Airline
2+
" coc.nvim
33
" ---------------
4-
let g:airline_powerline_fonts=1
4+
let g:coc_global_extensions = [
5+
\ 'coc-diagnostic',
6+
\ 'coc-marketplace',
7+
\ 'coc-pairs',
8+
\ 'coc-snippets',
9+
\ 'coc-vimlsp',
10+
\ ]
11+
12+
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
13+
" delays and poor user experience.
14+
set updatetime=300
15+
16+
" Don't pass messages to |ins-completion-menu|.
17+
set shortmess+=c
18+
19+
" Always show the signcolumn, otherwise it would shift the text each time
20+
" diagnostics appear/become resolved.
21+
set signcolumn=yes
22+
23+
" Use tab for trigger completion with characters ahead and navigate.
24+
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
25+
" other plugin before putting this into your config.
26+
inoremap <silent><expr> <TAB>
27+
\ pumvisible() ? "\<C-n>" :
28+
\ <SID>check_back_space() ? "\<TAB>" :
29+
\ coc#refresh()
30+
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
31+
32+
function! s:check_back_space() abort
33+
let col = col('.') - 1
34+
return !col || getline('.')[col - 1] =~# '\s'
35+
endfunction
36+
37+
" Use <c-space> to trigger completion.
38+
inoremap <silent><expr> <c-space> coc#refresh()
39+
40+
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
41+
" position. Coc only does snippet and additional edit on confirm.
42+
if exists('*complete_info')
43+
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
44+
else
45+
imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
46+
endif
47+
48+
" Use `[g` and `]g` to navigate diagnostics
49+
nmap <silent> [g <Plug>(coc-diagnostic-prev)
50+
nmap <silent> ]g <Plug>(coc-diagnostic-next)
51+
nmap <silent> <leader><s-space> <Plug>(coc-diagnostic-prev)
52+
nmap <silent> <leader><space> <Plug>(coc-diagnostic-next)
53+
54+
" GoTo code navigation.
55+
nmap <silent> gd <Plug>(coc-definition)
56+
nmap <silent> gy <Plug>(coc-type-definition)
57+
nmap <silent> gi <Plug>(coc-implementation)
58+
nmap <silent> gr <Plug>(coc-references)
59+
60+
" Use K to show documentation in preview window.
61+
nnoremap <silent> K :call <SID>show_documentation()<CR>
62+
63+
function! s:show_documentation()
64+
if (index(['vim','help'], &filetype) >= 0)
65+
execute 'h '.expand('<cword>')
66+
else
67+
call CocAction('doHover')
68+
endif
69+
endfunction
70+
71+
" Highlight the symbol and its references when holding the cursor.
72+
autocmd CursorHold * silent call CocActionAsync('highlight')
73+
74+
" Symbol renaming.
75+
nmap <leader>rn <Plug>(coc-rename)
76+
77+
" Formatting selected code.
78+
xmap <leader>f <Plug>(coc-format-selected)
79+
" nmap <leader>f <Plug>(coc-format-selected)
80+
81+
augroup mygroup
82+
autocmd!
83+
" Setup formatexpr specified filetype(s).
84+
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
85+
" Update signature help on jump placeholder.
86+
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
87+
augroup end
88+
89+
" Applying codeAction to the selected region.
90+
" Example: `<leader>aap` for current paragraph
91+
xmap <leader>a <Plug>(coc-codeaction-selected)
92+
nmap <leader>a <Plug>(coc-codeaction-selected)
93+
94+
" Remap keys for applying codeAction to the current line.
95+
nmap <leader>ac <Plug>(coc-codeaction)
96+
" Apply AutoFix to problem on the current line.
97+
nmap <leader>qf <Plug>(coc-fix-current)
98+
99+
" Introduce function text object
100+
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
101+
xmap if <Plug>(coc-funcobj-i)
102+
xmap af <Plug>(coc-funcobj-a)
103+
omap if <Plug>(coc-funcobj-i)
104+
omap af <Plug>(coc-funcobj-a)
105+
106+
" Use <TAB> for selections ranges.
107+
" NOTE: Requires 'textDocument/selectionRange' support from the language server.
108+
" coc-tsserver, coc-python are the examples of servers that support it.
109+
nmap <silent> <TAB> <Plug>(coc-range-select)
110+
xmap <silent> <TAB> <Plug>(coc-range-select)
111+
112+
" Add `:Format` command to format current buffer.
113+
command! -nargs=0 Format :call CocAction('format')
114+
115+
" Add `:Fold` command to fold current buffer.
116+
command! -nargs=? Fold :call CocAction('fold', <f-args>)
117+
118+
" Add `:OR` command for organize imports of the current buffer.
119+
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
120+
121+
" Add (Neo)Vim's native statusline support.
122+
" NOTE: Please see `:h coc-status` for integrations with external plugins that
123+
" provide custom statusline: lightline.vim, vim-airline.
124+
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
125+
126+
" Mappings using CoCList:
127+
" Show all diagnostics.
128+
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
129+
" Manage extensions.
130+
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
131+
" Show commands.
132+
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
133+
" Find symbol of current document.
134+
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
135+
" Search workspace symbols.
136+
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
137+
" Do default action for next item.
138+
nnoremap <silent> <space>j :<C-u>CocNext<CR>
139+
" Do default action for previous item.
140+
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
141+
" Resume latest coc list.
142+
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
5143
6144
" ---------------
7-
" bclose
145+
" Airline
8146
" ---------------
9-
cmap bd Bclose
147+
let g:airline_powerline_fonts=1
10148

11149
" ---------------
12150
" CtrlP
@@ -49,65 +187,6 @@ endif
49187

50188
nnoremap ,u :GundoToggle<CR>
51189
52-
" ---------------
53-
" syntastic
54-
" ---------------
55-
let g:syntastic_javascript_checkers = ['jshint']
56-
let g:syntastic_enable_signs=1
57-
"let g:syntastic_quiet_messages = {'level': 'warnings'}
58-
let g:syntastic_auto_loc_list=2
59-
60-
" ---------------
61-
" neocomplcache
62-
" ---------------
63-
let g:neocomplcache_enable_at_startup = 1
64-
let g:neocomplcache_enable_camel_case_completion = 1
65-
let g:neocomplcache_enable_underbar_completion = 0
66-
let g:neocomplcache_enable_fuzzy_completion = 1
67-
let g:neocomplcache_enable_fuzzy_completion_start_length = 2
68-
let g:neocomplcache_enable_smart_case = 1
69-
let g:neocomplcache_force_overwrite_completefunc = 1
70-
let g:neocomplcache_max_list = 20
71-
"let g:neocomplcache_disable_auto_complete = 1
72-
let g:neocomplcache_min_syntax_length = 3
73-
let g:neocomplcache_auto_completion_start_length = 2
74-
let g:neocomplcache_manual_completion_start_length = 0
75-
let g:neocomplcache_enable_auto_delimiter = 1
76-
77-
" Define keyword.
78-
if !exists('g:neocomplcache_keyword_patterns')
79-
let g:neocomplcache_keyword_patterns = {}
80-
endif
81-
let g:neocomplcache_keyword_patterns['default'] = '\h\w*'
82-
83-
"let g:neocomplcache_snippets_dir = $HOME . '/bundle/vim-snippets'
84-
85-
" ruby omni completion fix
86-
" http://osdir.com/ml/editors.vim.vim-ruby.devel/2007-02/msg00008.html
87-
if has("ruby")
88-
silent! ruby nil
89-
endif
90-
" Enable omni completion.
91-
autocmd FileType css,less setlocal omnifunc=csscomplete#CompleteCSS
92-
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
93-
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
94-
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
95-
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
96-
autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
97-
" Enable heavy omni completion.
98-
if !exists('g:neocomplcache_omni_patterns')
99-
let g:neocomplcache_omni_patterns = {}
100-
endif
101-
let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::'
102-
let g:neocomplcache_omni_patterns.go = '\h\w*\%.'
103-
let g:neocomplcache_omni_patterns.less = '^\s\+\w\+\|\w\+[):;]\?\s\+\w*\|[@!]'
104-
105-
" neocomplcache activation
106-
inoremap <expr> <c-space> pumvisible() ? "\<C-n>" : "\<C-x>\<C-u>"
107-
inoremap <expr><c-CR> neocomplcache#smart_close_popup() . "\<CR>"
108-
inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"
109-
inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
110-
111190
"---------------
112191
" Surround
113192
"---------------
@@ -142,12 +221,6 @@ map <leader>{ ysiw{
142221
vmap <leader>} c{ <C-R>" }<ESC>
143222
vmap <leader>{ c{<C-R>"}<ESC>
144223
145-
146-
"---------------
147-
" delimitMate
148-
"---------------
149-
let delimitMate_expand_cr = 1
150-
151224
"---------------
152225
" ACK
153226
"---------------

vimrc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ Plug 'lifepillar/vim-solarized8'
2121
Plug 'vim-airline/vim-airline'
2222
Plug 'vim-airline/vim-airline-themes'
2323
Plug 'ctrlpvim/ctrlp.vim'
24+
Plug 'neoclide/coc.nvim', {'branch': 'release'}
25+
26+
Plug 'kana/vim-textobj-user'
27+
Plug 'kana/vim-textobj-indent'
28+
Plug 'kana/vim-textobj-line'
29+
Plug 'kana/vim-textobj-entire'
30+
Plug 'terryma/vim-expand-region'
2431

25-
Plug 'Raimondi/delimitMate'
26-
Plug 'Shougo/neocomplcache'
2732
Plug 'godlygeek/tabular'
2833
Plug 'henrik/vim-indexed-search'
2934
Plug 'honza/vim-snippets'
3035
Plug 'mattn/emmet-vim'
3136
Plug 'mileszs/ack.vim'
32-
Plug 'scrooloose/syntastic'
33-
Plug 'sirver/ultisnips'
3437
Plug 'sjl/gundo.vim'
35-
Plug 'spiiph/vim-space'
3638
Plug 'tpope/vim-commentary'
37-
Plug 'tpope/vim-endwise'
3839
Plug 'tpope/vim-eunuch'
3940
Plug 'tpope/vim-fugitive'
4041
Plug 'tpope/vim-repeat'
@@ -135,9 +136,6 @@ set t_vb=
135136
set mousehide " Hide mouse after chars typed
136137
set mouse=a " Mouse in all modes
137138

138-
" Better complete options to speed it up
139-
set complete=.,w,b,u,U
140-
141139
" ================ Completion =======================
142140

143141
set wildmode=longest,full

0 commit comments

Comments
 (0)