-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot_vimrc
429 lines (336 loc) · 10.5 KB
/
dot_vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
if &compatible
set nocompatible
endif
"*****************************************************************************
"" Plugins
"*****************************************************************************
call plug#begin('~/.vim/plugged')
"" Themes
Plug 'KeitaNakamura/neodark.vim'
Plug 'altercation/vim-colors-solarized'
Plug 'arcticicestudio/nord-vim'
Plug 'cocopon/iceberg.vim'
Plug 'drewtempelmeyer/palenight.vim'
Plug 'liuchengxu/space-vim-dark'
Plug 'nanotech/jellybeans.vim'
Plug 'rakr/vim-one'
Plug 'tyrannicaltoucan/vim-deep-space'
"" Visual tab {bottom}
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
"" Tree
Plug 'scrooloose/nerdtree'
"" Fuzzy Finder
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
"" Grep
Plug 'mhinz/vim-grepper'
"" Smart comments
Plug 'tpope/vim-commentary'
"" Git
Plug 'tpope/vim-fugitive'
"" Shows a git diff in the gutter (sign column) and stages/undoes hunks.
Plug 'airblade/vim-gitgutter'
"" A collection of language packs for Vim.
Plug 'sheerun/vim-polyglot'
"" Ruby
Plug 'tpope/vim-rails'
Plug 'thoughtbot/vim-rspec'
"" HTML
Plug 'vim-scripts/HTML-AutoCloseTag'
Plug 'mattn/emmet-vim'
"" CSS
Plug 'hail2u/vim-css3-syntax'
Plug 'griffinqiu/vim-coloresque'
Plug 'styled-components/vim-styled-components', { 'branch': 'main' }
"" Go
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
"" Markdown
Plug 'junegunn/goyo.vim', { 'for': 'markdown' }
"" Intellisense engine
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
"" A set of mappings for HTML, XML, PHP, ASP, eRuby, JSP, and more
Plug 'tpope/vim-surround'
Plug 'tpope/vim-ragtag'
Plug 'tpope/vim-unimpaired'
"" Simplifies the transition between multiline and single-line code (gS, gJ)
Plug 'AndrewRadev/splitjoin.vim'
"" Type vv inside pairs objects such as () to select content
Plug 'gorkunov/smartpairs.vim'
"" This plugin causes all trailing whitespace to be highlighted in red.
Plug 'bronson/vim-trailing-whitespace'
"" Insert or delete brackets, parens, quotes in pair.
Plug 'jiangmiao/auto-pairs'
"" Enable repeating supported plugin maps with '.'
Plug 'tpope/vim-repeat'
"" EditorConfig plugin for Vim
Plug 'editorconfig/editorconfig-vim'
"" Asks to create directories in Vim when needed
Plug 'jordwalke/VimAutoMakeDirectory'
"" Start a * or # search from a visual block
Plug 'nelstrom/vim-visual-star-search'
"" Table mode
Plug 'dhruvasagar/vim-table-mode'
"" WakaTime for productivity metrics, goals, leaderboards, and automatic time tracking
Plug 'wakatime/vim-wakatime'
call plug#end()
"*****************************************************************************
"" Basic Setup
"*****************************************************************************
filetype plugin indent on
"" Encoding
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8
"" Tabs. May be overriten by autocmd rules
set tabstop=4
set shiftwidth=4
set softtabstop=4
set smarttab
set expandtab
"" Map leader to space
let mapleader = ' '
"" Enable hidden buffers
set hidden
"" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
"" Completion Options
set completeopt+=preview
set shortmess+=c
"" Command-line completion operates in an enhanced
set wildmenu
set wildmode=full
"" Folding
set foldmethod=indent
set nofoldenable
"" Directories for swp files
set nobackup
set noswapfile
set fileformats=unix,dos,mac
set showcmd
set shell=/bin/sh
set autoread
set autowrite
"" Session management
let g:session_directory = '~/.vim/session'
let g:session_autoload = 'no'
let g:session_autosave = 'no'
let g:session_command_aliases = 1
"" Persistent undo
if has('persistent_undo')
set undofile
" Run mkdir ~/.vim/undo if undo folder is not exists
set undodir=~/.vim/undo
endif
"*****************************************************************************
"" Visual Settings
"*****************************************************************************
syntax enable
set ruler
set number
let no_buffers_menu = 1
colorscheme nord
set background=dark
set mouse=a
set mousemodel=popup
if has('mouse_sgr')
set ttymouse=sgr
endif
set term=$TERM
"" True Color
if (has('termguicolors'))
let &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"
let &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"
set termguicolors
endif
"" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
"" Always show signcolumns
set signcolumn=yes
"" Status bar
set laststatus=2
"" Use modeline overrides
set modeline
set modelines=10
set title
set titleold=
set titlestring=%F
set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)\
if exists('*fugitive#statusline')
set statusline+=%{fugitive#statusline()}
endif
"*****************************************************************************
"" Functions
"*****************************************************************************
if !exists('*s:setupWrapping')
function s:setupWrapping()
set wrap
set wm=2
set textwidth=79
endfunction
endif
function! s:setupCommandAlias(input, output)
exec 'cabbrev <expr> '.a:input
\ .' ((getcmdtype() is# ":" && getcmdline() is# "'.a:input.'")'
\ .'? ("'.a:output.'") : ("'.a:input.'"))'
endfunction
function! s:showDocumentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
"*****************************************************************************
"" Autocmd Rules
"*****************************************************************************
"" The PC is fast enough, do syntax highlight syncing from start
augroup vimrc-sync-fromstart
autocmd!
autocmd BufEnter * :syntax sync fromstart
augroup END
"" Remember cursor position
augroup vimrc-remember-cursor-position
autocmd!
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
augroup END
"" txt
augroup vimrc-wrapping
autocmd!
autocmd BufRead,BufNewFile *.txt call s:setupWrapping()
augroup END
"" make/cmake
augroup vimrc-make-cmake
autocmd!
autocmd FileType make setlocal noexpandtab
autocmd BufNewFile,BufRead CMakeLists.txt setlocal filetype=cmake
augroup END
"*****************************************************************************
"" Plugins Configuration
"*****************************************************************************
"" NERDTree configuration
let g:NERDTreeChDirMode = 2
let g:NERDTreeIgnore = ['\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$', '__pycache__']
let g:NERDTreeSortOrder = ['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
let g:NERDTreeShowBookmarks = 1
let g:NERDTreeMapOpenInTabSilent = '<RightMouse>'
let g:NERDTreeWinSize = 30
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite
"" Airline
let g:airline_powerline_fonts = 1
let g:airline_theme = 'nord'
let g:airline#extensions#tabline#enabled = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.dirty = '!'
"" Grepper
let g:grepper = {
\ 'tools': ['rg', 'ag', 'git', 'grep']
\}
"" Table mode
" Markdown-compatible tables
let g:table_mode_corner = '|'
"" Coc
let g:coc_global_extensions = [
\ 'coc-clangd',
\ 'coc-css',
\ 'coc-eslint',
\ 'coc-flutter',
\ 'coc-fsharp',
\ 'coc-go',
\ 'coc-html',
\ 'coc-java',
\ 'coc-json',
\ 'coc-prettier',
\ 'coc-python',
\ 'coc-rls',
\ 'coc-svelte',
\ 'coc-tsserver',
\ '@yaegassy/coc-tailwindcss3',
\]
command! -nargs=0 Format :call CocAction('format')
"" vim-go
" Disable all linters as that is taken care of by coc.nvim
let g:go_diagnostics_enabled = 0
let g:go_metalinter_enabled = []
" Don't jump to errors after metalinter is invoked
let g:go_jump_to_error = 0
" Run go imports on file save
let g:go_fmt_command = "goimports"
" Automatically highlight variable your cursor is on
let g:go_auto_sameids = 0
" Disable vim-go mapping `gd` for go to definition
let g:go_def_mapping_enabled = 0
" Disable vim-go mapping `K` for showing documentation
let g:go_doc_keywordprg_enabled = 0
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
augroup go
autocmd!
" Show by default 4 spaces for a tab
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
" :GoBuild and :GoTestCompile
autocmd FileType go nmap <Leader>b :<C-u>call <SID>buildGoFiles()<CR>
augroup END
" buildGoFiles is a custom function that builds or compiles the test file.
" It calls :GoBuild if its a Go file, or :GoTestCompile if it's a test file
function! s:buildGoFiles()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
"*****************************************************************************
"" Command Aliases
"*****************************************************************************
call s:setupCommandAlias('grep', 'GrepperRg')
call s:setupCommandAlias('search', 'CocSearch')
"*****************************************************************************
"" Key Maps
"*****************************************************************************
nnoremap <C-p> :Files<CR>
nnoremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l>
" Search for the current word
nnoremap <Leader>* :Grepper -cword -noprompt<CR>
" Search for the current selection
nmap gs <plug>(GrepperOperator)
xmap gs <plug>(GrepperOperator)
" Format
xmap <Leader>f <Plug>(coc-format-selected)
nmap <Leader>f <Plug>(coc-format-selected)
nnoremap <Leader>F :Format<CR>
" Code actions
xmap <Leader>a <Plug>(coc-codeaction-selected)
nmap <Leader>a <Plug>(coc-codeaction-selected)
nmap <Leader>A <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line
nmap <Leader>qf <Plug>(coc-fix-current)
" Remap for rename current word
nmap <Leader>rn <Plug>(coc-rename)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>showDocumentation()<CR>
" Mappings using CocList
nnoremap <silent> <Leader>cd :<C-u>CocList diagnostics<CR>
nnoremap <silent> <Leader>ce :<C-u>CocList extensions<CR>
nnoremap <silent> <Leader>cc :<C-u>CocList commands<CR>
nnoremap <silent> <Leader>co :<C-u>CocList outline<CR>
nnoremap <silent> <Leader>cs :<C-u>CocList -I symbols<CR>
" Close the quickfix window with <Leader>a
nnoremap <Leader>Q :cclose<CR>