-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc.full
504 lines (375 loc) · 13.2 KB
/
vimrc.full
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" ██╗ ██╗██╗███╗ ███╗██████╗ ██████╗
" ██║ ██║██║████╗ ████║██╔══██╗██╔════╝
" ██║ ██║██║██╔████╔██║██████╔╝██║
" ╚██╗ ██╔╝██║██║╚██╔╝██║██╔══██╗██║
" ╚████╔╝ ██║██║ ╚═╝ ██║██║ ██║╚██████╗
" ╚═══╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"PLUGINS ----------------------------------------------------------------- {{{
call plug#begin('~/.vim/plugged')
Plug 'sonph/onehalf', {'rtp': 'vim/'}
Plug 'preservim/nerdtree'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'jlanzarotta/bufexplorer'
Plug 'yegappan/mru'
Plug 'dense-analysis/ale'
Plug 'preservim/nerdcommenter'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'junegunn/gv.vim'
Plug 'jiangmiao/auto-pairs'
Plug 'mbbill/undotree'
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'maxmellon/vim-jsx-pretty'
" Plug 'mcchrish/nnn.vim' // TODO
" Initialize plugin system.
call plug#end()
" }}}
" Do not make vim compatible with vi.
set nocompatible
" Allow plugins to be used.
filetype plugin indent on
" Use syntax highlighting.
syntax on
" Always leave 10 rows below cursor.
set scrolloff=5
" Display a column with relative number column.
" set relativenumber
" Add numbers to the lines.
" set number
" Show cursor line.
set cursorline
" Not Show cursor column.
set nocursorcolumn
" Set title of window to the name of the file.
set title
" Backup files.
set backup
" Backup directory.
set backupdir=~/.vim/backup/
" Hide mouse when typing.
set mousehide
" Check to see if an external file has changed.
set autoread
" Split window with cursor in bottom window.
set splitbelow splitright
" Leave windows uneven after split or close.
set noequalalways
" Switch buffers without saving.
set hidden
" Show error bell visually.
set visualbell
" Set the text width.
set textwidth=80
" Allow backspacing to work as expected.
set backspace=indent,eol,start
" Tabbing over moves four spaces.
set tabstop=2
" Number of spaces to use in automatically indent.
set shiftwidth=2
" Copy indent from current line when starting a new line.
set autoindent
" Use C style indentation
set cindent
" Use space characters instead of tabs.
set expandtab
" Incremental search an you type.
set incsearch
" Ignore capital letters during search.
set ignorecase
" Override the ignorecase option if searching for captial letters.
set smartcase
" Show the line and column position of cursor.
set ruler
" Show partial command in the last line of the screen.
set showcmd
" Show the mode in the last line.
set showmode
" Show matching words.
set showmatch
" Tenths of a second to show matching brackets.
set matchtime=1
" Use highlighting when doing a search.
set hlsearch
" Change the command history (default=20).
set history=100
" If using a fast terminal.
set ttyfast
" Set the character enconding when writing file.
set fileencoding=utf8
" Set the character encoding.
set encoding=utf8
" Show auto complete menus.
set wildmenu
" Make wildmenu behave like bash completion.
set wildmode=longest:full,full
" Ignore files with these extentions.
set wildignore=*.odt,*.doc*,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.JPG,*.exe,*.bmp,*.flv,*.gz,*.tgz,*.zip,*.iso,*.gzip,*.mov,*.xz,*.tar,*.img,*.docx,*.xlsx,*.xls
" Temporary files.
set directory=/tmp
" Show popup documentation
set completeopt=menu,menuone,popup,noselect,noinsert
" MAPPINGS --------------------------------------------------------------- {{{
" Set the leader to '-' instead of the default '\'.
let mapleader = " "
" Enable syntax highlighting in markdown code blocks.
let g:markdown_fenced_languages = ['html', 'python', 'css', 'vim', 'rust', 'c']
" Press <leader>- to go back to the last cursor position.
nnoremap <leader>- ``
" Yank from cursor to the end of line.
nnoremap Y y$
" Select all text in buffer.
noremap <leader>a ggVG
" Paste a block of code without formatting it.
nnoremap <mousemiddle> <esc>"*P
" Easy navigate the split view.
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
if has("gui_running")
nnoremap <silent> <Esc> :nohlsearch<Bar>:echo<CR>
else
map <silent> <leader><cr> :noh<cr>
endif
noremap <F12> <Esc>:syntax sync fromstart<CR>
inoremap <F12> <C-o>:syntax sync fromstart<CR>
nnoremap <silent> <leader>w :update<CR>
nnoremap <silent> <leader>q :x<CR>
nnoremap <up> :echoerr "Don't use arrow keys, use H, J, K, L instead!"<CR>
nnoremap <down> :echoerr "Don't use arrow keys, use H, J, K, L instead!"<CR>
nnoremap <right> :echoerr "Don't use arrow keys, use H, J, K, L instead!"<CR>
nnoremap <left> :echoerr "Don't use arrow keys, use H, J, K, L instead!"<CR>
" Close the current buffer
map <leader>xx :bd<cr>
" Close all the buffers
map <leader>xa :bufdo bd<cr>
map <leader>l :bnext<cr>
map <leader>h :bprevious<cr>
" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
" Close a buffer and switching to another buffer, do not close the
" window, see https://goo.gl/Wd8yZJ
nnoremap <silent> \d :bprevious <bar> bdelete #<CR>
" Map Ctrl-<Space> to / (search)
map <leader>s /
" Highlight words but do not jump
nnoremap * :keepjumps normal! mi*`i<CR>
" Use Tab to select ALE suggestions
inoremap <silent><expr> <Tab> pumvisible() ? "\<C-n>" : "\<TAB>"
inoremap <silent><expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-TAB>"
" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
" }}}
"PLUGINS CONFIGURATION ------------------------------------------------------- {{{
" Nerdcommenter
let g:NERDSpaceDelims = 1
" MRU
let MRU_Max_Entries = 20
map <leader>f :MRU<CR>
" NerdTree
let NERDTreeIgnore=['\.jpg$', '\.mp4$', '\.zip$', '\.iso$', '\.pdf$', '\.pyc$', '\.odt$', '\.png$', '\.svg$', '\.gif$', '\.tar$', '\.gz$', '\.xz$', '\.bz2$', '\.db$', '\.vim$', '\~$', '\.pyc$', 'node_modules']
nnoremap <leader>0 :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-m> :NERDTreeFind<CR>
let NERDTreeShowBookmarks=1
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
" BufExplorer
map <leader><tab> :b#<CR> " switch to latest buffer
nnoremap <silent> <leader>e :BufExplorer<CR>
" FZF
let g:fzf_layout = { 'down': '40%' }
nnoremap <silent> <C-p> :GFiles<CR>
nnoremap <silent> <C-g> :Rg<CR>
" ALE
let g:ale_completion_enabled = 1
let g:ale_completion_autoimport = 1
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'javascript': ['eslint', 'prettier'],
\ 'typescript': ['prettier'],
\ 'typescriptreact': ['prettier'],
\ 'scss': ['prettier'],
\ 'css': ['prettier']
\}
let g:ale_fix_on_save = 1
nmap <silent> ge :ALEDetail<CR>
nmap <silent> gr :ALEFindReferences<CR>
nmap <silent> gd :ALEGoToDefinition<CR>
nmap <silent> gy :ALEGoToTypeDefinition -vsplit<CR>
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
augroup VimDiff
autocmd!
autocmd VimEnter,BufEnter,FilterWritePre * if &diff | ALEDisable | endif
augroup END
" Fugitive
nnoremap <leader>gs :Git<CR>
nnoremap <leader>gc :Gcommit<CR>
nnoremap <leader>gP :Git push<CR>
nnoremap <leader>gl :GV!<CR>
nnoremap <leader>gL :GV<CR>
nnoremap <leader>gd :Gvdiff<CR>
nnoremap <leader>gb :Git blame<CR>
nnoremap <leader>gm :Git checkout master<CR>
" Gitgutter
nmap <Leader>gn <Plug>(GitGutterNextHunk) " git next
nmap <Leader>gp <Plug>(GitGutterPrevHunk) " git previous
nmap <Leader>ga <Plug>(GitGutterStageHunk) " git add (chunk)
nmap <Leader>gu <Plug>(GitGutterUndoHunk) " git undo (chunk)
set signcolumn=yes
let g:gitgutter_override_sign_column_highlight = 2
highlight SignColumn guibg=bg
highlight link GitGutterChangeLine DiffText
let g:gitgutter_sign_added = '++'
let g:gitgutter_sign_modified = '>>'
let g:gitgutter_sign_removed = '--'
let g:gitgutter_sign_removed_first_line = '^^'
let g:gitgutter_sign_modified_removed = '<<'
" Undotree
nnoremap <leader>u :UndotreeToggle<CR>
" Typescript
let g:typescript_indent_disable = 1
let g:typescript_opfirst='\%([<>=,?^%|*/&]\|\([-:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)'
let g:vim_jsx_pretty_colorful_config = 1
" TSX plugin
let g:vim_jsx_pretty_template_tags = ['html', 'jsx', 'tsx']
let g:vim_jsx_pretty_highlight_close_tag = 1
" VIMSCRIPT FILE SETTINGS ------------------------------------------------ {{{
" Use the marker method of folding.
"augroup filetype_vim
" autocmd!
" autocmd FileType vim setlocal foldmethod=marker
"augroup END
" Auto set current file directory
autocmd BufEnter * if expand("%:p:h") !~ '^/tmp' | silent! lcd %:p:h | endif
" Turn on cursorline and cursorcolumn only in active window.
augroup cursor_off
autocmd!
autocmd WinLeave * set nocursorline
autocmd WinEnter * set cursorline
augroup END
" Set indentation of HTML to 2 spaces.
autocmd Filetype html setlocal tabstop=2 shiftwidth=2 expandtab
" If vim version is equal to or greater than 7.3 enable undofile.
if version >= 703
set undodir=~/.vim/backup
set undofile
set undoreload=10000
endif
" Show ALE errors
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? ' OK ' : printf(
\ ' %dW | %dE ',
\ all_non_errors,
\ all_errors
\)
endfunction
augroup resume_edit_position
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | execute "normal! g`\"zvzz"
\ | endif
augroup END
function! InsertConsoleLog()
let word = expand("<cword>")
let linenumber = line(".")
execute "normal A \<BS>\<CR>\<ESC>0Aconsole.log('[" . expand('%:t'). ":" .linenumber. "]', ".word."); \/* TODO *\/"
endfunction
map <silent> <leader>v :call InsertConsoleLog()<CR>bbbbi
function! Gitbranch() abort
if exists('*FugitiveHead')
let [a,m,r] = GitGutterGetHunkSummary()
let branch = FugitiveHead()
return branch !=# '' ? ' '. branch . ' ' : ''
endif
return FugitiveHead()
endfunction
" Set terminal color
set t_Co=256
if has("gui_running")
" Set the background tone.
set background=dark
" Set the color scheme.
colorscheme onehalfdark
" Set font to DejaVu Sans Mono 10
set guifont=Hack\ Nerd\ Font:h12
" Hide the toolbar.
set guioptions-=T
" Hide the the left-side scroll bar.
set guioptions-=L
" Hide the the left-side scroll bar.
set guioptions-=r
" Hide the the menu bar.
set guioptions-=m
" Hide the the bottom scroll bar.
set guioptions-=b
" Map the F4 key to toggle the menu, tool, and scroll bar.
nnoremap <F4> :if &guioptions=~#'mTr'<Bar>
\set guioptions-=mTr<Bar>
\else<Bar>
\set guioptions+=mTr<Bar>
\endif<CR>
endif
" }}}
"STATUS LINE ------------------------------------------------------------ {{{
" Set colors for the status line.
hi User0 ctermbg=darkgray ctermfg=lightgray guibg=#4F5666 guifg=lightgray gui=italic
hi User1 ctermbg=darkblue ctermfg=lightblue guibg=#4F5666 guifg=lightgray gui=italic
" Clear status line when vimrc is reloaded.
set statusline=
" White on blue.
set statusline+=%0*
" Git.
set statusline+=%{Gitbranch()}
" White on blue.
set statusline+=%1*
" Full path to the file.
set statusline+=\ %t
" Modified flag.
set statusline+=\ %M
" Read only.
set statusline+=\ %R
set statusline+=%*
" Blue on white.
set statusline+=%1*
" Split the left from the right.
set statusline+=%=
" File type.
set statusline+=\ %y
" Blue on white.
set statusline+=\ %0*
" Show the row the cursor is on.
set statusline+=\ %l
" Show the lenth of the line.
set statusline+=\ %p%%
" White on blue.
set statusline+=\ %0*
" Color.
set statusline+=%#warningmsg#
" ALE status line flag.
set statusline+=%{LinterStatus()}
" Show the status on the second to last line.
set laststatus=2
" }}}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""