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