-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vimrc
442 lines (359 loc) · 11.8 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
" =============================
" Utility Functions
" =============================
function! SilentMkdir(path)
if !isdirectory(a:path)
call mkdir(a:path, "p", 0700)
endif
endfunction
" =============================
" Vim Settings
" =============================
" Basics
syntax enable
set number
set relativenumber
set cursorline
set hlsearch
set ignorecase
set smartcase
" Correct use of tabs
set tabstop=4
set expandtab
" Indentation
set shiftwidth=4
set shiftround
set autoindent
" Sensible backspace behavior
set backspace=2
" Open new split panes to right and bottom
set splitbelow
set splitright
" Tab completion in status bar
set wildmenu
" Enable all mouse modes
set mouse=a
" Disable page scrolling keybindings
noremap <S-Up> <Up>
noremap <S-Down> <Down>
" Use <Space> as leader key
let mapleader="\<Space>"
noremap <Space> <Nop>
" Use 'kj' to exit insert and command mode
inoremap kj <esc>
cnoremap kj <C-C>
" Persistent undo
set undofile "Maintain undo history between sessions
set undodir=~/.vim/undodir
call SilentMkdir($HOME . "/.vim/undodir")
" Load MAN plugin
runtime ftplugin/man.vim
" Write swap and backup files in different directory
set backupdir=~/.vim/backupdir//,/tmp//
set directory=~/.vim/swapfiles//,/tmp//
call SilentMkdir($HOME . "/.vim/backupdir")
call SilentMkdir($HOME . "/.vim/swapfiles")
" ------------------------------
" Shortcuts
" ------------------------------
" Quick save
nnoremap <Leader>w :w<CR>
nnoremap <Leader>wq :wq<CR>
" Open quickfix list item in new tab
nnoremap <C-t> <C-w><CR><C-w>T
" Move between tabs with <C-S-ARROW>
nnoremap <C-S-RIGHT> gt
nnoremap <C-S-LEFT> gT
" Select last edited text (including paste)
nnoremap gV `[v`]
" Copy selected text to clipboard
vnoremap <C-S-c> "+y
" Define 'a line' and 'inside line' text objects
" al is the whole line, including all white space
" il is the 'text' inside the line, no leading/trailing white space
vnoremap <silent> al :<C-U>normal 0v$h<CR>
omap <silent> al :normal val<CR>
vnoremap <silent> il :<C-U>normal ^vg_<CR>
omap <silent> il :normal vil<CR>
" =============================
" Commands & Functions
" =============================
" Run makeprg and open quickfix window
command -nargs=* Make make! <args> | cwindow
" Open split with some Latex character sequences translated to UTF-8 glyphs
command TexPreview setlocal scrollbind | vsplit
\ | setlocal conceallevel=2 | wincmd h
function! DeleteInactiveBuffers()
let tpbl=[]
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
for buf in filter(range(1, bufnr('$')), 'buflisted(v:val) && index(tpbl, v:val)==-1')
silent exec 'bd' buf
endfor
endfunction
" =============================
" Vim Plug
" =============================
" Automatically install vim-plug
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')
" High-light current word
Plug 'RRethy/vim-illuminate'
" Commenting shortcuts
Plug 'tomtom/tcomment_vim'
" Useful shell commands inside vim
Plug 'tpope/vim-eunuch'
" Surrounding text
Plug 'tpope/vim-surround'
" '.' command support for plugins
Plug 'tpope/vim-repeat'
" Handy navigation shortcuts
Plug 'tpope/vim-unimpaired'
" Manipulate variants of a word
Plug 'tpope/vim-abolish'
" Aligning text
Plug 'godlygeek/tabular'
" More text objects
Plug 'wellle/targets.vim'
" Enhanced matching text navigation
Plug 'andymass/vim-matchup'
" Live previews for substitute commands
Plug 'markonm/traces.vim'
" Highlight exact differences in diffs
Plug 'rickhowe/diffchar.vim'
" Linting engine
Plug 'dense-analysis/ale'
" GitHub copilot integration
Plug 'github/copilot.vim'
" Fugitive plug-in for git
Plug 'tpope/vim-fugitive'
" Git diff in gutter
Plug 'airblade/vim-gitgutter'
" Pretty status line
Plug 'itchyny/lightline.vim'
" FZF, both command and plugin installation
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Latex integration
Plug 'lervag/vimtex'
" Jupyter notebook integration
Plug 'untitled-ai/jupyter_ascending.vim'
" Markdown integration
Plug 'plasticboy/vim-markdown'
" Markdown preview
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
" Modern IDE features
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Snippets
Plug 'SirVer/ultisnips'
" Color schemes
Plug 'altercation/vim-colors-solarized'
Plug 'sonph/onehalf', { 'rtp': 'vim' }
" Initialize plugin system
call plug#end()
" =============================
" Plugin settings
" =============================
" ------------------------------
" Color Scheme
" ------------------------------
set background=dark
colorscheme onehalfdark
" Enable 24-bit colors, if possible
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
" Set matching onehalfdark colors for terminal windows.
let g:terminal_ansi_colors = [
\ '#282c34', '#e06c75', '#98c379', '#e5c07b',
\ '#61afef', '#c678dd', '#56b6c2', '#dcdfe4',
\ '#5c6370', '#e06c75', '#98c379', '#e5c07b',
\ '#61afef', '#c678dd', '#56b6c2', '#dcdfe4'
\ ]
endif
" ------------------------------
" Lightline
" ------------------------------
set laststatus=2
set noshowmode
let g:lightline = {
\ 'colorscheme': 'onehalfdark',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead'
\ },
\ }
" ------------------------------
" GitGutter
" ------------------------------
" Update sign column every quarter second
set updatetime=250
" ------------------------------
" ALE
" ------------------------------
" Automatically open/close location list on error
let g:ale_open_list = 1
" Show 5 lines of errors
let g:ale_list_window_size = 5
" Use virtual text only in current line
let g:ale_virtualtext_cursor = 1
" Use floating windows for hover message
let g:ale_hover_to_floating_preview = 1
" Pretty border for floating windows
let g:ale_floating_window_border = ['│', '─', '╭', '╮', '╯', '╰', '│', '─']
" ALE mappings
nnoremap <Leader>af :ALEFix<CR>
" ------------------------------
" CoC
" ------------------------------
" Use <TAB> for trigger completion with characters ahead and navigate.
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <CR> to accept selected completion item
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" CoC mappings
nnoremap <silent> <Leader>sr <Plug>(coc-rename)
nnoremap <silent> <Leader>sd :call CocActionAsync('definitionHover')<CR>
nnoremap <silent> <Leader>sjd <Plug>(coc-definition)
nnoremap <silent> <Leader>sji <Plug>(coc-implementation)
nnoremap <silent> <Leader>sjr <Plug>(coc-references)
nnoremap <silent> <Leader>sf <Plug>(coc-format)
nnoremap <silent> <Leader>sa <Plug>(coc-codeaction-line)
xnoremap <silent> <Leader>sa <Plug>(coc-codeaction-selected)
nnoremap <silent> <Leader>sA <Plug>(coc-codeaction)
" Define function and class text objects
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Disable conflicting page scrolling shortcuts
nnoremap <C-f> <Nop>
nnoremap <C-b> <Nop>
vnoremap <C-f> <Nop>
vnoremap <C-b> <Nop>
" Scroll CoC float windows/popups
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1, 3) : ""
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0, 3) : ""
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1, 3)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0, 3)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1, 3) : ""
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0, 3) : ""
" CoC extensions
let g:coc_global_extensions = [
\ 'coc-json',
\ 'coc-pyright',
\ 'coc-pydocstring',
\ 'coc-vimtex',
\ ]
" ------------------------------
" UltiSnips
" ------------------------------
let g:UltiSnipsExpandTrigger = '<C-j>'
let g:UltiSnipsListSnippets = '<C-y>'
let g:UltiSnipsJumpForwardTrigger = '<C-j>'
let g:UltiSnipsJumpBackwardTrigger = '<C-k>'
" Open snippet editor in split window
let g:UltiSnipsEditSplit = 'context'
" ------------------------------
" Vim-Traces
" ------------------------------
" Support for Vim-Abolish commands
let g:traces_abolish_integration = 1
" ------------------------------
" VimTeX
" ------------------------------
" Set PDF viewer
let g:vimtex_view_method = 'mupdf'
" Disable searching included files for text completion
let g:vimtex_include_search_enabled = 0
" ------------------------------
" Jupyter-Ascending
" ------------------------------
" Add sync mapping
nnoremap <Space><Space>s :call jupyter_ascending#sync()<CR>
" Disable automatic syncing
let g:jupyter_ascending_auto_write = v:false
" ------------------------------
" Vim-Markdown
" ------------------------------
" Disable folding
let g:vim_markdown_folding_disabled = 1
" ------------------------------
" GitHub Copilot
" ------------------------------
" Ask for completions
nnoremap <Leader>c :Copilot<CR>
" Use <C-l> to accept completions
imap <silent><script><expr> <C-l> copilot#Accept("\<CR>")
let g:copilot_no_tab_map = v:true
" ------------------------------
" FZF
" ------------------------------
" Search files
nnoremap <Leader>f :Files<CR>
" Search inisde files
nnoremap <Leader>g :Rg<CR>
" Search lines in open buffers
nnoremap <Leader>l :BLines<CR>
nnoremap <Leader>L :Lines<CR>
" Search vim commands
nnoremap <Leader>; :Commands<CR>
" Search open buffers
nnoremap <Leader>b :Buffers<CR>
" Search through tags
nnoremap <Leader>t :BTags<CR>
nnoremap <Leader>T :Tags<CR>
" Search through help tags
nnoremap <Leader>H :Helptags<CR>
" Search through snippets
nnoremap <Leader>z :Snippets<CR>
inoremap <C-z> <C-o>:Snippets<CR>
" Run highlighted command directly
let g:fzf_commands_expect = 'alt-enter'
" ------------------------------
" Tabularize
" ------------------------------
" Align text to character after <Leader>a
nnoremap <expr> <Leader>x ':Tabularize /'.nr2char(getchar()).'<CR>'
vnoremap <expr> <Leader>x ':Tabularize /'.nr2char(getchar()).'<CR>'
" =============================
" Miscellaneous
" =============================
" Highlight misspelled spelled words in red
hi SpellBad cterm=underline ctermfg=red
" Remove highlighting of first quickfix item
hi QuickFixLine ctermbg=none
" Use git commit highlighting for dotfiles commits
augroup DotFilesCommit
autocmd!
autocmd BufRead,BufNewFile COMMIT_EDITMSG set filetype=gitcommit
augroup END
" =============================
" Per-Project Settings
" =============================
" Load settings from .projct_vimrc for all files in a project:
" augroup PerProjectSettings
" autocmd!
" autocmd BufReadPre,BufNewFile /patch/to/project/* source /path/to/.project_vimrc
" augroup END
" BufReadPre loads settings BEFORE the file is read, so that autocmd settings work.