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