forked from JDevlieghere/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
400 lines (335 loc) · 12.5 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
set nocompatible
" ---------------------------------------------------------------------------- "
" Plug "
" ---------------------------------------------------------------------------- "
call plug#begin('~/.vim/plugged')
" Color Schemes
Plug 'altercation/vim-colors-solarized'
Plug 'nanotech/jellybeans.vim'
Plug 'chriskempson/base16-vim'
" Plug-ins
Plug 'Shougo/vimproc.vim', { 'do': 'make' }
Plug 'chiel92/vim-autoformat', { 'on': 'Autoformat' }
Plug 'ciaranm/detectindent'
Plug 'fatih/vim-go', { 'for': 'go' }
Plug 'godlygeek/tabular' | Plug 'plasticboy/vim-markdown', { 'for': 'markdown' }
Plug 'jdevlieghere/llvm.vim'
Plug 'majutsushi/tagbar'
Plug 'mbbill/undotree', { 'on': 'UndotreeToggle' }
Plug 'mhinz/vim-signify'
Plug 'moll/vim-bbye'
Plug 'octol/vim-cpp-enhanced-highlight', { 'for': 'cpp' }
Plug 'rhysd/vim-grammarous', { 'on': 'GrammarousCheck' }
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'vim-scripts/DoxygenToolkit.vim', { 'for': 'cpp' }
" FZF
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Rust
Plug 'racer-rust/vim-racer', { 'for': 'rust' }
Plug 'rust-lang/rust.vim', { 'for': 'rust' }
" Haskell
Plug 'Twinside/vim-hoogle', { 'for': 'haskell' }
Plug 'eagletmt/ghcmod-vim', { 'for': 'haskell' }
Plug 'eagletmt/neco-ghc', { 'for': 'haskell' }
Plug 'mpickering/hlint-refactor-vim', { 'for': 'haskell' }
if has("nvim")
Plug 'benekastah/neomake'
else
Plug 'scrooloose/syntastic'
Plug 'tpope/vim-dispatch'
endif
if has("python")
Plug 'valloric/youcompleteme', { 'do': './install.py --clang-completer --gocode-completer --tern-completer --racer-completer' }
endif
call plug#end()
" ---------------------------------------------------------------------------- "
" Vanilla Vim "
" ---------------------------------------------------------------------------- "
" Colors & Syntax
syntax enable " Enable syntax highlighting
set background=dark " Dark background color
" Color Scheme
colorscheme solarized
highlight clear SignColumn " Sing column same background as line numbers
" Essentials
filetype plugin indent on " Enable file type support
set encoding=utf-8 " UTF-8 encoding
set binary " Enable binary support
set hidden " Hide buffers
set showcmd " Show current command
set showmode " Show current mode
set autoread " Auto reload
set ttyfast " Fast terminal
set ruler " Show ruler
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%)
set nofoldenable " disable folding
set laststatus=2 " Alwasy display statusline
" Crypto
if !has("nvim")
set cm=blowfish
endif
" Temp Files
set nobackup " No backup file
set noswapfile " No swap file
" Line Numbers
set nu " Show line numbers
"set rnu " Relative line numbers
" Rulers
set colorcolumn=80,120 " Show ruler columns
" Cursor Line
"set cursorline
" Scrolling
set scrolloff=3 " Keep at least 3 lines above/below
set sidescrolloff=3 " Keep at least 3 lines left/right
" Searching
set incsearch " Incremental search
set hlsearch " Highlight matches
set ignorecase " Case-insensitive search
set smartcase " Unless search contains uppercase letter
set showmatch " Show matching bracket
vnoremap // y/<C-R>"<CR> " Search for visual selection
" Indentation
set smarttab " Better tabs
set smartindent " Inserts new level of indentation
set autoindent " Copy indentation from previous line
set tabstop=2 " Columns a tab counts for
set softtabstop=2 " Columns a tab inserts in insert mode
set shiftwidth=2 " Columns inserted with the reindent operations
set shiftround " Always indent by multiple of shiftwidth
set expandtab " Always use spaces instead of tabs
" Key sequence timeout
set ttimeout " Enable time out
set ttimeoutlen=100 " Set timeout time to 100 ms
" Backspace
set backspace=indent,eol,start " Delete over line breaks
" Mouse
set mousehide " Hide mouse when typing
set mouse=nicr " Disable mouse
" Typos
cnoreabbrev W w " :W
cnoreabbrev Q q " :Q
" Wrapping
set nowrap " No wrapping
set linebreak " When wrapping, only at certain characters
set textwidth=0 " Turn off physical line wrapping
set wrapmargin=0 " Turn off physical line wrapping
" Invisible Characters
nmap <leader>l :set list!<CR> " Toggle hidden characters
set nolist " Hide by default
set listchars=tab:▸\ ,trail:-,extends:>,precedes:<,nbsp:⎵,eol:¬
" Completion Menu
set completeopt=longest,menuone " Inserts the longest common text and
" show menu even with only one item
" Toggle Paste Mode
nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
" Spell Checking
set spelllang=en_us " Default language
set complete+=kspell " Word completion
map <F7> :setlocal spell!<CR> " Toggle spell check
autocmd BufRead,BufNewFile *.md setlocal spell
autocmd FileType gitcommit setlocal spell
" Doxygen
autocmd Filetype c,cpp set comments^=:///
" Disable Bells
set noeb vb t_vb=
" Treat given characters as a word boundary
set iskeyword-=. " '.' is an end of word designator
set iskeyword-=# " '#' is an end of word designator
" Wrapping
vmap Q gq
nmap Q gqap
" Cycle through buffers
nnoremap <silent> <Tab> :bnext<CR>
nnoremap <silent> <S-Tab> :bprevious<CR>
" Close window
nmap <silent> <Leader>wd <C-w>q
" Splits
set splitbelow
set splitright
" Enable Copy/Paste
set clipboard=unnamed
vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa
" Ctags
set tags=tags; " Find tags recursively
" Joining
set nojoinspaces " Only one space when joining lines
if has('patch-7.3.541')
set formatoptions+=j " Remove comment leader when joining lines
endif
" Undo
if has('persistent_undo')
set undofile " Persistent undo
set undodir=~/.vim/undo " Location to store undo history
set undolevels=1000 " Max number of changes
set undoreload=10000 " Max lines to save for undo on a buffer reload
endif
" NASM
au BufRead,BufNewFile *.nasm set filetype=nasm
" GUI
if has("gui_running")
set vb t_vb=
set guioptions-=L " Hide scroll bars
set lines=999 columns=999 " Start maximized
if has("gui_gtk2")
set guifont=Source\ Code\ Pro\ for\ Powerline:h12,Source\ Code\ Pro:h12
elseif has("gui_macvim")
set guifont=Source\ Code\ Pro\ for\ Powerline:h14,Source\ Code\ Pro:h14
elseif has("gui_win32")
set guifont=Sauce_Code_Powerline:h11:cANSI,Source_Code_Pro:h11:cANSI
endif
endif
" Copy filename:linenumber to clipboard
nnoremap <leader>y :let @+=expand('%:t') . ':' . line(".")<CR>
" Remove Trailing Whitespace
autocmd BufWritePre * :%s/\s\+$//e
" Watch my .vimrc
augroup reload_myvimrc
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END
" ---------------------------------------------------------------------------- "
" Functions "
" ---------------------------------------------------------------------------- "
" Highlight duplicate lines
" http://stackoverflow.com/questions/1268032/marking-duplicate-lines
function! HighlightRepeats() range
let lineCounts={}
let lineNum=a:firstline
while lineNum <= a:lastline
let lineText=getline(lineNum)
if lineText != ""
let lineCounts[lineText]=(has_key(lineCounts, lineText) ? lineCounts[lineText] : 0) + 1
endif
let lineNum=lineNum + 1
endwhile
exe 'syn clear Repeat'
for lineText in keys(lineCounts)
if lineCounts[lineText] >= 2
exe 'syn match Repeat "^' . escape(lineText, '".\^$*[]') . '$"'
endif
endfor
endfunction
command! -range=% HighlightRepeats <line1>,<line2>call HighlightRepeats()
" Switch between source and header files using ctags
" Rudimentary approach: only supports .cpp and .h
function! Switch()
let baseName=expand('%:t:r')
let extension=expand('%:e')
if extension =~ 'c'
execute "tag " . baseName . '.h'
else
execute "tag " . baseName . '.cpp'
endif
endfunction
nmap <silent> <Leader>fs :call Switch()<CR>
" ---------------------------------------------------------------------------- "
" Plugin Configuration "
" ---------------------------------------------------------------------------- "
" Close buffer
nnoremap <silent> <Leader>q :Bdelete<CR>
nnoremap <silent> <Leader>bd :Bdelete!<CR>
" FZF
let g:fzf_buffers_jump=1
nnoremap <silent> <C-p> :Files<CR>
nnoremap <silent> <C-b> :Buffers<CR>
" Airline
let g:airline_powerline_fonts=1
let g:airline#extensions#tabline#enabled=1
let g:airline#extensions#tabline#fnamemod=':t'
" Detect Indent
let g:detectindent_preferred_expandtab=1
let g:detectindent_preferred_indent=4
autocmd BufReadPost * :DetectIndent
" Tagbar
nnoremap <F8> :TagbarToggle<CR>
let g:tagbar_autofocus=0
let g:tagbar_right=1
let g:tagbar_width=35
if !has("nvim")
autocmd VimEnter * nested :TagbarOpen
endif
" NERDTree
let g:NERDTreeIgnore=['\.job$', '^CVS$', '\.orig', '\~$']
let g:NERDTreeShowHidden=1
let g:NERDTreeStatusline="%f"
let g:NERDTreeWinPos="left"
let g:NERDTreeWinSize=35
nnoremap <F9> :NERDTreeFind<CR>
nnoremap <F10> :NERDTreeToggle<CR>
" Open NERDTree when vim is started without file
" autocmd StdinReadPre * let s:std_in=1
" autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" Close vim if the only window left is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" YouCompleteMe
let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
let g:ycm_extra_conf_globlist=['~/.vim/*']
let g:ycm_always_populate_location_list = 0
let g:ycm_auto_trigger=1
let g:ycm_enable_diagnostic_highlighting=1
let g:ycm_enable_diagnostic_signs=1
let g:ycm_max_diagnostics_to_display=10000
let g:ycm_min_num_identifier_candidate_chars=0
let g:ycm_min_num_of_chars_for_completion=2
let g:ycm_open_loclist_on_ycm_diags=1
let g:ycm_show_diagnostics_ui=1
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_filetype_blacklist={
\ 'vim' : 1,
\ 'tagbar' : 1,
\ 'qf' : 1,
\ 'notes' : 1,
\ 'markdown' : 1,
\ 'md' : 1,
\ 'unite' : 1,
\ 'text' : 1,
\ 'vimwiki' : 1,
\ 'pandoc' : 1,
\ 'infolog' : 1,
\ 'mail' : 1
\}
" 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 python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
nnoremap <F12> :YcmDiags<CR>
nnoremap <silent> <Leader>yd :YcmDiags<CR>
nnoremap <silent> <Leader>fi :YcmCompleter FixIt<CR>
nnoremap <silent> <Leader>gt :YcmCompleter GoTo<CR>
" Auto Format
let g:formatdef_clangformat='"clang-format -style=file"'
" Doxygen
let g:DoxygenToolkit_commentType = "C++"
if has("nvim")
" Neomake
nnoremap <F5> :Neomake<CR>
let g:neomake_javascript_enabled_makers = ['jshint']
let g:neomake_python_enabled_makers = ['pylint']
else
" 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_cpp_checkers=['cppcheck']
let g:syntastic_javascript_checkers = ['jshint']
let g:syntastic_python_checkers=['pylint']
" Dispatch
nnoremap <F5> :Make<CR>
endif