4f0ea0aaeb84798914ad5765de8c016a24a34f4f
[dotfiles/.git] / .config / nvim / init.vim
1
2 " Specify a directory for plugins
3 call plug#begin('~/.vim/plugged')
4
5 Plug 'neoclide/coc.nvim', {'branch': 'release'}
6 Plug 'scrooloose/nerdtree'
7 "Plug 'tsony-tsonev/nerdtree-git-plugin'
8 Plug 'Xuyuanp/nerdtree-git-plugin'
9 Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
10 Plug 'ryanoasis/vim-devicons'
11 Plug 'airblade/vim-gitgutter'
12 Plug 'ctrlpvim/ctrlp.vim' " fuzzy find files
13 Plug 'scrooloose/nerdcommenter'
14 "Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
15
16 "This is a linter for python
17 Plug 'ChristianChiarulli/codi.vim'
18
19
20 Plug 'christoomey/vim-tmux-navigator'
21
22 Plug 'morhetz/gruvbox'
23 Plug 'dracula/vim',{'as':'dracula'}
24 Plug 'HerringtonDarkholme/yats.vim' " TS Syntax
25
26 " Initialize plugin system
27 call plug#end()
28
29 inoremap jk <ESC>
30 nmap <C-n> :NERDTreeToggle<CR>
31 nmap <C-s> :w<CR>
32 vmap ++ <plug>NERDCommenterToggle
33 nmap ++ <plug>NERDCommenterToggle
34 set timeout timeoutlen=2000
35
36 set termguicolors
37 set number
38 set ignorecase
39 set smartcase
40 set relativenumber
41 "colorscheme dracula
42 colorscheme gruvbox
43
44
45
46
47 " Change the color
48 highlight CodiVirtualText guifg=cyan
49
50 let g:codi#virtual_text_prefix = "❯ "
51
52
53 "
54 let g:codi#aliases = {
55                    \ 'javascript.jsx': 'javascript',
56                    \ }
57
58
59
60 " open NERDTree automatically
61 "autocmd StdinReadPre * let s:std_in=1
62 "autocmd VimEnter * NERDTree
63
64 let g:NERDTreeGitStatusWithFlags = 1
65 "let g:WebDevIconsUnicodeDecorateFolderNodes = 1
66 "let g:NERDTreeGitStatusNodeColorization = 1
67 "let g:NERDTreeColorMapCustom = {
68     "\ "Staged"    : "#0ee375",  
69     "\ "Modified"  : "#d9bf91",  
70     "\ "Renamed"   : "#51C9FC",  
71     "\ "Untracked" : "#FCE77C",  
72     "\ "Unmerged"  : "#FC51E6",  
73     "\ "Dirty"     : "#FFBD61",  
74     "\ "Clean"     : "#87939A",   
75     "\ "Ignored"   : "#808080"   
76     "\ }                         
77
78
79 let g:NERDTreeIgnore = ['^node_modules$']
80
81 " vim-prettier
82 "let g:prettier#quickfix_enabled = 0
83 "let g:prettier#quickfix_auto_focus = 0
84 " prettier command for coc
85 command! -nargs=0 Prettier :CocCommand prettier.formatFile
86 " run prettier on save
87 "let g:prettier#autoformat = 0
88 "autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
89
90
91 " ctrlp
92 let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
93
94 " j/k will move virtual lines (lines that wrap)
95 noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
96 noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
97
98
99 set smarttab
100 set cindent
101 set tabstop=2
102 set shiftwidth=2
103 " always uses spaces instead of tab characters
104 set expandtab
105
106
107
108 " sync open file with NERDTree
109 " " Check if NERDTree is open or active
110 function! IsNERDTreeOpen()        
111   return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
112 endfunction
113
114 " Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
115 " file, and we're not in vimdiff
116 function! SyncTree()
117   if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
118     NERDTreeFind
119     wincmd p
120   endif
121 endfunction
122
123 " Highlight currently open buffer in NERDTree
124 autocmd BufEnter * call SyncTree()
125
126 " coc config
127 let g:coc_global_extensions = [
128   \ 'coc-snippets',
129   \ 'coc-pairs',
130   \ 'coc-tsserver',
131   \ 'coc-eslint', 
132   \ 'coc-prettier', 
133   \ 'coc-json', 
134   \ 'coc-clangd', 
135   \ 'coc-css', 
136   \ 'coc-html', 
137   \ 'coc-markdownlint', 
138   \ 'coc-python', 
139   \ ]
140 " from readme
141 " if hidden is not set, TextEdit might fail.
142 set hidden " Some servers have issues with backup files, see #649 set nobackup set nowritebackup " Better display for messages set cmdheight=2 " You will have bad experience for diagnostic messages when it's default 4000.
143 set updatetime=300
144
145 " don't give |ins-completion-menu| messages.
146 set shortmess+=c
147
148 " always show signcolumns
149 set signcolumn=yes
150
151 " Use tab for trigger completion with characters ahead and navigate.
152 " Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
153 inoremap <silent><expr> <TAB>
154       \ pumvisible() ? "\<C-n>" :
155       \ <SID>check_back_space() ? "\<TAB>" :
156       \ coc#refresh()
157 inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
158
159 function! s:check_back_space() abort
160   let col = col('.') - 1
161   return !col || getline('.')[col - 1]  =~# '\s'
162 endfunction
163
164 " Use <c-space> to trigger completion.
165 inoremap <silent><expr> <c-space> coc#refresh()
166
167 " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
168 " Coc only does snippet and additional edit on confirm.
169 inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
170 " Or use `complete_info` if your vim support it, like:
171 " inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
172
173 " Use `[g` and `]g` to navigate diagnostics
174 nmap <silent> [g <Plug>(coc-diagnostic-prev)
175 nmap <silent> ]g <Plug>(coc-diagnostic-next)
176
177 " Remap keys for gotos
178 nmap <silent> gd <Plug>(coc-definition)
179 nmap <silent> gy <Plug>(coc-type-definition)
180 nmap <silent> gi <Plug>(coc-implementation)
181 nmap <silent> gr <Plug>(coc-references)
182
183 " Use K to show documentation in preview window
184 nnoremap <silent> K :call <SID>show_documentation()<CR>
185
186 function! s:show_documentation()
187   if (index(['vim','help'], &filetype) >= 0)
188     execute 'h '.expand('<cword>')
189   else
190     call CocAction('doHover')
191   endif
192 endfunction
193
194 " Highlight symbol under cursor on CursorHold
195 autocmd CursorHold * silent call CocActionAsync('highlight')
196
197 " Remap for rename current word
198 nmap <F2> <Plug>(coc-rename)
199
200 " Remap for format selected region
201 xmap <leader>f  <Plug>(coc-format-selected)
202 nmap <leader>f  <Plug>(coc-format-selected)
203
204 augroup mygroup
205   autocmd!
206   " Setup formatexpr specified filetype(s).
207   autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
208   " Update signature help on jump placeholder
209   autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
210 augroup end
211
212 " Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
213 xmap <leader>a  <Plug>(coc-codeaction-selected)
214 nmap <leader>a  <Plug>(coc-codeaction-selected)
215
216 " Remap for do codeAction of current line
217 nmap <leader>ac  <Plug>(coc-codeaction)
218 " Fix autofix problem of current line
219 nmap <leader>qf  <Plug>(coc-fix-current)
220
221 " Create mappings for function text object, requires document symbols feature of languageserver.
222 xmap if <Plug>(coc-funcobj-i)
223 xmap af <Plug>(coc-funcobj-a)
224 omap if <Plug>(coc-funcobj-i)
225 omap af <Plug>(coc-funcobj-a)
226
227 " Use <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python
228 nmap <silent> <C-d> <Plug>(coc-range-select)
229 xmap <silent> <C-d> <Plug>(coc-range-select)
230
231 " Use `:Format` to format current buffer
232 command! -nargs=0 Format :call CocAction('format')
233
234 " Use `:Fold` to fold current buffer
235 command! -nargs=? Fold :call     CocAction('fold', <f-args>)
236
237 " use `:OR` for organize import of current buffer
238 command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')
239
240 " Add status line support, for integration with other plugin, checkout `:h coc-status`
241 set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
242
243 " Using CocList
244 " Show all diagnostics
245 nnoremap <silent> <space>a  :<C-u>CocList diagnostics<cr>
246 " Manage extensions
247 nnoremap <silent> <space>e  :<C-u>CocList extensions<cr>
248 " Show commands
249 nnoremap <silent> <space>c  :<C-u>CocList commands<cr>
250 " Find symbol of current document
251 nnoremap <silent> <space>o  :<C-u>CocList outline<cr>
252 " Search workspace symbols
253 nnoremap <silent> <space>s  :<C-u>CocList -I symbols<cr>
254 " Do default action for next item.
255 nnoremap <silent> <space>j  :<C-u>CocNext<CR>
256 " Do default action for previous item.
257 nnoremap <silent> <space>k  :<C-u>CocPrev<CR>
258 " Resume latest coc list
259 nnoremap <silent> <space>p  :<C-u>CocListResume<CR>