-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
386 lines (314 loc) · 12.6 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
set nocompatible " be iMproved
" ====================================
" First time load, install plugins
" ====================================
if empty(glob("~/.vim/autoload/plug.vim"))
if executable('git')
execute('!mkdir -p ~/.vim/{autoload,undo,swap} && curl -sfLo ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim && vim +PlugInstall +qall')
else
echom "Please install git to allow plugin configuration through vim-plug"
endif
endif
" ====================================
" Plugin Management with vim-plug
" ====================================
call plug#begin()
" Appearance
Plug 'vim-airline/vim-airline' " Status bar for vim
Plug 'vim-airline/vim-airline-themes' " Status bar colors
Plug 'joshdick/onedark.vim' " Colour scheme (One Dark)
Plug 'ryanoasis/vim-devicons' " Add file type icons to vim plugins: NERDTree, vim-airline
Plug 'nathanaelkane/vim-indent-guides' " Show indent guides
Plug 'kshenoy/vim-signature' " Show marks beside line numbers
" Utility
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " Fuzzy finder
Plug 'scrooloose/nerdtree' " File explorer
Plug 'Xuyuanp/nerdtree-git-plugin' " Git status symbols in NERDTree
Plug 'majutsushi/tagbar' " Code navigation
Plug 'tpope/vim-fugitive' " Git plugin
Plug 'christoomey/vim-tmux-navigator' " Navigate seamlessly between vim and tmux splits
" Shortcuts
"Plug 'vim-scripts/DrawIt' " Ascii drawing plugin
Plug 'tpope/vim-commentary' " Comment out lines
Plug 'tpope/vim-surround' " Add quotes/parentheses
Plug 'tpope/vim-repeat' " Enable repeating supported plugin maps with '.'
" Generic programming
Plug 'sheerun/vim-polyglot' " Syntax highlighting
"Plug 'Valloric/YouCompleteMe' " Powerful code completion engine
Plug 'vim-syntastic/syntastic' " Python linter
" Markdown
Plug 'tpope/vim-markdown' " Markdown runtime files
Plug 'jtratner/vim-flavored-markdown' " Enable GitHub-flavoured Markdown
call plug#end()
" ====================================
" vim Configuration
" ====================================
" Basic config: line numbers, no line wrap, highlight incremental search,
" remap escape key. Quick config if no .vimrc:
" colo desert |set nu|set nowrap|set hls|set is|inoremap jk <esc>
" With 4 space tabs:
" colo desert |set nu|set et|set ts=4|set sw=4|set ci|set ai|set nowrap|set hls|set is|inoremap jk <esc>
set nu
set nowrap
set hlsearch
set incsearch
inoremap jk <esc>
" Identation
set expandtab
set tabstop=4
set shiftwidth=4
set cindent
set autoindent
filetype indent on
autocmd FileType make set noexpandtab
autocmd BufRead,BufNewFile *.html,*.php,*.yaml setl sw=2 sts=2 et foldmethod=indent
autocmd BufRead,BufNewFile *.c,*.cpp,*.h setl sw=4 sts=4 et
" color theme
syntax enable
set background=dark
if filereadable(expand("~/.vimrc_background"))
let base16colorspace=256
source ~/.vimrc_background
else
let g:onedark_termcolors = 256
let g:onedark_terminal_italics = 1
colorscheme onedark
endif
if &term =~ '256color'
" disable Background Color Erase (BCE)
set t_ut=
endif
" Indicates a fast terminal connection. More characters will be sent to the
" screen for redrawing
set ttyfast
" End-of-line options
set fileformats=unix,dos
" struct member autocomple, c only, if YCM is not used
set omnifunc=ccomplete#Complete
" Show more information while completing tags.
set showfulltag
" Always show status line
set laststatus=2
" mode is shown in the status line
set noshowmode
" Open splits more naturally
set splitright
" Show invisible chars (eol, tabs, trailing space)
"set list
set listchars=eol:$,tab:▸-,trail:·,extends:↷,precedes:↶,nbsp:•
" Use an undo file and set a directory to store the undo history
set undofile
set undodir=~/.vim/undo/
" put swap files in common dir
set backupdir=~/.vim/swap//,.,/tmp
set directory=~/.vim/swap//,.,/tmp
" automatically create folds, open all folds
set foldmethod=syntax
set foldlevelstart=99
" any buffer can be hidden (keeping its changes) without first writing the
" buffer to a file. This affects all commands and all buffers.
set hidden
" When you type the first tab hit will complete as much as possible, the
" second tab hit will provide a list, the third and subsequent tabs will cycle
" through completion options so you can complete the file without further keys
set wildmode=longest,list,full
set wildmenu
" Configs for vimdiff
if &diff
set diffopt+=iwhite " Ignore whitespace in vimdiff
endif
" highlight the current line in every window and update the highlight as the
" cursor moves.
set cursorline
set mouse=n " Enable mouse mode
if !has('nvim')
set ttymouse=xterm2 " Set TTY mouse type
endif
" Let cursor move past the last char in <C-v> mode
set virtualedit=block
" Keep 10 lines above and below the cursor
set scrolloff=10
" Gvim options
if has("gui_running")
try
if has('gui_win32')
set guifont=Inconsolata-dz_for_Powerline:h10:cANSI
else
set guifont=Inconsolata-dz\ for\ Powerline\ Medium\ 10
endif
catch /^Vim\%((\a\+)\)\=:E596/
echom "The Inconsolata-dz_for_Powerline font is not installed"
endtry
endif
" ====================================
" Key Maps
" ====================================
"cscope config
if has('cscope')
set cscopetag
if has('quickfix')
set cscopequickfix=s-,c-,d-,i-,t-,e-
endif
if filereadable("cscope.out")
try
cs add cscope.out
catch /^Vim\%((\a\+)\)\=:E568/
endtry
endif
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
endif
" Toggle line numbers and special characters with <F3>
noremap <F3> :set nu!<CR>
inoremap <F3> <C-o>:set nu!<CR>
" Toggle paste mode
set pastetoggle=<F2>
" Remove trailing whitespace with <F5>
:nnoremap <silent> <F5> :let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>
" switch back to last buffer
cmap bb b#
" ====================================
" Plugin Configuration
" ====================================
" deoplete
" --------
let g:deoplete#enable_at_startup = 1
" python-mode
" -----------
let g:pymode_options_max_line_length=120
autocmd FileType python set colorcolumn=120
" vim-airline
" ------------
" " don't count trailing whitespace since it lags in huge files
"let g:airline#extensions#whitespace#enabled = 0
" put a buffer list at the top
let g:airline#extensions#tabline#enabled = 1 " Enable the list of buffers
let g:airline#extensions#tabline#fnamemod = ':t' " Show just the filename
let g:airline#extensions#tabline#buffer_nr_show = 1
"special characters
let DISABLE_POWERLINE_FONT=$DISABLE_POWERLINE_FONT
if DISABLE_POWERLINE_FONT == '1'
" use when a powerline font is not installed, define empty powerline symbols
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
else
let g:airline_powerline_fonts = 1 " needs https://github.com/powerline/fonts
endif
" NERDTree
" ------------
"autocmd VimEnter * NERDTreeFind
"autocmd VimEnter * wincmd p
augroup nerd_loader
autocmd!
autocmd VimEnter * silent! autocmd! FileExplorer
autocmd BufEnter,BufNew *
\ if isdirectory(expand('<amatch>'))
\| call plug#load('nerdtree')
\| execute 'autocmd! nerd_loader'
\| endif
augroup END
nnoremap <silent> <Leader>v :NERDTreeFind<CR>
let NERDTreeShowHidden=1
let g:NERDTreeGitStatusLogLevel=3
" Tagbar
" ------------
"autocmd VimEnter * nested :call tagbar#autoopen(1)
nnoremap <silent> <Leader>b :TagbarToggle<CR>
" fzf
" ------------
" git grep
command! -bang -nargs=* GGrep
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)
" Augmenting Ag command using fzf#vim#with_preview function
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Likewise, Files command with preview window
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
noremap <leader>e :Files<CR>
" syntastic
" -----------
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
"let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_python_checkers=['flake8']
let g:syntastic_python_flake8_args='--ignore=E111,E113,E122,E131,E201,E202,E221,E226,E261,E402,E501,W503,W504,E701'
" ====================================
" Funcitons
" ====================================
function! GetVisualSelection() " from http://stackoverflow.com/a/6271254
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
let lines = getline(lnum1, lnum2)
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][col1 - 1:]
return join(lines, "\n")
endfunction
function! EncodeUrl(url) " Add characters as needed
let l:encoded=substitute(a:url, " ", "\\\\%20", "g") " Space
let l:encoded=substitute(l:encoded, "&", "\\\\%26", "g") " Ampersand
let l:encoded=substitute(l:encoded, "+", "\\\\%2B", "g") " Plus
let l:encoded=substitute(l:encoded, ",", "\\\\%2C", "g") " Comma
let l:encoded=substitute(l:encoded, "/", "\\\\%2F", "g") " Forward slash/Virgule
let l:encoded=substitute(l:encoded, ":", "\\\\%3A", "g") " Colon
let l:encoded=substitute(l:encoded, ";", "\\\\%3B", "g") " Semi-colon
let l:encoded=substitute(l:encoded, "=", "\\\\%3D", "g") " Equals
let l:encoded=substitute(l:encoded, "?", "\\\\%3F", "g") " Question mark
let l:encoded=substitute(l:encoded, "@", "\\\\%40", "g") " 'At' symbol
let l:encoded=substitute(l:encoded, "?", "\\\\%22", "g") " Quotation marks
let l:encoded=substitute(l:encoded, "<", "\\\\%3C", "g") " 'Less Than' symbol
let l:encoded=substitute(l:encoded, ">", "\\\\%3E", "g") " 'Greater Than' symbol
let l:encoded=substitute(l:encoded, "{", "\\\\%7B", "g") " Left Curly Brace
let l:encoded=substitute(l:encoded, "}", "\\\\%7D", "g") " Right Curly Brace
let l:encoded=substitute(l:encoded, "|", "\\\\%7C", "g") " Vertical Bar/Pipe
let l:encoded=substitute(l:encoded, "~", "\\\\%7E", "g") " Tilde
let l:encoded=substitute(l:encoded, "[", "\\\\%5B", "g") " Left Square Bracket
let l:encoded=substitute(l:encoded, "]", "\\\\%5D", "g") " Right Square Bracket
let l:encoded=substitute(l:encoded, "`", "\\\\%60", "g") " Grave Accent
let l:encoded=substitute(l:encoded, "#", "\\\\%23", "g") " 'Pound' character
" let l:encoded=substitute(a:url, %, \\\\%25, g) " Percent character
" let l:encoded=substitute(l:encoded, \\, \\\\%5C, g) " Backslash
" let l:encoded=substitute(l:encoded, $, \\\\%24, g) " Dollar
" let l:encoded=substitute(l:encoded, ^, \\\\%5E, g) " Caret
return encoded
endfunction
function! SearchGoogleW3m(str,extra)
let l:sCmd="w3m -M www.google.com/search\\?q=".EncodeUrl(a:str).a:extra
"echom l:sCmd
execute "!" . l:sCmd
endfunction
vnoremap <leader>g :call SearchGoogleW3m(GetVisualSelection(), "")<CR>
" https://stackoverflow.com/a/26314537
let g:rnd = localtime() % 0x10000
function! Random(n) abort
let g:rnd = (g:rnd * 31421 + 6927) % 0x10000
return g:rnd * a:n / 0x10000
endfunction
if !empty(glob("~/.vim/plugged/tagbar/plugin/tagbar.vim"))
noremap <leader>t :make TEST=<C-R>=substitute(tagbar#currenttag("%s",""),"()","","")<CR><CR>
else
echom "Using <cword> for <leader>t"
noremap <leader>t :make TEST=<C-R>=expand("<cword>")<CR><CR>
endif
" YouCompleteMe settings
"let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
"let g:ycm_confirm_extra_conf = '0'
"let g:ycm_max_diagnostics_to_display = 1000