-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvimrc
480 lines (360 loc) · 10.2 KB
/
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
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
"{{{ Vi-nocompatible
set nocompatible
"}}}
"{{{ Leader key
let mapleader = " "
"}}}
"{{{ Terminal profile (Light|Dark)
let iterm_profile = $ITERM_PROFILE
"}}}
"{{{ Plugins
"{{ Load plugin manager
if !filereadable(expand('~/.vim/autoload/plug.vim'))
let s:first_init=1
endif
if exists("s:first_init")
echom 'Plugin manager: vim-plug not been installed. Attempting installation...'
exec 'silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs '.
\ 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
echom 'Installed successfully!'
endif
call plug#begin('~/.vim/plugged')
"}}
"{{ Intellisense and autocomplete
Plug 'rescript-lang/vim-rescript'
autocmd BufWritePost .res :RescriptFormat<CR>
Plug 'neoclide/coc.nvim', {'branch': 'release'}
let g:coc_global_extensions = ['coc-json', 'coc-pyright', 'coc-tsserver', 'coc-eslint', 'coc-prettier', 'coc-rls', 'coc-flutter']
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
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)
nmap <silent> gs <Plug>(coc-rename)
"}}
"{{ Colorschemes and views
" Load colorscheme
Plug 'morhetz/gruvbox'
" Use the default gruvbox contrast level
let g:gruvbox_contrast_dark='default'
Plug 'junegunn/goyo.vim'
let g:goyo_linenr = 1
nnoremap <silent> <leader>g :Goyo<CR>
function! s:goyo_enter()
if executable('tmux') && strlen($TMUX)
silent !tmux set status off
silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
endif
set noshowmode
set noshowcmd
set scrolloff=999
endfunction
function! s:goyo_leave()
if executable('tmux') && strlen($TMUX)
silent !tmux set status on
silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
endif
set showmode
set showcmd
set scrolloff=12
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
" tsconfig set correct format
Plug 'neoclide/jsonc.vim'
autocmd BufRead,BufNewFile tsconfig.json set filetype=jsonc
"}}
"{{ Version control - Git
" Git integration on normal mode
Plug 'tpope/vim-fugitive'
nmap <silent> gf :diffget //3<CR>
nmap <silent> gj :diffget //2<CR>
" Open GitHub repo using :Gbrowse
Plug 'tpope/vim-rhubarb'
" Gutter showing git changes
Plug 'airblade/vim-gitgutter'
"Cheat sheet
"Plug 'https://gitlab.com/dbeniamine/cheat.sh-vim'
"let g:CheatSheetDoNotMap=1
" Add mappings from cheat.sh-vim/plugin/cheat.vim with the '!' parameter replaced by ''
"nnoremap <script> <silent> <leader>KB
" \ :call cheat#cheat("", getcurpos()[1], getcurpos()[1], 0, 0, '')<CR>
"vnoremap <script> <silent> <leader>KB
" \ :call cheat#cheat("", -1, -1, 2, 0, '')<CR>
" Nerd tree showing git changes
Plug 'Xuyuanp/nerdtree-git-plugin'
"let g:NERDTreeUpdateOnCursorHold = 0
let g:NERDTreeWinSize = 40
"}}
"{{ Language syntax helpers
" GraphQL
Plug 'jparise/vim-graphql'
" Comments
Plug 'tpope/vim-commentary'
" JavaScript
Plug 'pangloss/vim-javascript'
" Dart
Plug 'dart-lang/dart-vim-plugin'
" JSX with some overrides
Plug 'maxmellon/vim-jsx-pretty'
" C++
Plug 'octol/vim-cpp-enhanced-highlight'
let g:cpp_class_scope_highlight = 1
let g:cpp_member_variable_highlight = 1
let g:cpp_class_decl_highlight = 1
let g:cpp_experimental_template_highlight = 1
let g:cpp_concepts_highlight = 1
Plug 'rhysd/vim-clang-format'
"let g:clang_format#auto_format = 1
autocmd FileType c,cpp,objc ClangFormatAutoEnable
" GLSL
Plug 'tikhomirov/vim-glsl'
" Close braces and brackets
Plug 'jiangmiao/auto-pairs'
au FileType rust let b:AutoPairs = AutoPairsDefine({ "'" : '' })
" Close XML tags
Plug 'alvan/vim-closetag'
let g:closetag_filenames = '*.html,*.xhtml,*.xml,*.vue,*.js,*.jsx,*.tsx,*.ts'
"}}
"{{ Navigation
" Project file tree
Plug 'preservim/nerdtree'
let g:NERDTreeMinimalUI = 1
let g:NERDTreeShowHidden = 1
let g:NERDTreeIgnore = [ '__pycache__', '\.pyc$', '\.o$', '\.swp', '*\.swp', 'node_modules', '.dart_tool', '.idea' ]
" Autostart NERDTree on starting Vim
autocmd vimenter * NERDTree
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:stdn_in") | NERDTree | endif
" Toggle NERDTree
map <silent> <C-n> :NERDTreeToggle<CR>
map <silent> <leader>r :NERDTreeFind<cr>
" Folder name color same as folder icon
highlight! link NERDTreeFlags NERDTreeDir
" TMUX-Vim integration
Plug 'christoomey/vim-tmux-navigator'
" Maximize active pane
Plug 'zhaocai/GoldenView.Vim'
let g:goldenview__enable_default_mapping = 0
" Fuzzy finder
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
let g:fzf_command_prefix = 'Fzf'
let g:fzf_history_dir = '~/.fzf/history'
nnoremap <silent> <leader>c :FzfCommits<CR>
nnoremap <silent> <leader>f :FzfAg<CR>
nnoremap <silent> <leader>F :FzfFiles<CR>
command! -bang -nargs=? -complete=dir FzfFiles
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
command! -bang -nargs=* FzfAg
\ call fzf#vim#ag(<q-args>,
\ '--ignore "node_modules" --ignore "yarn.lock" --ignore "package-lock.json"',
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
function! s:set_fzf_maps()
tnoremap <buffer> <C-t> <C-\><C-n>:close<CR>:sleep 100m<CR>:FzfFiles<CR>
tnoremap <buffer> <C-g> <C-\><C-n>:close<CR>:sleep 100m<CR>:FzfAg<CR>
tnoremap <buffer> <C-o> <C-\><C-n>:close<CR>:sleep 100m<CR>:FzfHistory<CR>
endfunction
augroup fzfMappingsAu
autocmd!
autocmd FileType fzf call <SID>set_fzf_maps()
augroup END
" Global search allowing navigation from file to file
Plug 'dyng/ctrlsf.vim'
let g:ctrlsf_auto_focus = { 'at': 'start' }
let g:ctrlsf_mapping = { 'next': 'n', 'prev': 'N' }
let g:ctrlsf_position = 'bottom'
let g:ctrlsf_auto_preview = 1
nnoremap <leader>s viw :<C-u>call <SID>GrepFromSelected(visualmode())<CR>
function! s:GrepFromSelected(type)
let saved_unnamed_register = @@
if a:type ==# 'v'
normal! `<v`>y
elseif a:type ==# 'char'
normal! `[v`]y
else
return
endif
let word = substitute(@@, '\n$', '', 'g')
let word = escape(word, '| ')
let @@ = saved_unnamed_register
execute 'CtrlSF '.word
endfunction
" }}
Plug 'easymotion/vim-easymotion'
nmap e <Plug>(easymotion-bd-w)
Plug 'tpope/vim-surround'
Plug 'AndrewRadev/tagalong.vim'
let g:tagalong_additional_filetypes = ['javascript']
let g:tagalong_mappings = ['s', 'c', 'C', 'v', 'i', 'a']
"}}
"{{ Extras
Plug 'itchyny/lightline.vim'
if iterm_profile == 'Dark'
let g:lightline = {
\ 'colorscheme': 'seoul256',
\ }
else
let g:lightline = {
\ 'colorscheme': 'PaperColor_light',
\ }
endif
"}}
" Install all plugins if this is the firs load
if exists('s:first_init')
PlugInstall
end
call plug#end()
"}}}
"{{{ Settings
"{{ General
set magic
set lazyredraw
set encoding=utf-8
set showmatch
set autoread
set updatetime=300
set mouse=a
"}}
"{{ Indentation
set ruler
set tabstop=2
set shiftwidth=2
set expandtab
set smarttab
set autoindent
set smartindent
set nowrap
set bs=2
"}}
"{{ Search
set incsearch
set hlsearch
set smartcase
"}}
"{{ Syntax
filetype plugin indent on
syntax on
syntax sync minlines=100
syntax sync maxlines=240
set synmaxcol=800
" 4 spaces == 1 tab in php
autocmd BufNewFile,BufRead *.php call SetTabsSpacing()
function SetTabsSpacing()
setlocal tabstop=4
setlocal shiftwidth=4
endfunction
"}}
"{{ View
let g:gruvbox_contrast_light="hard"
let g:gruvbox_contrast_dark="soft"
colorscheme gruvbox
if iterm_profile == "Dark"
set background=dark
else
set background=light
endif
set conceallevel=3
set cmdheight=2
set scrolloff=12
let &colorcolumn=80
if has('gui')
:set guioptions-=m " remove menu bar
:set guioptions-=T " remove toolbar
:set guioptions-=r " remove right-hand scroll bar
:set guioptions-=L " remove left-hand scroll bar
end
set shortmess+=A
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
"}}
set hidden
set nobackup
set nowritebackup
set completeopt-=preview
"{{ Sane splits
set splitbelow
"}}
"{{ Persistent Undo
"" Keep undo history across sessions by storing it in a file
if has('persistent_undo')
let vim_dir = '$HOME/.vim'
"let &runtimepath.=','.vim_dir
let undo_dir = expand(vim_dir.'/undo')
call system('mkdir ' . vim_dir)
call system('mkdir ' . undo_dir)
let &undodir = undo_dir
set undofile
set undodir=~/.vim/undo
set undolevels=1000
set undoreload=10000
endif
"}}
"{{ Clipboard
set clipboard=unnamed,unnamedplus
"}}
" clear highlighting on return in normal mode
nnoremap <silent> <CR> :noh<CR><CR>
" Edit vim configuration
nnoremap <silent> <leader>ev :vs $MYVIMRC<CR>
nnoremap <silent> <leader>sv :source $MYVIMRC<CR>
" nice move
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
nnoremap <C-x> <C-w>x
"{{ No annoying bells
set noerrorbells
set novisualbell
set t_vb=
set tm=500
if has("gui_macvim")
autocmd GUIEnter * set vb t_vb=
endif
"}}
"{{ Files
set nobackup
set nowb
set noswapfile
"}}
"}}}
"{{ Aliases
cnoreabbrev W w
cnoreabbrev Q q
cnoreabbrev X x
cnoreabbrev QA qa
"}}
"{{{ Autoreload vim on changes made to vim configuration
augroup vimrc
au!
au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC
augroup END
"}}}
"{{{ Override syntax highlighting
highlight def link jsxTag Identifier
highlight def link jsxTagName Identifier
highlight def link jsxComponentName Identifier
highlight def link jsxAttrib Include
highlight def link jsxAttribKeyword jsxAttrib
highlight def link jsxString String
highlight def link jsxComment Comment
highlight def link jsxDot Operator
highlight def link jsxNamespace Operator
highlight def link jsxEqual Operator
highlight def link jsxSpreadOperator Operator
highlight def link jsxBraces Operator
"}}}