-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
430 lines (341 loc) · 13 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
"*****
"** Thank you Mister Conway, http://tinyurl.com/IBV2013
"** Also I never forget the folks at http://www.vimbits.com/
"** /r/vim gave me a number of tips.
"** The newest tips came from Amir Salihefendic ( http://amix.dk/vim/vimrc.html )
"*****
"====[ Function Keys ]=======
"<F1>
"<F2>
"<F3>
"<F4>
"<F5> Undotree
"<F6>
"<F7> TagList
"<F8>
"<F9>
"<F10>
"<F11>
"<F12> Todo list
" Todo; Add ctags
"====[ Init Stuff ]======
" No things for vim-tiny or vim-small
if !1 | finish | endif
if has('vim_starting')
if $compatible
set nocompatible " No vi.
endif
endif
let g:isunix = 1
if has("win32") || has("win16")
let g:isunix = 0
endif
"====[ Plug Plugins ]=============
let iCanHazPlugz=1
let plugsrc=expand('~/.vim/autoload/plug.vim')
if !filereadable(plugsrc)
let iCanHazPlugz=0
if g:isunix==1
silent !executable('curl') -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
else
endif
if iCanHazPlugz==1
call PlugInstall
endif
endif
call plug#begin()
" Empower VIM
" Core Plugins
" Git plugin
Plug 'tpope/vim-fugitive'
" Visualize the undo tree
Plug 'mbbill/undotree'
" Pretty colours
Plug 'vim-scripts/darkspectrum'
" Awesome search
Plug 'kien/ctrlp.vim'
" Fix Whitespaces
Plug 'bronson/vim-trailing-whitespace'
" Better CtrlP stuff
Plug 'tacahiroy/ctrlp-funky'
" Visualize Marks
Plug 'kshenoy/vim-signature'
" Vim File Manager
Plug 'tpope/vim-vinegar'
" Fancy Startpage, to easily reach for deep files.
Plug 'mhinz/vim-startify'
" Easy tabs completions
Plug 'ervandew/supertab'
" Better TagBar
Plug 'majutsushi/tagbar'
" Fixme list
Plug 'vim-scripts/TaskList.vim'
" Markdown Writing
Plug 'gabrielelana/vim-markdown'
" Bloat for other addons
Plug 'tomtom/tlib_vim'
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'xolox/vim-misc'
Plug 'roxma/nvim-yarp'
" Language Specific
" LSP Support
Plug 'prabirshrestha/vim-lsp'
" Snort Support
Plug 'sploit/snort-vim'
" Python Support
Plug 'davidhalter/jedi-vim'
call plug#end()
let g:deoplete#enable_at_startup = 1 " Auto Complete
filetype plugin indent on
if v:version > 799
packadd termdebug " Terminal Debugger
endif
"====[ Generic Source Code Editing ]====================
" Auto Change to the directory of the edited file.
autocmd BufEnter * silent! lcd %:p:h
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = "\<Space>"
let g:mapleader = "\<Space>"
set clipboard+=unnamed " Sane default
set expandtab " Spaces instead of tabs
set title " Keep our terminals sane
set autoread " Auto read changed files, I can handle it
set hidden " Unsaved background buffers can be undo'd
set hlsearch " Hilight search
set incsearch " Increase Search
set linebreak " No word breaking
set mouse=a " Enable Mouse-Support
set number " Show number -- Hybrid mode
set relativenumber " Show Relative numbers
set shiftwidth=4 " Assume tab with of 4
set tabstop=4 " Assume tab with of 4
set nofoldenable " We hate folding
set directory^=$HOME/.vim/tmp/ " Dont make a mess out of my filesystem
set complete=.,w,b,u,t,i " Vim can help me being less dyslectic
set background=dark " Dark Background
syntax on
color darkspectrum " Pretty Colours
"====[ Language Servers ]=======
if executable('clangd')
au User lsp_setup call lsp#register_server({
\ 'name': 'clangd',
\ 'cmd': {server_info->['clangd']},
\ 'alloclist': ['cpp', 'cc', 'h'],
\})
endif
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
let g:lsp_format_sync_timeout = 1000
autocmd! BufWritePre *.cpp,*.cc,*.h call execute('LspDocumentFormatSync')
endfunction
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
"====[ WildIgnore. ]============
set wildignore =.* " Ignore dot files
set wildignore+=*.o,*.obj,*.pyc " Ignore objects
set wildignore+=.git,.hg.svn " Ignore repos
set wildignore+=*.png,*.jpg,*.gif " We don't need images in vim.
"====[ Make the status line do something useful. ]====================
set statusline=%t\ "tail of the filename
" set statusline+=\ %{LinterStatus()} "Syntax Error
set statusline+=\ \ %{FugitiveHead(5)}\ "Show the current git branch
set statusline+=%{IsPasteMode()} "show pastemode state
if v:version < 800 "Warn me when I use old stuff
set statusline+=[Outdated\ :\
set statusline+=%{v:version}
set statusline+=\ ]
endif
if !has('python3') || !has('terminal') || !has('job')
set statusline+=[Not\ Found\ :\ "
if !has('python3')
set statusline+=Python\ 3\ "
endif
if !has('terminal')
set statusline+=Terminal\ "
endif
if !has('job')
set statusline+=Job\ "
endif
set statusline+=]
endif
set statusline+=%= "left/right separator
set statusline+=[Line:%l/%L\ | "cursor line/total lines
set statusline+=Col:%c]\ "cursor column
set statusline+=<%H "help file flag
set statusline+=%M "modified flag
set statusline+=%R>\ "read only flag
set statusline+=[%{strlen(&fenc)?&fenc:'none'}, "file encoding
set statusline+=%{&ff}] "file format
set statusline+=%y "filetype
set laststatus=2
"====[ Startify ]================
let g:startify_session_dir = '~/.vim/session'
"====[ Make the 81st column of wide lines stand out.. ]====================
let colorcolumn=150
hi ColorColumn guibg=#272727 ctermbg=0
"====[ Less Aggressive spell checking ]====================
highlight clear SpellBad
highlight SpellBad cterm=underline ctermfg=red
highlight SpellBad gui=undercurl,bold
"====[ Make tabs, trailing whitespace, and non-breaking spaces visible ]======
exec "set listchars=tab:\uA6\\ ,trail:\uAF,nbsp:~"
set list
"====[ Todo list ]====
let g:tlTokenList = ['Todo', 'TODO', 'FixMe']
let g:tlWindowPosition = 1
map <F12> <Plug>TaskList
"====[ Swap v and CTRL-V, because Block mode is more useful that Visual mode " ]=
nnoremap v <C-V>
nnoremap <C-V> v
vnoremap v <C-V>
vnoremap <C-V> v
"====[ Open any file with a pre-existing swapfile in readonly mode "]=========
augroup NoSimultaneousEdits
autocmd!
autocmd SwapExists * let v:swapchoice = 'o'
autocmd SwapExists * echo 'Duplicate edit session (readonly)'
autocmd SwapExists * echohl None
autocmd SwapExists * sleep 1
augroup END
"====[ Ctrl-P ]====
nnoremap <Leader>fu :CtrlPFunky<Cr>
let g:ctrlp_cmd = 'CtrlPMixed'
let g:ctrlp_funky_syntax_highlight = 1
"The Silver Searcher
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
"====[ TagList ]=====
let g:tagbar_ctags_bin=executable('ctags')
" let Tlist_Ctags_Cmd='/usr/bin/ctags'
" let Tlist_GainFocus_On_ToggleOpen = 1
" let Tlist_Close_On_Select = 1
" let Tlist_Use_Right_Window = 1
" let Tlist_File_Fold_Auto_Close = 1
" " ToDo: Something like :TlistAddFilesRecursive {directory} [ {pattern} ]
nmap <F7> :TagbarToggle<CR>
"====[ Spell Checking ]===
let b:myLang=0
let g:myLangList=["nospell", "en_US", "nl"]
function! ToggleSpell()
if !exists(b:myLang)
let b:myLang=0
endif
let b:myLang=b:myLang+1
if b:myLang>=len(g:myLangList)
let b:myLang=0
endif
if b:myLang==0
setlocal nospell
else
"execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
execute "set spelllang=".get(g:myLangList, b:myLang)
endif
echo "spell checking language:" g:myLangList[b:myLang]
endfunction
map <leader>st :call ToggleSpell()<CR>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
"===[ GUI stuff ]===
if has('gui_running')
" Remove bloat
" Todo; remove items from menu
set mousemodel=popup " Allow Modern mouse usage.
set guioptions+=m " Use menubar
" set guioptions+=c " Remove pop-ups and use console like stuff
set guioptions-=T " Remove Toolbar
set guioptions-=r " Remove right-scrollbar
set guioptions-=L " Remove left-scrollbar
" let font_choice_one = DejaVu\ Sans\ Mono\ 10
" let font_choice_two = Hack\ Regular\ 10
" " Maybe add Gohu?
"set guifont=Hack\ Regular\ 10
set guifont=Hack:h12:cANSI:qDRAFT
let s:pattern = '^\(.* \)\([1-9][0-9]*\)$'
let s:minfontsize = 6
let s:maxfontsize = 64
function! AdjustFontSize(amount)
let fontname = substitute(&guifont, s:pattern, '\1', '')
let cursize = substitute(&guifont, s:pattern, '\2', '')
let newsize = cursize + a:amount
if (newsize >= s:minfontsize) && (newsize <= s:maxfontsize)
let newfont = fontname . newsize
let &guifont = newfont
endif
endfunction
function! LargerFont()
call AdjustFontSize(1)
endfunction
command! LargerFont call LargerFont()
function! SmallerFont()
call AdjustFontSize(-1)
endfunction
command! SmallerFont call SmallerFont()
map <S-Up> :LargerFont<cr>
map <S-Down> :SmallerFont<cr>
" Todo; add scoll wheel support.
endif
"====[ Compile YCM ]====
function! CompileYouCompleteMe()
!~/.vim/plugged/YouCompleteMe/install.py --clang-completer
endfunction
"====[ Undo Tree ]===
if has('persistent_undo')
silent !mkdir -p ~/.vim/undodir/
set undodir='~/.vim/undodir/'
endif
nnoremap <F5> :UndotreeToggle<cr>
" Todo; test this again.
"====[ File Type Settings ]===
" This is what PEP8 wants.
autocmd Filetype python set smartindent tabstop=4 shiftwidth=4 expandtab
" This is for the C-Things..
autocmd Filetype c set smartindent tabstop=8 shiftwidth=8 noexpandtab
autocmd Filetype cpp set smartindent tabstop=8 shiftwidth=8 noexpandtab
autocmd Filetype asm set smartindent tabstop=8 shiftwidth=8 noexpandtab
autocmd Filetype s set smartindent tabstop=8 shiftwidth=8 noexpandtab
" Tex friendly
autocmd Filetype tex set tabstop=2 softtabstop=2 shiftwidth=2 expandtab shiftround smarttab spell spelllang=en_gb
"autocmd FileType tex setlocal foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*%'
" Research
au! BufRead,BufNewFile *.markdown set filetype=mkd
au! BufRead,BufNewFile *.md set filetype=mkd syntax=markdown colorcolumn=125
au! BufRead,BufNewFile *.snort set syntax=hog
autocmd Filetype md set tabstop=4 softtabstop=4 shiftwidth=3 shiftround smarttab spell spelllang=en_gb noshowmode noshowcmd scrolloff=999
"====[ Remaps ]===
" Really annoying Ex-mode
nnoremap Q <nop>
" sudo Write
cmap w!! %!sudo tee > /dev/null %
" Easy paste
if has("gui_running")
map <silent> <S-Insert> "+p
imap <silent> <S-Insert> <Esc>"+pa
endif
"===[ Custom Functions ]===
function! IsPasteMode()
if &paste
return '[PASTE MODE]'
endif
return ''
endfunction
"====[ From VIM-Sensible ]====
set nrformats-=octal
if &encoding ==# 'latin1' && has('gui_running')
set encoding=utf-8
endif
if v:version > 703 || v:version == 703 && has("patch541")
set formatoptions+=j " Delete comment character when joining commented lines
endif