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