init.vim cut into plugins
[dotfiles/.git] / .config / nvim / init.vim.old
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 'scrooloose/nerdcommenter'
13 "This is a linter for python
14 Plug 'metakirby5/codi.vim'
15 Plug 'christoomey/vim-tmux-navigator'
16 Plug 'morhetz/gruvbox'
17 Plug 'dracula/vim',{'as':'dracula'}
18 Plug 'HerringtonDarkholme/yats.vim' " TS Syntax
19 " Initialize plugin system
20 call plug#end()
21
22
23 "Remaps:
24 "remap the leader to space
25 "let mapleader = " "
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
97
98 "Vim_prettier:
99 "let g:prettier#quickfix_enabled = 0
100 "let g:prettier#quickfix_auto_focus = 0
101 " prettier command for coc
102 command! -nargs=0 Prettier :CocCommand prettier.formatFile
103 " run prettier on save
104 "let g:prettier#autoformat = 0
105 "autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
106
107
108 "NERDTree:
109 let g:NERDTreeGitStatusWithFlags = 1
110 let g:WebDevIconsUnicodeDecorateFolderNodes = 1
111 let g:NERDTreeGitStatusNodeColorization = 1
112 let g:NERDTreeColorMapCustom = {
113     \ "Staged"    : "#0ee375",
114     \ "Modified"  : "#d9bf91",
115     \ "Renamed"   : "#51C9FC",
116     \ "Untracked" : "#FCE77C",
117     \ "Unmerged"  : "#FC51E6",
118     \ "Dirty"     : "#FFBD61",
119     \ "Clean"     : "#87939A",
120     \ "Ignored"   : "#808080"
121     \ }
122 let g:NERDTreeIgnore = ['^node_modules$']
123 " sync open file with NERDTree
124 " " Check if NERDTree is open or active
125 function! IsNERDTreeOpen()
126   return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
127 endfunction
128 " Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
129 " file, and we're not in vimdiff
130 function! SyncTree()
131   if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
132     NERDTreeFind
133     wincmd p
134   endif
135 endfunction
136 " Highlight currently open buffer in NERDTree
137 autocmd BufEnter * call SyncTree()
138
139
140 "Coc:
141 let g:coc_global_extensions = [
142   \ 'coc-snippets',
143   \ 'coc-pairs',
144   \ 'coc-tsserver',
145   \ 'coc-eslint',
146   \ 'coc-prettier',
147   \ 'coc-json',
148   \ 'coc-clangd',
149   \ 'coc-css',
150   \ 'coc-html',
151   \ 'coc-markdownlint',
152   \ 'coc-python',
153   \ ]
154
155 " Use tab for trigger completion with characters ahead and navigate.
156 " Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
157 inoremap <silent><expr> <TAB>
158       \ pumvisible() ? "\<C-n>" :
159       \ <SID>check_back_space() ? "\<TAB>" :
160       \ coc#refresh()
161 inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
162
163 function! s:check_back_space() abort
164   let col = col('.') - 1
165   return !col || getline('.')[col - 1]  =~# '\s'
166 endfunction
167
168 " Use <c-space> to trigger completion.
169 inoremap <silent><expr> <c-space> coc#refresh()
170
171 " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
172 " Coc only does snippet and additional edit on confirm.
173 inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
174 " Or use `complete_info` if your vim support it, like:
175 " inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
176
177 " Use `[g` and `]g` to navigate diagnostics
178 nmap <silent> [g <Plug>(coc-diagnostic-prev)
179 nmap <silent> ]g <Plug>(coc-diagnostic-next)
180
181 " Remap keys for gotos
182 nmap <silent> gd <Plug>(coc-definition)
183 nmap <silent> gy <Plug>(coc-type-definition)
184 nmap <silent> gi <Plug>(coc-implementation)
185 nmap <silent> gr <Plug>(coc-references)
186
187 " Use K to show documentation in preview window
188 nnoremap <silent> K :call <SID>show_documentation()<CR>
189
190 function! s:show_documentation()
191   if (index(['vim','help'], &filetype) >= 0)
192     execute 'h '.expand('<cword>')
193   else
194     call CocAction('doHover')
195   endif
196 endfunction
197
198 " Highlight symbol under cursor on CursorHold
199 autocmd CursorHold * silent call CocActionAsync('highlight')
200
201 " Remap for rename current word
202 nmap <F2> <Plug>(coc-rename)
203
204 " Remap for format selected region
205 xmap <leader>f  <Plug>(coc-format-selected)
206 nmap <leader>f  <Plug>(coc-format-selected)
207
208 augroup mygroup
209   autocmd!
210   " Setup formatexpr specified filetype(s).
211   autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
212   " Update signature help on jump placeholder
213   autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
214 augroup end
215
216 " Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
217 xmap <leader>a  <Plug>(coc-codeaction-selected)
218 nmap <leader>a  <Plug>(coc-codeaction-selected)
219
220 " Remap for do codeAction of current line
221 nmap <leader>ac  <Plug>(coc-codeaction)
222 " Fix autofix problem of current line
223 nmap <leader>qf  <Plug>(coc-fix-current)
224
225 " Create mappings for function text object, requires document symbols feature of languageserver.
226 xmap if <Plug>(coc-funcobj-i)
227 xmap af <Plug>(coc-funcobj-a)
228 omap if <Plug>(coc-funcobj-i)
229 omap af <Plug>(coc-funcobj-a)
230
231 " Use <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python
232 nmap <silent> <C-d> <Plug>(coc-range-select)
233 xmap <silent> <C-d> <Plug>(coc-range-select)
234
235 " Use `:Format` to format current buffer
236 command! -nargs=0 Format :call CocAction('format')
237
238 " Use `:Fold` to fold current buffer
239 command! -nargs=? Fold :call     CocAction('fold', <f-args>)
240
241 " use `:OR` for organize import of current buffer
242 command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')
243
244 " Add status line support, for integration with other plugin, checkout `:h coc-status`
245 set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
246
247 " Using CocList
248 " Show all diagnostics
249 nnoremap <silent> <space>a  :<C-u>CocList diagnostics<cr>
250 " Manage extensions
251 nnoremap <silent> <space>e  :<C-u>CocList extensions<cr>
252 " Show commands
253 nnoremap <silent> <space>c  :<C-u>CocList commands<cr>
254 " Find symbol of current document
255 nnoremap <silent> <space>o  :<C-u>CocList outline<cr>
256 " Search workspace symbols
257 nnoremap <silent> <space>s  :<C-u>CocList -I symbols<cr>
258 " Do default action for next item.
259 nnoremap <silent> <space>j  :<C-u>CocNext<CR>
260 " Do default action for previous item.
261 nnoremap <silent> <space>k  :<C-u>CocPrev<CR>
262 " Resume latest coc list
263 nnoremap <silent> <space>p  :<C-u>CocListResume<CR>
264
265
266
267
268 "My_autocmds:
269 fun! TrimWhitespace()
270     let l:save = winsaveview()
271     keeppatterns %s/\s\+$//e
272     call winrestview(l:save)
273 endfun
274
275 augroup JOSUERODRIGUEZ
276     autocmd!
277     autocmd BufWritePre * :call TrimWhitespace()
278 augroup END