-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
351 lines (312 loc) · 10.3 KB
/
vimrc
File metadata and controls
351 lines (312 loc) · 10.3 KB
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
if has('eval')
silent! execute pathogen#infect()
endif
" GUI Options (applied only once)
if has('gui_running') && !get(g:, 'gui_initialized', 0)
set guioptions=aAcemg
set guifont=CaskaydiaMono\ NFM:h12
set lines=60 columns=200
let g:gui_initialized=1
endif
if has("gui_macvim") && has("gui_running")
set guifont=CaskaydiaCoveNFM-Regular:h14
set lines=80 columns=200
let g:gui_initialized=1
endif
" Run vim-sensible now so that we can override the settings
runtime! plugin/sensible.vim
" Options
set belloff=all
set clipboard=unnamedplus
set sessionoptions+=resize,winpos
set encoding=utf-8
scriptencoding utf-8
set autoread
set modeline
set tabstop=4
set shiftwidth=4
set expandtab
set list
set listchars=tab:→\ ,trail:·,extends:⟩,precedes:⟨,nbsp:␣
if has('mouse')
set mouse=nvc
endif
set mousehide
set shortmess=a
set hidden
set number
set signcolumn=yes
set nofoldenable
set cmdheight=2
set laststatus=2
set hlsearch
set incsearch
set ignorecase
set smartcase
set cinoptions=:0,g0,t0,(0,w1,W4
set fileformats=unix,dos,mac
set switchbuf=useopen
set mousemodel=popup_setpos
set whichwrap=b,s,<,>,~,[,]
set nowrap
set backspace=indent,eol,start
set nospell
set diffopt=filler,vertical,algorithm:patience,indent-heuristic
set colorcolumn=+1
" set textwidth=120
set wildmenu
set cursorline
if executable('rg')
set grepprg=rg\ --vimgrep
set grepformat=%f:%l:%c:%m
endif
" Plugin configuration
if has('eval')
let c_space_errors=1
let g:airline#extensions#tabline#enabled=1
let g:airline#extensions#tabline#fnamemod=':t'
let g:airline#extensions#default#section_truncate_width={}
let g:airline#extensions#lsp#enabled=1
let g:airline_powerline_fonts=1
let g:airline_inactive_collapse=0
let g:netrw_fastbrowse = 0
let g:rooter_patterns = ['.git', 'GenerateProjectFiles.bat', 'Makefile', 'compile_commands.json']
if executable('rg')
let $FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git"'
endif
let g:fzf_colors = {'fg':['fg','Normal'],'bg':['bg','Normal'],'hl':['fg','Comment'],'fg+':['fg','CursorLine','CursorColumn','Normal'],'bg+':['bg','CursorLine','CursorColumn'],'hl+':['fg','Statement'],'info':['fg','PreProc'],'prompt':['fg','Conditional'],'pointer':['fg','Exception'],'marker':['fg','Keyword'],'spinner':['fg','Label'],'header':['fg','Comment']}
let g:lsp_diagnostics_echo_cursor=1
let g:lsp_diagnostics_signs_enabled=1
let g:lsp_diagnostics_float_cursor=1
let g:lsp_diagnostics_virtual_text_enabled=1
let g:lsp_signature_help_enabled=1
let g:lsp_code_action_ui='float'
let g:asyncomplete_auto_completeopt=0
set completeopt=menuone,noinsert,popup
endif
" Completion menu: Enter or Tab accepts the selected item
inoremap <expr> <CR> pumvisible() ? "\<C-Y>" : "\<CR>"
inoremap <expr> <Tab> pumvisible() ? "\<C-Y>" : "\<Tab>"
" vim-lsp key mappings
if has('eval')
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
nmap <buffer> gd :FzfLspDefinition<CR>
nmap <buffer> gD :FzfLspDeclaration<CR>
nmap <buffer> gr :FzfLspReferences<CR>
nmap <buffer> gi :FzfLspImplementation<CR>
nmap <buffer> K <plug>(lsp-hover)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> <leader>ca :FzfLspCodeAction<CR>
nmap <buffer> <leader>a <plug>(lsp-switch-source-header)
nmap <buffer> <leader>f <plug>(lsp-document-format)
vmap <buffer> <leader>f <plug>(lsp-document-range-format)
endfunction
if has('autocmd')
augroup lsp_install
autocmd!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
endif
endif
" Colorscheme
if has('termguicolors')
if !has('gui_running') && &term =~# '^\(tmux\|screen\)'
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set termguicolors
endif
if has('eval')
let g:codedark_modern=1
let g:airline_theme='codedark'
endif
silent! colorscheme codedark
" Auxiliary functions
" Cleans up all trailing whitespace and retabs the file
if has('eval')
command! SessionReset only | %bdelete
command! DiffOff call <SID>DiffOff()
function! <SID>DiffOff()
let l:scratchbufs = []
for l:buf in getbufinfo()
let l:name = bufname(l:buf.bufnr)
let l:is_scratch = getbufvar(l:buf.bufnr, '&buftype') ==# 'nofile' && getbufvar(l:buf.bufnr, '&diff')
let l:is_fugitive = l:name =~# '^fugitive://' && getbufvar(l:buf.bufnr, '&diff')
if l:is_scratch || l:is_fugitive
call add(l:scratchbufs, l:buf.bufnr)
endif
endfor
diffoff!
for l:buf in l:scratchbufs
execute 'bwipeout ' . l:buf
endfor
endfunction
command! Cleanup call <SID>CleanupFile()
function! <SID>CleanupFile()
%s/\s\+$//ge
retab
endfunction
function! s:YankHighlight()
let [l1, c1] = [line("'["), col("'[")]
let [l2, c2] = [line("']"), col("']")]
let lines = []
if l1 == l2
call add(lines, [l1, c1, c2 - c1 + 1])
else
call add(lines, [l1, c1, col([l1, '$']) - c1])
for l in range(l1 + 1, l2 - 1)
call add(lines, [l])
endfor
call add(lines, [l2, 1, c2])
endif
let m = matchaddpos('IncSearch', lines)
call timer_start(200, {-> matchdelete(m)})
endfunction
endif
" vim-which-key
nnoremap <silent> <Leader> :<C-U>WhichKey '\'<CR>
" Key mappings
" Manipulate .vimrc
nnoremap <silent> <Leader>v :e $MYVIMRC<CR>
nnoremap <silent> <Leader>p :source $MYVIMRC<CR>
" fzf
nnoremap <silent> <C-P> :Files<CR>
nnoremap <silent> <Leader>b :Buffers<CR>
nnoremap <silent> <Leader>/ :Rg<CR>
nnoremap <silent> <Leader>g :silent grep <C-R><C-W> \| copen<CR>
nnoremap <silent> <expr> <Leader>c getwininfo()->filter({_,v -> v.quickfix})->len() ? ":cclose\<CR>" : ":copen\<CR>"
" Window manipulation
nnoremap <silent> <Leader>q :Bdelete<CR>
nnoremap <silent> <Leader>a :A<CR>
nnoremap <silent> <C-S> :update<CR>
inoremap <silent> <C-S> <C-O>:update<CR>
noremap <silent> <C-TAB> :bnext<CR>
noremap <silent> <S-C-TAB> :bprev<CR>
" Toggle bottom terminal
nnoremap <silent> <C-`> :call <SID>ToggleTerminal()<CR>
tnoremap <silent> <C-`> <C-W>:call <SID>ToggleTerminal()<CR>
if has('eval')
function! s:ToggleTerminal()
let l:buf = get(g:, 'terminal_buf', -1)
if l:buf != -1 && bufexists(l:buf)
let l:win = bufwinnr(l:buf)
if l:win != -1
execute l:win . 'wincmd w'
hide
else
execute 'botright sbuffer ' . l:buf
resize 15
endif
else
botright terminal
resize 15
let g:terminal_buf = bufnr('%')
endif
endfunction
endif
" Window navigation
nnoremap <C-H> <C-W>h
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-L> <C-W>l
tnoremap <C-H> <C-W>h
tnoremap <C-J> <C-W>j
tnoremap <C-K> <C-W>k
tnoremap <C-L> <C-W>l
" IDE-style mappings
nnoremap <silent> <A-o> :A<CR>
nnoremap <silent> <F2> <plug>(lsp-rename)
nnoremap <silent> <F12> :FzfLspDefinition<CR>
nnoremap <silent> <S-F12> :FzfLspReferences<CR>
nnoremap <silent> <C-S-o> :FzfLspDocumentSymbol<CR>
nnoremap <silent> <C-t> :FzfLspWorkspaceSymbol<CR>
nnoremap <silent> <A-Up> :move .-2<CR>==
nnoremap <silent> <A-Down> :move .+1<CR>==
vnoremap <silent> <A-Up> :move '<-2<CR>gv=gv
vnoremap <silent> <A-Down> :move '>+1<CR>gv=gv
nnoremap <silent> <A-g> :FzfLspDefinition<CR>
nnoremap <silent> <C-LeftMouse> <LeftMouse>:FzfLspDefinition<CR>
nnoremap <silent> <X1Mouse> <C-O>
nnoremap <silent> <X2Mouse> <C-I>
nnoremap <silent> <A-m> :FzfLspDocumentSymbol<CR>
nnoremap <silent> <A-S-o> :Files<CR>
nnoremap <silent> <A-S-s> :FzfLspWorkspaceSymbol<CR>
nnoremap <silent> <A-Left> <C-O>
nnoremap <silent> <A-Right> <C-I>
nnoremap <silent> <Leader>gs :Git<CR>
nnoremap <silent> <Leader>gb :Git blame<CR>
nnoremap <silent> <Leader>do :DiffOrig<CR>
nnoremap <silent> <Leader>dg :Gdiffsplit<CR>
nnoremap <silent> <Leader>dp :Vp4Diff<CR>
nnoremap <silent> <C-S-f> :Rg<CR>
nnoremap <silent> <C-/> :Commentary<CR>
vnoremap <silent> <C-/> :Commentary<CR>
" Function keys
nnoremap <silent> <F3> :nohlsearch<CR>
" Control-Backspace deletes a word
inoremap <C-BS> <C-W>
cnoremap <C-BS> <C-W>
" Auto commands
if has('autocmd')
augroup vimrc
autocmd!
" Briefly highlight yanked text
if exists('##TextYankPost') && has('patch-8.0.1394')
autocmd TextYankPost * call s:YankHighlight()
endif
" Change formatoptions regardless of filetype
autocmd FileType * setlocal formatoptions-=o
" Use C++ style comments in C++
autocmd FileType c,cpp let b:commentary_format="//%s"
" Set tw=78 on text files
autocmd FileType markdown setlocal tw=78 spell
" Git commit tw=72
autocmd FileType gitcommit setlocal textwidth=72 spell
" K looks up help in .vim files instead of running man
autocmd FileType vim nmap K :help <c-r><c-w><cr>
autocmd FileType bindzone setlocal ts=8 sw=8
autocmd FileType yaml,yml setlocal indentkeys-=0#
" Auto open qf window after grep
autocmd QuickFixCmdPost [^l]*grep* cwindow
autocmd QuickFixCmdPost l*grep* lwindow
" Restore line position
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Auto-restore session if Session.vim exists and no files were passed
autocmd VimEnter * nested
\ if !argc() && filereadable('Session.vim') |
\ source Session.vim |
\ endif
" Auto cleanup of vim-fugitive buffers
autocmd BufReadPost fugitive://* set bufhidden=delete
" Press q to close diff mode, disable LSP on scratch diff buffers
autocmd OptionSet diff if &diff
\ | nnoremap <buffer> <silent> q :DiffOff<CR>
\ | if &buftype ==# 'nofile' | let b:lsp_diagnostics_enabled = 0 | endif
\ | else
\ | silent! nunmap <buffer> q
\ | endif
" Change directory to file path for each buffer (replaced by vim-rooter)
" autocmd BufEnter,BufReadPost * silent! lcd %:p:h
augroup END
end
" Load local config file
if has('eval')
let s:vimrc_local = expand("<sfile>:p:r")."_local"
if filereadable(s:vimrc_local)
exe "source " . fnameescape(s:vimrc_local)
endif
if has('gui_running')
let s:vimrc_local_gui = expand("<sfile>:p:r")."_local_gui"
if filereadable(s:vimrc_local_gui)
exe "source " . fnameescape(s:vimrc_local_gui)
endif
endif
endif
" vim:ts=2:sw=2:tw=100:et:ft=vim: