-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.vim
471 lines (434 loc) · 13.5 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
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
"Leader {{{
let mapleader = ','
"}}}
"Python interpreter {{{
let home = expand('~')
let py3path = home . '/.venvs/neovim/bin/'
let py3interp = py3path . 'python'
let g:python3_host_prog = py3interp
"}}}
" Settings {{{
set autoindent
set autoread
set backspace=indent,eol,start
set cmdheight=2
set colorcolumn=79
set cursorline
set dictionary+=/usr/share/dict/words
set dictionary?
set encoding=utf-8
set expandtab
set foldlevel=99
set foldmethod=syntax
set guicursor=
set hidden
set hlsearch
set ignorecase
set inccommand=nosplit
set incsearch
set laststatus=2
set nocompatible
set noshowmode
set number
set path+=**
set scrolloff=2
set shiftwidth=4
set shortmess+=c
set showcmd
set signcolumn=yes
set smartcase
set smarttab
set splitbelow
set splitright
set t_Co=256
set tabstop=4
set termguicolors
set updatetime=300
set wildmenu
set wildmode=longest,list
set mouse=
set ffs=unix
syntax on
filetype plugin on
"}}}
" Terminal {{{
tnoremap <Esc> <C-\><C-n>
" }}}
" Plugins {{{
call plug#begin('~/.local/share/nvim/plugged')
Plug 'cespare/vim-toml'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'ekalinin/Dockerfile.vim'
Plug 'fatih/vim-go'
Plug 'flazz/vim-colorschemes'
Plug 'mhinz/vim-grepper'
Plug 'neoclide/coc.nvim', {'branch': 'release', 'do': 'yarn install --frozen-lockfile'}
Plug 'preservim/tagbar'
Plug 'preservim/vim-markdown'
Plug 'puremourning/vimspector'
Plug 'rust-lang/rust.vim'
Plug 'sbdchd/neoformat'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'Shougo/echodoc'
Plug 'tpope/vim-fugitive'
Plug 'Yggdroot/indentLine'
Plug 'vim-python/python-syntax'
Plug 'arzg/vim-sh'
Plug 'airblade/vim-gitgutter'
Plug 'kana/vim-submode'
Plug 'tpope/vim-surround'
Plug 'mustache/vim-mustache-handlebars'
Plug 'hashivim/vim-terraform'
Plug 'tpope/vim-abolish'
Plug 'wesQ3/vim-windowswap'
Plug 'inkarkat/vim-SyntaxRange'
Plug 'inkarkat/vim-ingo-library'
Plug 'romainl/vim-qf'
Plug 'towolf/vim-helm'
Plug 'derdennis/vim-markdownfootnotes'
call plug#end()
" }}}
"Colorscheme {{{
colorscheme molokai
"}}}
" Local functions {{{
function! ToggleQuickFix()
if empty(filter(getwininfo(), 'v:val.quickfix'))
copen
else
cclose
endif
endfunction
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
function! ProjectTab(projectDir) abort
tabnew
execute 'tcd' a:projectDir
NERDTreeToggle
endfunction
function! ActionLint() abort
if executable('actionlint')
cgete system('actionlint -oneline')
copen
endif
endfunction
function! Scratch()
split
noswapfile hide enew
setlocal buftype=nofile
setlocal bufhidden=hide
"setlocal nobuflisted
"lcd ~
file scratch
endfunction
" }}}
" Commands {{{
command! -nargs=1 -complete=file ProjectTab call ProjectTab(<f-args>)
command! ActionLint call ActionLint()
command! Scratch call Scratch()
" }}}
" Keymaps {{{
" Insert {{{
imap <Left> <Nop>
imap <Right> <Nop>
imap <Up> <Nop>
imap <Down> <Nop>
inoremap <PageUp> <Nop>
inoremap <PageDown> <Nop>
inoremap <Insert> <Nop>
inoremap <Home> <Nop>
inoremap <End> <Nop>
inoremap <Del> <Nop>
inoremap <C-h> <Left>
imap <C-j> <C-o>gj
imap <C-k> <C-o>gk
inoremap <C-l> <Right>
inoremap <F5> <C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR>
inoremap <silent><expr> <C-e> coc#pum#visible() ? coc#pum#cancel() : "\<C-e>"
inoremap <silent><expr> <C-n> coc#pum#visible() ? coc#pum#next(1) : "\<C-n>"
inoremap <silent><expr> <C-p> coc#pum#visible() ? coc#pum#prev(1) : "\<C-p>"
inoremap <silent><expr> <c-space> coc#refresh()
inoremap <silent><expr> <C-y> coc#pum#visible() ? coc#pum#confirm() : "\<C-y>"
inoremap <silent><expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<CR>"
inoremap <silent><expr> <TAB> coc#pum#visible() ? coc#_select_confirm() : "\<TAB>"
"}}}
" Normal {{{
nnoremap <leader>qf <Plug>(qf_qf_toggle)
nnoremap qf <Plug>(qf_qf_switch)
nnoremap [q <Plug>(qf_qf_next)
nnoremap ]q <Plug>(qf_qf_previous)
nmap <leader>T :TagbarToggle<CR>
nmap <Leader>di <Plug>VimspectorBalloonEval
nmap <leader>dd :call vimspector#Launch()<CR>
nmap <leader>de :VimspectorEval
nmap <leader>do :VimspectorShowOutput
nmap <leader>dw :VimspectorWatch
nmap <leader>dx :VimspectorReset<CR>
nmap <leader>y <Plug>(coc-format)
nmap <leader>n <Plug>(coc-rename)
nmap <silent> <leader>gd :call CocAction('jumpDefinition', 'edit')<CR>
nmap <silent> <leader>gi :call CocAction('jumpImplementation', 'edit')<CR>
nmap <silent> <leader>gr :call CocAction('jumpReferences', 'edit')<CR>
nmap <silent> <leader>gy :call CocAction('jumpTypeDefinition', 'edit')<CR>
nmap <silent> [n <Plug>(coc-diagnostic-prev>
nmap <silent> ]n <Plug>(coc-diagnostic-next>
nmap <silent> gd :call CocAction('jumpDefinition', 'vsplit')<CR>
nmap <silent> gi :call CocAction('jumpImplementation', 'vsplit')<CR>
nmap <silent> gr :call CocAction('jumpReferences', 'vsplit')<CR>
nmap <silent> gy :call CocAction('jumpTypeDefinition', 'vsplit')<CR>
" I'm sure ZZ is useful to someone but not me
nnoremap ZZ <Nop>
nnoremap <space> za
nnoremap <C-j> gT
nnoremap <C-k> gt
nnoremap <C-t> :tabnew<CR>
nnoremap <Down> <Nop>
nnoremap <Left> <Nop>
nnoremap <Right> <Nop>
nnoremap <Up> <Nop>
nnoremap <PageUp> <Nop>
nnoremap <PageDown> <Nop>
nnoremap <Insert> <Nop>
nnoremap <Home> <Nop>
nnoremap <End> <Nop>
nnoremap <Del> <Nop>
nnoremap <leader>gq gqip
nnoremap <silent> <leader><space> :noh<CR>
nnoremap <silent> <space>a :<C-u>CocList diagnostics<CR>
nnoremap <silent> <space>c :<C-u>CocList commands<CR>
nnoremap <silent> <space>e :<C-u>CocList extensions<CR>
nnoremap <silent> <space>f <Plug>(coc-fix-current)
nnoremap <silent> <space>j :<C-u>CocNext<CR>
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
nnoremap <silent> <space>o :<C-u>CocList outline<CR>
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
nnoremap <silent> <space>s :<C-u>CocList -I symbols<CR>
nnoremap <silent> <leader>a <Plug>(coc-codeaction-selected)
nnoremap <silent> <leader>ac <Plug>(coc-codeaction-cursor)
nnoremap <silent> <leader>as <Plug>(coc-codeaction-source)
nnoremap <silent> <leader>se <Plug>(coc-codeaction-refactor)
nnoremap <silent> <leader>s <Plug>(coc-codeaction-refactor-selected)
nnoremap <silent> <leader>cl <Plug>(coc-codelens-action)
nnoremap <silent> U :call <SID>show_documentations()<CR>
nnoremap H ^
nnoremap J }
nnoremap K {
nnoremap L $
nnoremap gj j
nnoremap gk k
nnoremap j gj
nnoremap k gk
nnoremap ntt :NERDTreeToggle<CR>
nnoremap <leader>J J
"}}}
"Visual {{{
vnoremap <leader>y :Neoformat 'full'<CR>
xmap <silent> <leader>s <Plug>(coc-codeaction-refactor-selected)
xmap <Leader>di <Plug>VimspectorBalloonEval
vmap <leader>y <Plug>(coc-format-selected)
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
"}}}
"Command {{{
cnoremap <C-j> <Down>
cnoremap <C-k> <Up>
cnoremap <C-h> <Left>
cnoremap <C-l> <Right>
cnoremap <Down> <Nop>
cnoremap <Left> <Nop>
cnoremap <Right> <Nop>
cnoremap <Up> <Nop>
cnoremap <PageUp> <Nop>
cnoremap <PageDown> <Nop>
cnoremap <Insert> <Nop>
cnoremap <Home> <Nop>
cnoremap <End> <Nop>
"}}}
"}}}
" NERDTree {{{
let NERDTreeIgnore=['\.pyc$', '\~$', '\.git$', '\.tox$', '\.cache$', '\.sw[a-z]$', 'node_modules', 'gmon.out', '.mypy_cache', '.pytest_cache', 'tags', '__pycache__']
let NERDTreeShowHidden=1
let NERDTreeUseTCD=1
let NERDTreeShowLineNumbers=1
let NERDTreeAutoDeleteBuffer=1
" }}}
"neoformat {{{
let g:neoformat_python_isort = {
\ 'exe': py3path . 'isort',
\ 'args': ['-', '--quiet'],
\ 'stdin': 1
\ }
let g:neoformat_python_black = {
\ 'exe': py3path . 'black',
\ 'args': ['-', '2>/dev/null'],
\ 'stdin': 1
\}
let g:neoformat_javascript_prettier = {
\ 'exe': 'prettier',
\ 'stdin': 1,
\ 'args': [
\ '--stdin',
\ '--single-quote',
\ '--no-bracket-spacing',
\ '--trailing-comma', 'none'
\]
\ }
let g:neoformat_typescript_prettier = {
\ 'exe': 'prettier',
\ 'stdin': 1,
\ 'args': [
\ '--stdin',
\ '--single-quote',
\ '--trailing-comma', 'none',
\ '--parser', 'typescript'
\]
\ }
let g:neoformat_yaml_pyaml = {
\ 'exe': py3interp,
\ 'args': ['-m', 'pyaml'],
\ 'stdin': 1,
\}
let g:neoformat_yaml_yamlfmt = {
\'exe': 'yamlfmt',
\'args': ['-'],
\'stdin':1,
\}
let g:neoformat_enabled_python = ['isort', 'black']
let g:neoformat_enabled_javascript = ['prettier']
let g:neoformat_enabled_typescript = ['prettier']
let g:neoformat_enabled_rust = ['rustfmt']
let g:neoformat_enabled_html = ['htmlbeautify']
let g:neoformat_enabled_go = ['gofmt']
let g:neoformat_enabled_yaml = ['yamlfmt']
let g:neoformat_run_all_formatters = 1
let g:neoformat_verbose = 0
let g:rustfmt_autosave = 1
let g:rustfmt_emit_files = 1
let g:rustfmt_fail_silently = 0
"}}}
" CtrlP/Vimgrepper Ripgrep {{{
let g:ctrlp_extensions = ['line', 'buffertag', 'tag', 'dir']
let g:ctrlp_cmd = 'CtrlPLastMode'
let g:ctrlp_show_hidden = 1
if executable('rg')
let g:ctrlp_user_command = 'rg %s --files --color=never -S --hidden -g''!.git/*'' -g''!.worktrees/*'' -g''!.worktree/*'' -g''!tags'' '
let g:ctrlp_use_caching = 0
nnoremap \ :GrepperRg<SPACE>
else
nnoremap \ :Grepper -tool grep<SPACE>
endif
"}}}
" Autocommands {{{
augroup Dockerfile
autocmd!
au BufRead,BufNewFile Dockerfile* set filetype=Dockerfile
augroup END
augroup Typescript
autocmd!
au BufRead,BufNewFile *.jsx set filetype=javascript.jsx
au BufRead,BufNewFile *.tsx set filetype=typescript.tsx
augroup END
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
augroup END
augroup Go
autocmd!
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t :GoTest!<CR>
au FileType go nmap <leader>c <Plug>(go-coverage-toggle)
au FileType go nmap <leader>e <Plug>(go-rename)
au FileType go iab iferr if err != nil {}<Up>
au FileType go nmap <Leader>a <Plug>(go-alternate-vertical)
au FileType go nmap <Leader>i :GoImport!
au FileType go nmap <Leader>I :GoImportAs!
augroup END
augroup Markdown
autocmd!
au FileType markdown nmap <leader>toc :Toc<CR>
au FileType markdown setlocal spell spelllang=en_us
augroup END
augroup Quickfix
autocmd!
au FileType qf map <buffer> <leader>d :.Reject<CR>
augroup END
augroup Nerdtree
autocmd!
au VimEnter * NERDTreeToggle
augroup END
augroup Help
autocmd!
au FileType help set nu
au FileType help set rnu
augroup END
au TabLeave * let g:lasttab = tabpagenr()
au InsertLeave,CompleteDone * if pumvisible() == 0 || pclose || endif
augroup InlineSyntax
autocmd!
autocmd Syntax * call SyntaxRange#Include('@begin=sh@', '@end=sh@', 'sh', 'NonText')
autocmd Syntax * call SyntaxRange#Include('@begin=bash@', '@end=bash@', 'bash', 'NonText')
autocmd Syntax * call SyntaxRange#Include('@begin=js@', '@end=js@', 'javascript', 'NonText')
autocmd Syntax * call SyntaxRange#Include('@begin=sql@', '@end=sql@','sql', 'NonText')
autocmd Syntax * call SyntaxRange#Include('@begin=py@', '@end=py@', 'python', 'NonText')
autocmd Syntax * call SyntaxRange#Include('@begin=go@', '@end=go@', 'go', 'NonText')
augroup END
"}}}
" Vimspector {{{
let g:vimspector_base_dir=expand('$HOME/.config/nvim/vimspector')
let g:vimspector_enable_mappings='HUMAN'
let g:vimspector_install_gadgets=['debugpy', 'CodeLLDB', 'vscode-cpptools', 'delve']
"""
"Vim Go {{{
let g:go_def_mapping_enabled = 0
"}}}
"Indents {{{
let g:indentLine_char_list = ['|', '¦', '┆', '┊']
let g:indentLine_setConceal = 0
"}}}
"Docs {{{
let g:echodoc#enable_at_startup = 1
"}}}
"Gitgutter {{{
let g:gitgutter_map_keys = 0
let g:gitgutter_use_location_list = 1
nnoremap ]h <Plug>(GitGutterNextHunk)
nnoremap [h <Plug>(GitGutterPrevHunk)
nnoremap <Leader>ghs <Plug>(GitGutterStageHunk)
nnoremap <Leader>ghu <Plug>(GitGutterUndoHunk)
nnoremap <Leader>ghp <Plug>(GitGutterPreviewHunk)
"}}}
"Submode {{{
let g:submode_always_show_submode = 1
"Window Submode {{{
" We're taking over the default <C-w> setting. Don't worry we'll do
" our best to put back the default functionality.
call submode#enter_with('window', 'n', '', '<C-w>')
" Note: <C-c> will also get you out to the mode without this mapping.
" Note: <C-[> also behaves as <ESC>
call submode#leave_with('window', 'n', '', '<ESC>')
" Go through every letter
for key in ['a','b','c','d','e','f','g','h','i','j','k','l','m',
\ 'n','o','p','q','r','s','t','u','v','w','x','y','z']
" maps lowercase, uppercase and <C-key>
call submode#map('window', 'n', '', key, '<C-w>' . key)
call submode#map('window', 'n', '', toupper(key), '<C-w>' . toupper(key))
call submode#map('window', 'n', '', '<C-' . key . '>', '<C-w>' . '<C-'.key . '>')
endfor
" Go through symbols. Sadly, '|', not supported in submode plugin.
for key in ['=','_','+','-','<','>']
call submode#map('window', 'n', '', key, '<C-w>' . key)
endfor
" Old way, just in case.
nnoremap <Leader>w <C-w>
"}}}
"}}}