-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
403 lines (333 loc) · 11.2 KB
/
init.vim
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
lua require('plugins')
lua require('config')
let g:polyglot_disabled = ['latex']
nn <F9> :silent Dispatch!<CR>
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
nnoremap gj j
nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap gk k
nnoremap gV `[v`]
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
nnoremap & :&&<CR>
xnoremap & :&&<CR>
let mapleader=","
noremap \ ,
inoremap jk <ESC>
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
filetype plugin on
runtime plugins/matchit.vim
syntax on
nnoremap <space>f <cmd>Telescope find_files<cr>
nnoremap <space>g <cmd>Telescope live_grep<cr>
nnoremap <space>r <cmd>Telescope grep_string<cr>
nnoremap <space>b <cmd>Telescope buffers<cr>
nnoremap <space>h <cmd>Telescope help_tags<cr>
nnoremap <space>o <cmd>Telescope oldfiles cwd_only=true<cr>
nnoremap <space>m <cmd>Telescope marks<cr>
nnoremap <space>q <cmd>Telescope quickfix<cr>
nnoremap <space>k <cmd>Telescope keymaps<cr>
nnoremap <space>a <cmd>Telescope diagnostics bufnr=0<cr>
nnoremap <space>s <cmd>Telescope lsp_document_symbols<cr>
nnoremap <space>p <cmd>Telescope resume<cr>
function! ToggleZoom(zoom, direction)
if exists("t:restore_zoom") && (a:zoom == v:true || t:restore_zoom.win != winnr())
exec t:restore_zoom.cmd
unlet t:restore_zoom
elseif a:zoom
let t:restore_zoom = { 'win': winnr(), 'cmd': winrestcmd() }
if a:direction == "vert"
exec "normal \<C-W>_"
else
exec "normal \<C-W>\|"
endif
endif
endfunction
augroup restorezoom
au WinEnter * silent! :call ToggleZoom(v:false, "")
augroup END
nnoremap <silent> <C-w>z :call ToggleZoom(v:true, 'vert')<CR>
nnoremap <silent> <C-w>Z :call ToggleZoom(v:true, 'horiz')<CR>
let g:DirDiffExcludes = "CVS,*.class,*.o,.git,build,.clangd"
let g:DirDiffWindowSize = winheight(0)*2/3
let g:rooter_patterns = ['.git']
let g:rooter_silent_chdir = 1
let g:SignatureMap = {
\ 'Leader' : "m",
\ 'PlaceNextMark' : "m,",
\ 'ToggleMarkAtLine' : "m.",
\ 'PurgeMarksAtLine' : "m-",
\ 'DeleteMark' : "dm",
\ 'PurgeMarks' : "m<Space>",
\ 'PurgeMarkers' : "m<BS>",
\ 'GotoNextLineAlpha' : "",
\ 'GotoPrevLineAlpha' : "",
\ 'GotoNextSpotAlpha' : "",
\ 'GotoPrevSpotAlpha' : "",
\ 'GotoNextLineByPos' : "",
\ 'GotoPrevLineByPos' : "",
\ 'GotoNextSpotByPos' : "",
\ 'GotoPrevSpotByPos' : "",
\ 'GotoNextMarker' : "",
\ 'GotoPrevMarker' : "",
\ 'GotoNextMarkerAny' : "",
\ 'GotoPrevMarkerAny' : "",
\ 'ListBufferMarks' : "m/",
\ 'ListBufferMarkers' : "m?"
\ }
nnoremap <F8> :TagbarToggle<CR>
nnoremap <F5> :UndotreeToggle<cr>
let g:undotree_SetFocusWhenToggle = 1
let g:undotree_WindowLayout = 2
let g:better_whitespace_filetypes_blacklist=['git', 'diff', 'gitcommit', 'unite', 'qf', 'help']
let g:better_whitespace_enabled=0
let g:strip_whitespace_on_save=0
let g:slime_no_mappings = 1
xmap <c-c><c-c> <Plug>SlimeRegionSend
nmap <c-c>v <Plug>SlimeConfig
let g:slime_target = 'tmux'
" tmux target pane should be the last digit of $TMUX + :, e.g., 8:. Need
" "default" not "default " as tmux server
let g:slime_python_ipython = 1
let g:slime_default_config = {"socket_name": "default", "target_pane": "{last}"}
let g:slime_dont_ask_default = 1
let g:ipython_cell_delimit_cells_by = 'tags'
nnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gm :Gstatus<CR><C-w>T
nnoremap <leader>gp :Gpush<CR>
nnoremap <silent> <C-n> :set hlsearch!<CR>
au FocusLost * silent! wa
au BufLeave * silent! wa
au BufNewFile,BufRead *.cu set filetype=cuda
au BufNewFile,BufRead *.cu_inl set filetype=cuda
au BufNewFile,BufRead *.cuh set filetype=cuda
command! MakeTags !ctags -R .
command! Nw noa w
function! GetFilepath_T()
" from https://github.com/Lokaltog/vim-powerline/blob/09c0cea859a2e0989eea740655b35976d951a84e/autoload/Powerline/Functions.vim
let dirsep = has('win32') && ! &shellslash ? '\' : '/'
let filepath = expand('%:p:~')
let fpath = split(filepath, dirsep)
let len_p = len(fpath)
if len_p > 2
let fpath_shortparts = map(fpath[0:-3], 'v:val[0]')
let ret = extend(fpath_shortparts, [fpath[-2], fpath[-1]])
let ret = join(ret, dirsep)
if filepath[0] == dirsep
let ret = dirsep . ret
endif
else
let ret = filepath
endif
return ret
endfunction
function! LightlineGitGutter()
let branch = get(b:, 'gitsigns_head', '')
let status = get(b:, 'gitsigns_status', '')
if !(status == '')
return branch . ' ' . status
else
return branch
endif
endfunction
let g:lightline = {
\ 'colorscheme': 'gruvbox',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'tpath', 'readonly', 'modified', 'git', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_hints', 'linter_ok' ] ],
\ 'right': [[ 'lineinfo'] ] },
\ 'inactive': {
\ 'left': [ ['tpath', 'readonly', 'modified' ] ],
\ 'right': [ [ 'lineinfo' ],
\ ]
\ },
\ 'component': {
\ 'lineinfo': '%3l(%L):%-2v',
\ },
\ 'component_function': {
\ 'tpath': 'GetFilepath_T',
\ 'git': 'LightlineGitGutter'
\ },
\ }
let g:lightline.component_expand = {
\ 'linter_hints': 'lightline#lsp#hints',
\ 'linter_infos': 'lightline#lsp#infos',
\ 'linter_warnings': 'lightline#lsp#warnings',
\ 'linter_errors': 'lightline#lsp#errors',
\ 'linter_ok': 'lightline#lsp#ok',
\ }
filetype plugin indent on
let g:tex_flavor='latex'
let g:vimtex_view_method='zathura'
let g:vimtex_quickfix_mode=0
let g:tex_conceal='abdmg'
set spelllang=en_us
set spellfile=~/Dropbox/scripts/nvim/spell/en.utf-8.add
inoremap <C-l> <c-g>u<Esc>[s1z=`]a<c-g>u
" for d in glob('~/Dropbox/scripts/nvim/spell/*.add', 1, 1)
" if filereadable(d) && (!filereadable(d . '.spl') || getftime(d) > getftime(d . '.spl'))
" exec 'mkspell! ' . fnameescape(d)
" endif
" endfor
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
au FileType markdown,text,rst
\ let b:dispatch = '~/.config/nvim/preview.sh %:p' |
\ setlocal spell |
\ setlocal textwidth=80 |
\ setlocal formatlistpat+=\\\|^\\*\\s*
au FileType tex,latex
\ let b:dispatch = '~/.config/nvim/preview.sh %:p' |
\ setlocal spell |
\ setlocal textwidth=80
au FileType json
\ set conceallevel=0 |
\ nn <buffer> <F4> :%!python3 -m json.tool<CR>
au FileType python
\ nnoremap <buffer> <c-c><c-c> :IPythonCellExecuteCellVerbose<CR> |
\ nnoremap <buffer> <c-c><c-n> :IPythonCellExecuteCellVerboseJump<CR> |
\ Abolish -buffer true True |
\ Abolish -buffer false False
au FileType cpp
\ setlocal cindent
au BufWritePost *.sh silent! !chmod +x %:p
let g:netrw_banner = 0
let g:netrw_winsize = 20
let g:netrw_altv = 1
let g:netrw_cursor = 1
let g:netrw_browsex_viewer="xdg-open"
let g:netrw_fastbrowse = 0
let g:netrw_altfile = 1
let g:netrw_liststyle = 1
let g:netrw_maxfilenamelen = 50
tnoremap <Esc> <C-\><C-n>
tnoremap <C-v><Esc> <Esc>
nnoremap <leader>T <C-w>T<CR>
nnoremap <leader>t :tab split<CR>
let g:dispatch_no_maps = 1
nnoremap <S-Tab> :bnext<cr>
nnoremap <space><space> <C-^>
nnoremap <C-j> <C-d>
nnoremap <C-k> <C-u>
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
nnoremap <silent> <C-w>j :wincmd h<CR>
nnoremap <silent> <C-w>k :wincmd l<CR>
nnoremap <silent> <C-w>h :wincmd j<CR>
nnoremap <silent> <C-w>l :wincmd k<CR>
" # Function to permanently delete views created by 'mkview'
function! MyDeleteView()
let path = fnamemodify(bufname('%'),':p')
" vim's odd =~ escaping for /
let path = substitute(path, '=', '==', 'g')
if empty($HOME)
else
let path = substitute(path, '^'.$HOME, '\~', '')
endif
let path = substitute(path, '/', '=+', 'g') . '='
" view directory
let path = &viewdir.'/'.path
call delete(path)
echo "Deleted: ".path
endfunction
" # Command Delview (and it's abbreviation 'delview')
command Delview call MyDeleteView()
" Lower-case user commands: http://vim.wikia.com/wiki/Replace_a_builtin_command_using_cabbrev
cabbrev delview <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Delview' : 'delview')<CR>
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
command! TT :vs | terminal
augroup TerminalStuff
autocmd TermOpen * setlocal nonumber norelativenumber signcolumn=no | startinsert
augroup END
" file is large from 10mb
let g:LargeFile = 1024 * 1024 * 100
augroup LargeFile
au!
autocmd BufReadPre * let f=getfsize(expand("<afile>")) | if f > g:LargeFile || f == -2 | call LargeFile() | endif
augroup END
function! LargeFile()
" save memory when other file is viewed
setlocal bufhidden=unload
" is read-only (write with :w new_filename)
setlocal buftype=nowrite
" no undo possible
setlocal undolevels=-1
" display message
set noloadplugins
set lazyredraw
set noswapfile
set eventignore=all
set nohidden
set syntax=off
autocmd VimEnter * echo "The file is larger than " . (g:LargeFile / 1024 / 1024) . " MB, so some options are changed (see .vimrc for details)."
endfunction
if exists('$TMUX')
augroup TMUX
autocmd BufEnter,BufNewFile,WinEnter * call system("tmux rename-window \"nvim " . expand("%") . "\"") |
augroup END
endif
if !exists('g:lasttab')
let g:lasttab = 1
endif
nmap <space>T :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
nnoremap <expr> <space>v '`[' . strpart(getregtype(), 0, 1) . '`]'
" from https://www.vim.org/scripts/script.php?script_id=4335
let s:savedCpo = &cpo
set cpo&vim
function! s:VStarsearch_searchCWord()
let wordStr = expand("<cword>")
if strlen(wordStr) == 0
echohl ErrorMsg
echo 'E348: No string under cursor'
echohl NONE
return
endif
if wordStr[0] =~ '\<'
let @/ = '\<' . wordStr . '\>'
else
let @/ = wordStr
endif
let savedUnnamed = @"
let savedS = @s
normal! "syiw
if wordStr != @s
normal! w
endif
let @s = savedS
let @" = savedUnnamed
endfunction
" https://github.com/bronson/vim-visual-star-search/
function! s:VStarsearch_searchVWord()
let savedUnnamed = @"
let savedS = @s
normal! gv"sy
let @/ = '\V' . substitute(escape(@s, '\'), '\n', '\\n', 'g')
let @s = savedS
let @" = savedUnnamed
endfunction
nnoremap <silent> * :call <SID>VStarsearch_searchCWord()<CR>:set hls<CR>
vnoremap <silent> * :<C-u>call <SID>VStarsearch_searchVWord()<CR>:set hls<CR>
nmap <silent> # *
vmap <silent> # *
noremap <expr> n 'Nn'[v:searchforward]
noremap <expr> N 'nN'[v:searchforward]
let &cpo = s:savedCpo
" autocmd BufReadPost fugitive://* set bufhidden=delete
nnoremap <leader>cd :cd %:p:h<CR>:pwd<CR>
" au VimEnter * let g:volatile_ftypes += ['git']
"
" to find out origin of a mapping use e.g., :verbose map <C-x>
" copy relative filepath and the current line number to clipboard
nmap ,cl :let @+=join([@%, line(".")], ':')<CR>
nmap ,h /[^\d0-\d127]<CR>
let g:python3_host_prog = expand('/usr/bin/python3')
" highlight link TSError Normal
let g:vim_isort_config_overrides = { 'profile': 'black'}
autocmd FileType c,cpp,java setlocal commentstring=//\ %s