-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
388 lines (337 loc) · 11.2 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
if has('python3')
endif
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')
if has("unix")
" NOTE: YCM is a PITA on windows...
Plug 'valloric/youcompleteme'
Plug 'SirVer/ultisnips'
endif
Plug 'honza/vim-snippets'
Plug 'majutsushi/tagbar'
Plug 'junegunn/vim-easy-align'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'w0rp/ale'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-dispatch'
" Plug 'airblade/vim-gitgutter'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'pangloss/vim-javascript'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'adelarsq/vim-matchit'
Plug 'jmcantrell/vim-virtualenv'
Plug 'mmarchini/bpftrace.vim'
Plug 'godlygeek/tabular'
Plug 'cdelledonne/vim-cmake'
"python folding help
Plug 'tmhedberg/SimpylFold'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
Plug 'google/yapf'
Plug 'dracula/vim', {'as':'dracula'}
" Plug 'JBakamovic/cxxd-vim'
Plug 'rust-lang/rust.vim'
Plug 'racer-rust/vim-racer'
call plug#end()
set backspace=indent,eol,start
set encoding=utf-8
set nocompatible " let vim be vim, not vi
set history=550 " have 550 lines of command-line (etc) history:
set undolevels=200 " number of commands
set hidden " dont require saving to switch buffers
set nowrap " dont wrap long lines
set shiftwidth=4 " use indents of 4 spaces,
set tabstop=4 " and have them copied down lines:
set shiftround " round indent to multiple of sw
set expandtab " use spaces instead of tabs
set autoindent " copy indent from prev line or syn
set cindent
set smarttab " smartly handle the tab/space thing
set completeopt=longest,menuone
set autowrite " auto-save when calling :make
packadd termdebug
let g:termdebug_wide=1
let mapleader = ","
let NERDSpaceDelims=1 " spaces after comment char
if has("unix")
" trailing backslash stores entire file path in backupdir
let g:my_vimrc = $HOME . "/.vim/vimrc"
let g:my_vimdir = $HOME . "/.vim"
let g:my_guifont = "Hack\\ 11"
else
" windows
let g:my_vimdir = $HOME . "/vimfiles"
let g:my_vimrc = $HOME . "/vimfiles/vimrc"
let g:my_guifont = "Hack:h11:cANSI"
endif
if has("gui_running")
set mousehide " Hide the mouse when typing text
set guioptions=
set guioptions+=c
exe "set guifont=" . g:my_guifont
let g:my_colors = 'zenburn'
elseif &t_Co == 256
let g:my_colors = 'zenburn'
else
let g:my_colors = 'desert'
endif
" augroup dracula_customize
" au!
" let g:dracula_bold = 1
" let g:dracula_underline = 1
" let g:dracula_undercurl = 1
" let g:dracula_colorterm = 0
" let g:dracula_italic = 1
" autocmd ColorScheme zenburn hi CursorLine cterm=underline term=underline
" augroup END
exe ":colorscheme" g:my_colors
" Keep working directories clutter-free
let &runtimepath=my_vimdir . "," . &runtimepath
let &backupdir=my_vimdir.'/var/backups//'
let &directory=my_vimdir.'/var/swap//'
" first list the available options and complete the longest common part
set wildmode=list:longest,full
set wildignore=*.o,*.obj,*.bak,*.exe
set sessionoptions=blank,buffers,curdir,folds,help,winsize,tabpages
set viminfo=/30,'1000,r/media,r/.gvfs,r/.ssh,f0,h,\"100,%
" search & replace
set ignorecase " make searches case-insensitive,
set smartcase " unless they contain upper-case letters:
set incsearch " show the `best match so far'
set hlsearch " set highlighted search on
" Appearance
set number
set relativenumber
set vb t_vb= " no flash
set showmatch " show matches for parens/brackets
set cmdheight=1 " command line one line high
set winminheight=0 " let windows shrink to filenames only
set showmode " display the current mode
set showcmd " and partially-typed commands in the status line:
set scrolloff=5 " keep cursor +/- 5 lines in window
set ruler " cursor pos always shown
set shortmess+=aI
set background=dark
set cursorline
let &showbreak = '> '
" " KEYS
" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <Leader>n :cnext<CR>
map <Leader>p :cnext<CR>
nnoremap <leader>a :cclose<CR>
map <silent> <Leader>c <plug>NERDCommenterToggle
map <silent> <Leader>s :call StripTrailingSpace()<CR>
map <silent> <Leader>e :TagbarToggle<CR>
nnoremap <C-l> :nohlsearch<CR><C-l>
exe 'map <Leader>b :buffer '
nnoremap <space> za
" Fixes conflict with YCM and UltiSnips
" uh, somehow i have to press ^p, then ^j... which is a PITA
let g:UltiSnipsExpandTrigger="<c-j>"
" Stop YCM asking me to load
let g:ycm_extra_conf_globlist = ['~/sandbox/*',]
" let g:ycm_autoclose_preview_window_after_insertion = 1
" let g:ycm_autoclose_preview_window_after_completion = 1
" let g:ycm_max_num_candidates = 20
" let g:ycm_max_num_identifier_candidates = 10
" let g:ycm_enable_diagnostic_signs = 1
" Make sure there is always a spot for symbols
set signcolumn=yes
" ",v ,V edit/reload vimrc
map <Leader>v :exe "sp" g:my_vimrc<CR>
map <silent> <Leader>V :exe "source" g:my_vimrc<CR>
\:filetype detect<CR>
\:exe ":echo 'vimrc reloaded'"<CR>
" " if forget to `sudo vim` a file
cmap w!! w !sudo tee % >/dev/null
" " Windows
nnoremap <C-k> <C-W>k
nnoremap <C-j> <C-W>j
map <C-m> <C-W>+
map <C-n> <C-W>-
" " tagbar
let g:tagbar_position = 'topleft vertical'
let g:tagbar_width = 30
let g:tagbar_compact = 2
" " Make shift-insert work like in Xterm
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>
" " I hate long lines
function! MyGoToLongLine()
" Helper function moves to the next long line in buffer
if exists("b:long_line")
call cursor(b:long_line, (&tw ? &tw : 80))
" unfold, then move cursor line to top of window and move back a word
norm! zv
norm! zt
norm! b
else
echo "No long lines found"
endif
endfunction
map <silent> <Leader>l :call MyGoToLongLine()<CR>
" " Filetypes
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! MyRustSettings()
set fdm=syntax
set fo+=ro fdm=indent tw=80 iskeyword+=35 nowrap
endfunction
function! MyCSettings()
set fo+=ro fdm=syntax tw=80 iskeyword+=35 nowrap
set colorcolumn=80
highlight ColorColumn ctermbg=darkgray
let &path.="src,include,lib"
let c_comment_strings = 1 " strings inside C comments
" syn match matchName /\(#define\)\@<= .*\(\\$\)\=\_.*/
" call LoadTypesHilights()
endfunction
function! MyPythonSettings()
let python_fold = 1
let python_highlight_all = 1
set fo+=ro fdm=indent tw=79 iskeyword+=35 nowrap
let g:SimpylFold_docstring_preview=1
endfunction
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
function! MyGoSettings()
" Go uses tabs for indentation
" set fo+=ro fdm=syntax tw=79 nowrap ts=4 sw=4 noet
set fo+=ro fdm=syntax tw=79 nowrap sw=4 noet
setlocal ts=4 sts=4
" trying to fix gofmt folding
let g:go_fmt_experimental = 1
" clean up imports when formatting
let g:go_fmt_command = "goimports"
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
" golang keys
map <Leader>t :GoTest<CR>
nmap <leader>m :<C-u>call <SID>build_go_files()<CR>
nmap <leader>r :GoRun<CR>
endfunction
augroup ftypes
au!
filetype on
filetype plugin on
filetype plugin indent on
au FileType * set fo-=l et ts=8 sw=4 sts=4
au BufRead,BufNewFile *.lua.in set ft=lua
au FileType rust call MyRustSettings()
au FileType make set noet sw=8 ts=8 fdm=indent tw=80
au FileType basic,lua,vim,zsh,sh,java
\ set formatoptions+=ro fdm=indent tw=80
au FileType c,cpp call MyCSettings()
au FileType python call MyPythonSettings()
au FileType go call MyGoSettings()
au BufRead,BufNewFile *.go call MyGoSettings()
au BufRead,BufNewFile *.js,*.html,*.css
\ set tabstop=2 softtabstop=2 shiftwidth=2
au BufRead,BufNewFile *.txt set ft=text tw=72
au BufRead,BufNewFile *.md set ft=markdown sw=2 tw=72
au BufRead,BufNewFile CMakeLists.txt set ft=cmake nowrap
au FileType text set tw=0 linebreak wrap
" git TAG descriptions are recognized as 'conf' files.. :S
au BufRead,BufNewFile .git/TAG* set ft=gitcommit
au FileType gitcommit call setpos('.', [0, 1, 1, 0])
au FileType gitcommit,mail set tw=72 nofoldenable
let perl_fold = 1
let lua_fold = 1
let lua_version = 5
let lua_subversion = 1
let g:is_bash = 1
let g:sh_fold_enabled = 7 " allow all folds in bash
augroup END
" augroup remember_folds
" autocmd!
" autocmd BufWinLeave ?* mkview | filetype detect
" autocmd BufWinEnter ?* silent loadview | filetype detect
" augroup END
" " Status line
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:airline_theme='zenburn'
let g:airline#extensions#tabline#enabled = 1
function! StripTrailingSpace()
"remove all trailing whitespace from buffer
if search('\s\+$', 'nw') != 0
norm! mZ
exe '%s:\s\+$::'
norm! 'Z
endif
endfunction
function! s:LongLines()
"return a list containing the lengths of the long lines in this buffer
let threshold = (&tw ? &tw : 80)
let spaces = repeat(" ", &ts)
let long_line_lens = []
if exists("b:long_line")
unlet b:long_line
endif
let i = 1
while i <= line("$")
let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
if len > threshold
if !exists("b:long_line")
"push the first line as the next bad line
let b:long_line = i
endif
call add(long_line_lens, len)
endif
let i += 1
endwhile
return long_line_lens
endfunction
" controls the output of longline functions
let g:SL_LongLine_Verbose=1
" Golang
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:ale_linters = {
\ 'python': ['pylint', 'flake8', 'jedi'],
\ 'javascript': ['eslint'],
\}
nnoremap <C-p> :Files<cr>
" Vim dispatch for builds using cmake
" Open vim-dispatch window and scroll to bottom
nnoremap <C-m>m :Copen<CR> <bar> G
" Build debug and release targets
nnoremap <C-m>bd :Dispatch! make -C build/Debug<CR>
nnoremap <C-m>br :Dispatch! make -C build/Release<CR>