-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.vim
559 lines (492 loc) · 15.1 KB
/
main.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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
set nocompatible
set mouse=a
set nomousehide
set autoread
set foldlevelstart=99
set colorcolumn=120
set updatetime=300
set signcolumn=auto
" for some reason...much better performance
set guicursor=
syntax on
filetype plugin indent on
" statusbar, tabline
set laststatus=2
set showtabline=2
" prefer text tabs instead of gui
set guioptions-=e
" show cursorline
set cursorline
" slightly more normal leader
let mapleader = ','
" prefer vertical split while diffing
set diffopt+=vertical
" use system clipboard
if has('unnamedplus')
set clipboard=unnamedplus,unnamed
else
set clipboard=unnamed
endif
" context scroll
set scrolloff=3
set sidescrolloff=5
" relative line numbers
set relativenumber number
" enable smartcase search
set ignorecase
set smartcase
" automatically reload config when saving it
augroup myvimrc
au!
au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc,main.vim source $MYVIMRC
augroup END
" forgot sudo...
cmap w!! w !sudo tee >/dev/null %
" normal backspace
set backspace=indent,eol,start
" close all sidebars if they are the last window in a tab
source ~/.vim/repo/sidebars.vim
" must be defined before the plug#begin below
let g:coc_global_extensions = [
\ 'coc-css',
\ 'coc-docker',
\ 'coc-html',
\ 'coc-json',
\ 'coc-pyright',
\ 'coc-sh',
\ 'coc-snippets',
\ 'coc-sql',
\ 'coc-vimlsp',
\ 'coc-yaml',
\ ]
call plug#begin('~/.vim/plugged')
" dependencies
Plug 'kana/vim-textobj-entire'
Plug 'kana/vim-textobj-line'
Plug 'kana/vim-textobj-user'
Plug 'xolox/vim-misc'
" essentials
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'AndrewRadev/splitjoin.vim'
Plug 'bling/vim-airline'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'dkprice/vim-easygrep'
Plug 'dsimidzija/vim-nerdtree-ignore'
"Plug 'jistr/vim-nerdtree-tabs'
Plug 'Lokaltog/vim-easymotion'
Plug 'preservim/nerdcommenter'
Plug 'preservim/nerdtree'
Plug 'Raimondi/delimitMate'
Plug 'scrooloose/syntastic'
Plug 'Shougo/context_filetype.vim'
Plug 'SirVer/ultisnips'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-sleuth'
Plug 'tpope/vim-surround'
Plug 'xolox/vim-session'
Plug 'moll/vim-bbye'
Plug 'ntpeters/vim-better-whitespace'
Plug 'skammer/vim-css-color'
Plug 'xolox/vim-easytags'
Plug 'terryma/vim-expand-region'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'groenewege/vim-less'
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Plug 'milkypostman/vim-togglelist'
Plug 'nelstrom/vim-visual-star-search'
Plug 'wesQ3/vim-windowswap'
Plug 'sheerun/vim-polyglot'
Plug 'dhruvasagar/vim-table-mode'
Plug 'mattn/emmet-vim'
Plug 'jmcantrell/vim-virtualenv'
Plug 'maralla/validator.vim'
Plug 'majutsushi/tagbar'
Plug 'wfxr/minimap.vim'
Plug 'bfrg/vim-jqplay'
" filetypes & frameworks
Plug 'python-mode/python-mode'
Plug 'tpope/vim-rails'
Plug 'andrewstuart/vim-kubernetes'
Plug 'briancollins/vim-jst'
Plug 'chrisbra/csv.vim'
Plug 'duganchen/vim-soy'
Plug 'evidens/vim-twig'
Plug 'hashivim/vim-terraform'
Plug 'mustache/vim-mustache-handlebars'
"Plug 'vim-pandoc/vim-pandoc'
Plug 'vim-pandoc/vim-pandoc-syntax'
" git
Plug 'airblade/vim-gitgutter'
Plug 'int3/vim-extradite'
Plug 'junegunn/gv.vim'
Plug 'rhysd/git-messenger.vim'
Plug 'tpope/vim-fugitive'
"Plug 'Xuyuanp/nerdtree-git-plugin'
" unused ATM
"Plug 'kchmck/vim-coffee-script'
"Plug 'ryanoasis/vim-devicons' " killing performance with constant refreshes
"Plug 'shawncplus/phpcomplete.vim'
"Plug 'vim-php/phpctags'
"Plug 'vim-php/tagbar-phpctags.vim'
"Plug 'vitalk/vim-simple-todo'
" colorschemes
Plug 'vim-airline/vim-airline-themes'
Plug 'altercation/vim-colors-solarized'
Plug 'HenryNewcomer/vim-theme-papaya'
Plug 'whatyouhide/vim-gotham'
Plug 'dracula/vim'
Plug 'morhetz/gruvbox'
Plug 'cocopon/iceberg.vim'
Plug 'ayu-theme/ayu-vim'
Plug 'arcticicestudio/nord-vim'
Plug 'nanotech/jellybeans.vim'
Plug 'bluz71/vim-nightfly-guicolors'
call plug#end()
" keys
" BEGIN: coc-nvim tab completion
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
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>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice.
inoremap <silent><expr> <CR>
\ coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" END: coc-nvim tab completion
inoremap <silent><expr> <c-k> coc#refresh()
nnoremap <silent> <c-f> :call <SID>show_documentation()<CR>
nmap <silent> <leader>g <Plug>(coc-definition)
nmap <silent> <leader>r <Plug>(coc-references)
nmap <silent> <leader>rn <Plug>(coc-rename)
"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)
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" BEGIN: fugitive
nnoremap <leader>G :tab G<CR>
" END: fugitive
nnoremap <leader>n :NERDTreeTabsToggle<CR>
nnoremap <F1> <nop>
inoremap <F1> <nop>
vnoremap <F1> <nop>
nnoremap <F3> :Git<CR>
nnoremap <F10> :GrepOptions<CR>
nnoremap <F11> :tabdo :windo lcl\|ccl<CR>
nnoremap <F12> :set hlsearch!<CR>:set hlsearch?<CR>
" use tab to find file in nerdtree, and tab again to close nerdtree
"nnoremap <S-Tab> :NERDTreeToggle<CR>
nnoremap <S-Tab> :NERDTreeFind<CR>
"autocmd FileType nerdtree nnoremap <buffer> <Tab> :NERDTreeClose<CR>
autocmd FileType nerdtree nnoremap <buffer> <S-Tab> :NERDTreeClose<CR>
" delete buffer to clean up the active session
nnoremap <leader>qq :Bdelete<CR>
nnoremap <leader>QQ :bufdo :Bdelete<CR>
" vim very magic regex
nnoremap / /\v
vnoremap / /\v
" CRO keyboard layout easier search
nmap _ /
vmap _ /
" shortcircuit esc
inoremap <silent> jj <ESC>
" move around windows
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" easy tab navigation
map <S-H> gT
map <S-L> gt
" fix wrapped lines up/down navigation
noremap j gj
noremap k gk
" visual shifting
vnoremap < <gv
vnoremap > >gv
" faster selection
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" fix syntax highlighting
nnoremap <F5> :syntax sync fromstart<CR>
inoremap <F5> <C-o>:syntax sync fromstart<CR>
nnoremap <C-g> <C-]> " go to tag, work around ] in shortcut
" replace currently selected text with default register without yanking it
vnoremap p "0p
vnoremap P "0P
" move visual block
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" easy ymd
imap <Leader>ymd <C-R>=strftime("%Y-%m-%d")<CR>
" quickfix open in new tab
autocmd FileType qf nnoremap <buffer> <C-t> <C-w><CR><C-w>T
" quickfix close on enter (EasyGrep used to do this automatically)
autocmd FileType qf nnoremap <buffer> <CR> <CR>:cclose<CR>
" easygrep
nnoremap <C-e> :copen<CR>
" quick way to add blank lines
nnoremap <silent><A-j> :set paste<CR>m`o<Esc>``:set nopaste<CR>
nnoremap <silent><A-k> :set paste<CR>m`O<Esc>``:set nopaste<CR>
" surround shortcuts
nmap ` ysiw`
" toggle tagbar
nmap <leader>t :TagbarToggle<CR>
nnoremap <leader>m :MinimapToggle<CR>
" don't show trailing whitespace for minimap buffer
autocmd FileType minimap DisableWhitespace
" easygrep
let g:EasyGrepCommand = 1
let g:EasyGrepEveryMatch = 0
let g:EasyGrepJumpToMatch = 0
let g:EasyGrepOpenWindowOnMatch = 1
let g:EasyGrepRecursive = 1
let g:EasyGrepFilesToExclude=".svn,.git,.vimtags,tags,*.sw?,*.egg-info,node_modules,bower_components,*.py.orig,*.js.map,*.apib,htmlcov,_build,build"
let g:EasyGrepSearchCurrentBufferDir = 0 " not very good when you have a file open in ~
let g:EasyGrepWindow = 0 " for compatibility with syntastic, see :h syntastic-easygrep
" nerdtree + vim-session workaround
let g:nerdtree_tabs_open_on_gui_startup = 0
let g:nerdtree_tabs_open_on_new_tab = 0
let g:nerdtree_tabs_focus_on_files = 1
" double click folder opening
let g:NERDTreeMouseMode = 1
" chdir vim when nerdtree is chdir'd
let g:NERDTreeChDirMode = 2
let g:NERDTreeShowLineNumbers = 1
" NERDCommenter
let g:NERDDefaultAlign = 'left'
" gui font...
if has('gui_running')
"set guifont=Hack\ 13
set guifont=Fira\ Code\ 14 " ttf-fira-code
"set guifont=DejaVuSansMono\ Nerd\ Font\ Mono\ 14
endif
set expandtab
set tabstop=4
set shiftwidth=4
" feck off with the fast and incorrect typing
command! W w
command! Q q
command! Qa qa
command! QA qa
command! Wq wq
command! WQ wq
command! Wa wa
command! WA wa
command! -complete=file -nargs=* Tabe tabe <args>
" edit config in a new tab
command! Conf tabnew ~/.vim/repo/main.vim
" edit snippet in a new tab
command! -nargs=1 Snip tabnew ~/.vim/repo/snippets/<args>.snippets
" leave only current buffer open
command! Only silent! execute "%bd|e#|bd#"
" vim-session
set sessionoptions-=help,options,blank,minimap,nerdtree
let g:session_autoload = 'no'
let g:session_autosave = 'yes'
if !has('gui_running')
let g:session_default_name = 'console'
endif
if isdirectory($HOME.'/work/projects')
let g:sessions_project_path = '$HOME/work/projects'
endif
let s:hostname = substitute(system('hostname'), '\n', '', '')
if s:hostname == "NEMATODA"
" workaround for the idiotic DELL XPS keyboard layout
noremap <PageUp> <nop>
noremap <PageDown> <nop>
endif
" airline
if has('gui_running')
let g:airline_powerline_fonts = 1
endif
"let g:airline_theme = 'powerlineish'
let g:airline_theme = 'cool'
let g:airline#extensions#virtualenv#enabled = 1
" easytags / tagbar / coffeetags
set tags=./.vimtags;/,vimtags;/,./tags;/,tags;/,~/.vimtags
"let g:tagbar_phpctags_bin='$HOME/.vim/bundle/phpctags/phpctags'
let g:easytags_suppress_ctags_warning = 1
let g:easytags_async = 1
let g:easytags_auto_highlight = 0
let g:easytags_dynamic_files = 1
let g:CoffeeAutoTagFile = '.vimtags'
let g:CoffeeAutoTagIncludeVars = 0
" UltiSnips
let g:UltiSnipsSnippetDirectories=[$HOME.'/.vim/repo/snippets']
let g:UltiSnipsExpandTrigger="<s-cr>"
let g:UltiSnipsListSnippets="<c-s-cr>"
let g:UltiSnipsJumpForwardTrigger="<c-k>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
" iterm workaround
imap ✠ <s-cr>
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
"autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType javascript setlocal omnifunc=tern#Complete
"autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" phpcomplete
let g:phpcomplete_mappings = {
\ 'jump_to_def': ',g',
\ }
" vim-better-whitespace
" ask on stack how to call ToggleStripWhitespaceOnSave for all buffers
" syntastic
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 0
let g:syntastic_mode_map = {'mode':'passive'}
let g:syntastic_javascript_checkers = ['jshint']
let g:syntastic_python_checkers = ['pylint']
nnoremap <C-w>e :SyntasticCheck<CR>
nnoremap <C-w>f :SyntasticToggleMode<CR>
" vim-gitgutter
highlight clear SignColumn
highlight GitGutterAdd ctermfg=green guifg=darkgreen
highlight GitGutterChange ctermfg=yellow guifg=darkyellow
highlight GitGutterDelete ctermfg=red guifg=darkred
highlight GitGutterChangeDelete ctermfg=yellow guifg=darkyellow
" CtrlP stuff
let g:ctrlp_by_filename = 1
let g:ctrlp_max_files = 0
let g:ctrlp_use_caching = 0
let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:15,results:15'
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
\ },
\ 'fallback': 'find %s -type f'
\ }
" easymotion highlight colors
highlight link EasyMotionTarget Search
highlight link EasyMotionTarget2First Search
highlight link EasyMotionTarget2Second Search
highlight link EasyMotionShade Comment
" annoying piece of shite
autocmd FileType soy setlocal foldmethod=manual
" gitv
autocmd FileType git setlocal foldmethod=manual
" fixes window movement keys with gitv
let g:Gitv_DoNotMapCtrlKey = 1
" git messenger issue: https://github.com/rhysd/git-messenger.vim/issues/54
let g:git_messenger_always_into_popup = v:true
let g:git_messenger_include_diff = "current"
" vim-extradite
let g:extradite_resize = 0
" syntastic keeps showing this stuping message for <% end %> erb
let g:syntastic_eruby_ruby_quiet_messages =
\ {'regex': 'possibly useless use of a variable in void context'}
" validator
let g:validator_python_checkers = ["flake8"]
let g:validator_permament_sign = 1
function! s:ChangeVirtualenv()
:py3 <<EOF
import os
import vim
cwd = vim.eval("getcwd()")
activate_this = os.path.join(cwd, ".venv", "bin", "activate_this.py")
if os.path.exists(activate_this):
with open(activate_this) as f:
exec(f.read(), {'__file__': activate_this})
print(f"Switched virtualenv to {cwd}")
EOF
endfunction
augroup virtualenv
autocmd!
autocmd DirChanged * call s:ChangeVirtualenv()
augroup end
let g:python_highlight_all=1
source ~/.vim/repo/python.vim
let g:pymode_lint = 0
let g:pymode_folding = 0
let g:pymode_rope = 0
let g:pymode_options_max_line_length = 120
let g:pymode_virtualenv = 1
let g:pymode_run = 0
" pandoc + pandoc markdown
let g:pandoc#modules#disabled = ["formatting", "folding", "bibliographies"]
let g:pandoc#formatting#mode = "hA"
let g:pandoc#filetypes#pandoc_markdown = 0
" used to format json in a buffer, as dumped by python in terminal
function! JsonF()
%s/'/"/ge
%s/\vDecimal\("([0-9.]+)"\)/\1/ge
%!python -m json.tool --sort-keys
endfunction
command! Json call JsonF()
" same as above, but for XML
com! Xml :%!python3 -c "import xml.dom.minidom, sys; print(xml.dom.minidom.parse(sys.stdin).toprettyxml())"
function! ScratchCurrentBuffer(name)
set noswapfile
setlocal buftype=nofile
" runs file value_of_a:name
execute 'file' a:name
endfunction
function! ScratchF()
tabe
silent call ScratchCurrentBuffer("scratch")
endfunction
command! Scratch call ScratchF()
nnoremap <silent> <leader>s :Scratch<CR>
function! QuickDiffF()
" open a new tab, vertical split
" run scratch+diffthis on both buffers
" close entire tab with <leader>d
tabe
silent call ScratchCurrentBuffer("diff-right")
nnoremap <buffer> <leader>d :tabclose<CR>
diffthis
vsp
enew
silent call ScratchCurrentBuffer("diff-left")
nnoremap <buffer> <leader>d :tabclose<CR>
diffthis
normal <ctrl-h>
endfunction
command! QuickDiff call QuickDiffF()
nnoremap <silent> <leader>d :QuickDiff<CR>
" enable external .vimrc
"set exrc
"set secure
" colour scheme
if &background != 'dark'
set background=dark
endif
if !has('gui_running')
let g:solarized_termcolors = 256
endif
let g:solarized_italic=0
let ayucolor="dark"
let g:gruvbox_contrast_dark = 'hard'
let g:current_colorscheme = 'gruvbox'
"colorscheme solarized
"colorscheme papaya
"colorscheme dracula
"colorscheme gruvbox
"colorscheme gotham
"colorscheme iceberg
"colorscheme ayu " missing tabs
"colorscheme nord
"colorscheme jellybeans " missing tabs
"colorscheme nightfly
if !exists('g:colors_name') || g:colors_name != g:current_colorscheme
exec 'colorscheme' g:current_colorscheme
endif
" gnome terminal needs this for some reason, colorscheme destroys the
" background
"if &background != 'dark'
" set background=dark
"endif