forked from timss/vimconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
630 lines (565 loc) · 23.7 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
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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
"-----------------------------------------------"
" Author: Tim Sæterøy "
" Homepage: http://thevoid.no "
" Source: http://github.com/timss/vimconf "
"-----------------------------------------------"
" vimconf is not vi-compatible
set nocompatible
""" Automatically make needed files and folders on first run
""" If you don't run *nix you're on your own (as in remove this) {{{
call system("mkdir -p $HOME/.vim/{swap,undo}")
if !filereadable($HOME . "/.vimrc.plugins") | call system("touch $HOME/.vimrc.plugins") | endif
if !filereadable($HOME . "/.vimrc.first") | call system("touch $HOME/.vimrc.first") | endif
if !filereadable($HOME . "/.vimrc.last") | call system("touch $HOME/.vimrc.last") | endif
""" }}}
""" Vundle plugin manager {{{
""" Automatically setting up Vundle, taken from
""" http://www.erikzaadi.com/2012/03/19/auto-installing-vundle-from-your-vimrc/ {{{
let has_vundle=1
if !filereadable($HOME."/.vim/bundle/Vundle.vim/README.md")
echo "Installing Vundle..."
echo ""
silent !mkdir -p $HOME/.vim/bundle
silent !git clone https://github.com/gmarik/Vundle.vim $HOME/.vim/bundle/Vundle.vim
let has_vundle=0
endif
""" }}}
""" Initialize Vundle {{{
filetype off " required to init
set rtp+=$HOME/.vim/bundle/Vundle.vim " include vundle
call vundle#begin() " init vundle
""" }}}
""" Github repos, uncomment to disable a plugin {{{
Plugin 'gmarik/Vundle.vim'
""" Local plugins (and only plugins in this file!) {{{{
if filereadable($HOME."/.vimrc.plugins")
source $HOME/.vimrc.plugins
endif
""" }}}
" Edit files using sudo/su
Plugin 'chrisbra/SudoEdit.vim'
" <Tab> everything!
Plugin 'ervandew/supertab'
" Fuzzy finder (files, mru, etc)
Plugin 'kien/ctrlp.vim'
" A pretty statusline, bufferline integration
Plugin 'itchyny/lightline.vim'
Plugin 'bling/vim-bufferline'
" Easy... motions... yeah.
Plugin 'Lokaltog/vim-easymotion'
" Glorious colorscheme
Plugin 'nanotech/jellybeans.vim'
" Super easy commenting, toggle comments etc
Plugin 'scrooloose/nerdcommenter'
" Autoclose (, " etc
Plugin 'Townk/vim-autoclose'
" Git wrapper inside Vim
Plugin 'tpope/vim-fugitive'
" Handle surround chars like ''
Plugin 'tpope/vim-surround'
" Align your = etc.
Plugin 'vim-scripts/Align'
" Snippets like textmate
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'honza/vim-snippets'
Plugin 'garbas/vim-snipmate'
" A fancy start screen, shows MRU etc.
Plugin 'mhinz/vim-startify'
" Vim signs (:h signs) for modified lines based off VCS (e.g. Git)
Plugin 'mhinz/vim-signify'
" Awesome syntax checker.
" REQUIREMENTS: See :h syntastic-intro
Plugin 'scrooloose/syntastic'
" Functions, class data etc.
" REQUIREMENTS: (exuberant)-ctags
Plugin 'majutsushi/tagbar'
" Finish Vundle stuff
call vundle#end()
""" Installing plugins the first time, quits when done {{{
if has_vundle == 0
:silent! PluginInstall
:qa
endif
""" }}}
""" }}}
""" Local leading config, only use for prerequisites as it will be
""" overwritten by anything below {{{{
if filereadable($HOME."/.vimrc.first")
source $HOME/.vimrc.first
endif
""" }}}
""" User interface {{{
""" Syntax highlighting {{{
filetype plugin indent on " detect file plugin+indent
syntax on " syntax highlighting
set background=dark " we're using a dark bg
colorscheme jellybeans " colorscheme from plugin
""" .txt w/highlight, plaintex is useless, markdown for .md {{{
augroup FileTypeRules
autocmd!
autocmd BufNewFile,BufRead *.txt set ft=sh tw=79
autocmd BufNewFile,BufRead *.tex set ft=tex tw=79
autocmd BufNewFile,BufRead *.md set ft=markdown tw=79
augroup END
""" }}}
""" 256 colors for maximum jellybeans bling. See commit log for info {{{
if (&term =~ "xterm") || (&term =~ "screen")
set t_Co=256
endif
""" }}}
""" Tab colors, overwritten by lightline(?) {{{
"hi TabLineFill ctermfg=NONE ctermbg=233
"hi TabLine ctermfg=241 ctermbg=233
"hi TabLineSel ctermfg=250 ctermbg=233
""" }}}
""" Custom highlighting, where NONE uses terminal background {{{
function! CustomHighlighting()
highlight Normal ctermbg=NONE
highlight NonText ctermbg=NONE
highlight LineNr ctermbg=NONE
highlight SignColumn ctermbg=NONE
highlight SignColumn guibg=#151515
highlight CursorLine ctermbg=235
endfunction
call CustomHighlighting()
""" }}}
""" }}}
""" Interface general {{{
set cursorline " hilight cursor line
set more " ---more--- like less
set number " line numbers
set scrolloff=3 " lines above/below cursor
set showcmd " show cmds being typed
set title " window title
set vb t_vb= " disable beep and flashing
set wildignore=*.a,*.o,*.so,*.pyc,*.jpg,
\*.jpeg,*.png,*.gif,*.pdf,*.git,
\*.swp,*.swo " tab completion ignores
set wildmenu " better auto complete
set wildmode=longest,list " bash-like auto complete
""" Depending on your setup you may want to enforce UTF-8.
""" Should generally be set in your environment LOCALE/$LANG {{{
" set encoding=utf-8 " default $LANG/latin1
" set fileencoding=utf-8 " default none
""" }}}
""" Gvim {{{
set guifont=DejaVu\ Sans\ Mono\ 9
set guioptions-=m " remove menubar
set guioptions-=T " remove toolbar
set guioptions-=r " remove right scrollbar
""" }}}
""" }}}
""" }}}
""" General settings {{{
set hidden " buffer change, more undo
set history=1000 " default 20
set iskeyword+=_,$,@,%,# " not word dividers
set laststatus=2 " always show statusline
set linebreak " don't cut words on wrap
set listchars=tab:>\ " > to highlight <tab>
set list " displaying listchars
set mouse= " disable mouse
set noshowmode " hide mode cmd line
set noexrc " don't use other .*rc(s)
set nostartofline " keep cursor column pos
set nowrap " don't wrap lines
set numberwidth=5 " 99999 lines
set shortmess+=I " disable startup message
set splitbelow " splits go below w/focus
set splitright " vsplits go right w/focus
set ttyfast " for faster redraws etc
set ttymouse=xterm2 " experimental
""" Folding {{{
set foldcolumn=0 " hide folding column
set foldmethod=indent " folds using indent
set foldnestmax=10 " max 10 nested folds
set foldlevelstart=99 " folds open by default
""" }}}
""" Search and replace {{{
set gdefault " default s//g (global)
set incsearch " "live"-search
""" }}}
""" Matching {{{
set matchtime=2 " time to blink match {}
set matchpairs+=<:> " for ci< or ci>
set showmatch " tmpjump to match-bracket
""" }}}
""" Return to last edit position when opening files {{{
augroup LastPosition
autocmd! BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
""" }}}
""" }}}
""" Files {{{
set autochdir " always use curr. dir.
set autoread " refresh if changed
set confirm " confirm changed files
set noautowrite " never autowrite
set nobackup " disable backups
""" Persistent undo. Requires Vim 7.3 {{{
if has('persistent_undo') && exists("&undodir")
set undodir=$HOME/.vim/undo/ " where to store undofiles
set undofile " enable undofile
set undolevels=500 " max undos stored
set undoreload=10000 " buffer stored undos
endif
""" }}}
""" Swap files, unless vim is invoked using sudo. Inspired by tejr's vimrc
""" https://github.com/tejr/dotfiles/blob/master/vim/vimrc {{{
if !strlen($SUDO_USER)
set directory^=$HOME/.vim/swap// " default cwd, // full path
set swapfile " enable swap files
set updatecount=50 " update swp after 50chars
""" Don't swap tmp, mount or network dirs {{{
augroup SwapIgnore
autocmd! BufNewFile,BufReadPre /tmp/*,/mnt/*,/media/*
\ setlocal noswapfile
augroup END
""" }}}
else
set noswapfile " dont swap sudo'ed files
endif
""" }}}
""" }}}
""" Text formatting {{{
set autoindent " preserve indentation
set backspace=indent,eol,start " smart backspace
set cinkeys-=0# " don't force # indentation
set expandtab " no real tabs
set ignorecase " by default ignore case
set nrformats+=alpha " incr/decr letters C-a/-x
set shiftround " be clever with tabs
set shiftwidth=4 " default 8
set smartcase " sensitive with uppercase
set smarttab " tab to 0,4,8 etc.
set softtabstop=4 " "tab" feels like <tab>
set tabstop=4 " replace <TAB> w/4 spaces
""" Only auto-comment newline for block comments {{{
augroup AutoBlockComment
autocmd! FileType c,cpp setlocal comments -=:// comments +=f://
augroup END
""" }}}
""" Take comment leaders into account when joining lines, :h fo-table
""" http://ftp.vim.org/pub/vim/patches/7.3/7.3.541 {{{
if has("patch-7.3.541")
set formatoptions+=j
endif
""" }}}
""" }}}
""" Keybindings {{{
""" General {{{
" Remap <leader>
let mapleader=","
" Quickly edit/source .vimrc
noremap <leader>ve :edit $HOME/.vimrc<CR>
noremap <leader>vs :source $HOME/.vimrc<CR>
" Yank(copy) to system clipboard
noremap <leader>y "+y
" Toggle folding
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf
" Bubbling (bracket matching)
nmap <C-up> [e
nmap <C-down> ]e
vmap <C-up> [egv
vmap <C-down> ]egv
" Scroll up/down lines from 'scroll' option, default half a screen
map <C-j> <C-d>
map <C-k> <C-u>
" Treat wrapped lines as normal lines
nnoremap j gj
nnoremap k gk
" Working ci(, works for both breaklined, inline and multiple ()
nnoremap ci( %ci(
" We don't need any help!
inoremap <F1> <nop>
nnoremap <F1> <nop>
vnoremap <F1> <nop>
" Disable annoying ex mode (Q)
map Q <nop>
" Buffers, preferred over tabs now with bufferline.
nnoremap gn :bnext<CR>
nnoremap gN :bprevious<CR>
nnoremap gd :bdelete<CR>
nnoremap gf <C-^>
""" }}}
""" Functions or fancy binds {{{{
""" Toggle syntax highlighting {{{
function! ToggleSyntaxHighlighthing()
if exists("g:syntax_on")
syntax off
else
syntax on
call CustomHighlighting()
endif
endfunction
nnoremap <leader>s :call ToggleSyntaxHighlighthing()<CR>
""" }}}
""" Highlight characters past 79, toggle with <leader>h
""" You might want to override this function and its variables with
""" your own in .vimrc.last which might set for example colorcolumn or
""" even the textwidth. See https://github.com/timss/vimconf/pull/4 {{{
let g:overlength_enabled = 0
highlight OverLength ctermbg=238 guibg=#444444
function! ToggleOverLength()
if g:overlength_enabled == 0
match OverLength /\%79v.*/
let g:overlength_enabled = 1
echo 'OverLength highlighting turned on'
else
match
let g:overlength_enabled = 0
echo 'OverLength highlighting turned off'
endif
endfunction
nnoremap <leader>h :call ToggleOverLength()<CR>
""" }}}
""" Toggle relativenumber using <leader>r {{{
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunction
nnoremap <leader>r :call NumberToggle()<CR>
""" }}}
""" Toggle text wrapping, wrap on whole words
""" For more info see: http://stackoverflow.com/a/2470885/1076493 {{{
function! WrapToggle()
if &wrap
set list
set nowrap
else
set nolist
set wrap
endif
endfunction
nnoremap <leader>w :call WrapToggle()<CR>
""" }}}
""" Remove multiple empty lines {{{
function! DeleteMultipleEmptyLines()
g/^\_$\n\_^$/d
endfunction
nnoremap <leader>ld :call DeleteMultipleEmptyLines()<CR>
""" }}}
""" Split to relative header/source {{{
function! SplitRelSrc()
let s:fname = expand("%:t:r")
if expand("%:e") == "h"
set nosplitright
exe "vsplit" fnameescape(s:fname . ".cpp")
set splitright
elseif expand("%:e") == "cpp"
exe "vsplit" fnameescape(s:fname . ".h")
endif
endfunction
nnoremap <leader>le :call SplitRelSrc()<CR>
""" }}}
""" Strip trailing whitespace, return to cursor at save {{{
function! <SID>StripTrailingWhitespace()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfunction
augroup StripTrailingWhitespace
autocmd!
autocmd FileType c,cpp,conf,css,html,perl,python,sh
\ autocmd BufWritePre <buffer> :call
\ <SID>StripTrailingWhitespace()
augroup END
""" }}}
""" }}}
""" Plugins {{{
" Toggle tagbar (definitions, functions etc.)
map <F1> :TagbarToggle<CR>
" Toggle pastemode, doesn't indent
set pastetoggle=<F3>
" Syntastic - toggle error list. Probably should be toggleable.
noremap <silent><leader>lo :Errors<CR>
noremap <silent><leader>lc :lcl<CR>
""" }}}
""" }}}
""" Plugin settings {{{
""" Lightline {{{
let g:lightline = {
\ 'colorscheme': 'jellybeans',
\ 'active': {
\ 'left': [
\ ['mode', 'paste'],
\ ['readonly', 'fugitive'],
\ ['ctrlpmark', 'bufferline']
\ ],
\ 'right': [
\ ['lineinfo'],
\ ['percent'],
\ ['fileformat', 'fileencoding', 'filetype', 'syntastic']
\ ]
\ },
\ 'component': {
\ 'paste': '%{&paste?"!":""}'
\ },
\ 'component_function': {
\ 'mode' : 'MyMode',
\ 'fugitive' : 'MyFugitive',
\ 'readonly' : 'MyReadonly',
\ 'ctrlpmark' : 'CtrlPMark',
\ 'bufferline' : 'MyBufferline',
\ 'fileformat' : 'MyFileformat',
\ 'fileencoding' : 'MyFileencoding',
\ 'filetype' : 'MyFiletype'
\ },
\ 'component_expand': {
\ 'syntastic': 'SyntasticStatuslineFlag',
\ },
\ 'component_type': {
\ 'syntastic': 'middle',
\ },
\ 'subseparator': {
\ 'left': '|', 'right': '|'
\ }
\ }
let g:lightline.mode_map = {
\ 'n' : ' N ',
\ 'i' : ' I ',
\ 'R' : ' R ',
\ 'v' : ' V ',
\ 'V' : 'V-L',
\ 'c' : ' C ',
\ "\<C-v>" : 'V-B',
\ 's' : ' S ',
\ 'S' : 'S-L',
\ "\<C-s>" : 'S-B',
\ '?' : ' ' }
function! MyMode()
let fname = expand('%:t')
return fname == '__Tagbar__' ? 'Tagbar' :
\ fname == 'ControlP' ? 'CtrlP' :
\ winwidth('.') > 60 ? lightline#mode() : ''
endfunction
function! MyFugitive()
try
if expand('%:t') !~? 'Tagbar' && exists('*fugitive#head')
let mark = '± '
let _ = fugitive#head()
return strlen(_) ? mark._ : ''
endif
catch
endtry
return ''
endfunction
function! MyReadonly()
return &ft !~? 'help' && &readonly ? '≠' : '' " or ⭤
endfunction
function! CtrlPMark()
if expand('%:t') =~ 'ControlP'
call lightline#link('iR'[g:lightline.ctrlp_regex])
return lightline#concatenate([g:lightline.ctrlp_prev, g:lightline.ctrlp_item
\ , g:lightline.ctrlp_next], 0)
else
return ''
endif
endfunction
function! MyBufferline()
call bufferline#refresh_status()
let b = g:bufferline_status_info.before
let c = g:bufferline_status_info.current
let a = g:bufferline_status_info.after
let alen = strlen(a)
let blen = strlen(b)
let clen = strlen(c)
let w = winwidth(0) * 4 / 11
if w < alen+blen+clen
let whalf = (w - strlen(c)) / 2
let aa = alen > whalf && blen > whalf ? a[:whalf] : alen + blen < w - clen || alen < whalf ? a : a[:(w - clen - blen)]
let bb = alen > whalf && blen > whalf ? b[-(whalf):] : alen + blen < w - clen || blen < whalf ? b : b[-(w - clen - alen):]
return (strlen(bb) < strlen(b) ? '...' : '') . bb . c . aa . (strlen(aa) < strlen(a) ? '...' : '')
else
return b . c . a
endif
endfunction
function! MyFileformat()
return winwidth('.') > 90 ? &fileformat : ''
endfunction
function! MyFileencoding()
return winwidth('.') > 80 ? (strlen(&fenc) ? &fenc : &enc) : ''
endfunction
function! MyFiletype()
return winwidth('.') > 70 ? (strlen(&filetype) ? &filetype : 'no ft') : ''
endfunction
let g:ctrlp_status_func = {
\ 'main': 'CtrlPStatusFunc_1',
\ 'prog': 'CtrlPStatusFunc_2',
\ }
function! CtrlPStatusFunc_1(focus, byfname, regex, prev, item, next, marked)
let g:lightline.ctrlp_regex = a:regex
let g:lightline.ctrlp_prev = a:prev
let g:lightline.ctrlp_item = a:item
let g:lightline.ctrlp_next = a:next
return lightline#statusline(0)
endfunction
function! CtrlPStatusFunc_2(str)
return lightline#statusline(0)
endfunction
let g:tagbar_status_func = 'TagbarStatusFunc'
function! TagbarStatusFunc(current, sort, fname, ...) abort
let g:lightline.fname = a:fname
return lightline#statusline(0)
endfunction
function! s:syntastic()
SyntasticCheck
call lightline#update()
endfunction
augroup AutoSyntastic
autocmd!
autocmd BufWritePost *.c,*.cpp,*.perl,*py call s:syntastic()
augroup END
""" }}}
" Startify, the fancy start page
let g:ctrlp_reuse_window = 'startify' " don't split in startify
let g:startify_bookmarks = [
\ $HOME . "/.vimrc", $HOME . "/.vimrc.first",
\ $HOME . "/.vimrc.last", $HOME . "/.vimrc.plugins"
\ ]
let g:startify_custom_header = [
\ ' Author: Tim Sæterøy',
\ ' Homepage: http://thevoid.no',
\ ' Source: http://github.com/timss/vimconf',
\ ''
\ ]
" CtrlP - don't recalculate files on start (slow)
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_working_path_mode = 'ra'
" TagBar
let g:tagbar_left = 0
let g:tagbar_width = 30
set tags=tags;/
" Syntastic - This is largely up to your own usage, and override these
" changes if be needed. This is merely an exemplification.
let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_compiler_options = ' -std=c++0x'
let g:syntastic_mode_map = {
\ 'mode': 'passive',
\ 'active_filetypes':
\ ['c', 'cpp', 'perl', 'python'] }
" Netrw - the bundled (network) file and directory browser
let g:netrw_banner = 0
let g:netrw_list_hide = '^\.$'
let g:netrw_liststyle = 3
" Automatically remove preview window after autocomplete (mainly for clang_complete)
augroup RemovePreview
autocmd!
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
augroup END
""" }}}
""" Local ending config, will overwrite anything above. Generally use this. {{{{
if filereadable($HOME."/.vimrc.last")
source $HOME/.vimrc.last
endif
""" }}}