Source

MyVim / .vimrc

Full commit
  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
".vimrc by rride aka Alexander Ivaniuk
" Last Change:11-Mar-2012.

set nocompatible

if has("mac") && &term == "xterm"
    set t_Co=8
else
    set t_Co=256
endif


filetype off                   " required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Bundles
" let Vundle manage Vundle
" required! 
Bundle 'gmarik/vundle'
Bundle 'kien/tabman.vim'

Bundle 'Color-Sampler-Pack'
Bundle 'autodate.vim'
Bundle 'altercation/vim-colors-solarized'
Bundle 'ervandew/supertab'
Bundle 'DirDiff.vim'
Bundle 'L9'
Bundle 'FuzzyFinder'
Bundle 'sjbach/lusty'
Bundle 'scrooloose/nerdcommenter'
Bundle 'scrooloose/nerdtree'
Bundle 'bufexplorer.zip'
Bundle 'tomasr/molokai'
Bundle 'ScrollColors'

Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-repeat'
Bundle 'compview'
Bundle 'kien/ctrlp.vim'


Bundle 'godlygeek/tabular'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'IndexedSearch'

"Bundle 'viewdoc'
"Bundle 'GtagsClient'
" non github repos
Bundle 'git://git.wincent.com/command-t'
Bundle 'msanders/snipmate.vim'
Bundle 'scrooloose/snipmate-snippets' 
Bundle 'Lokaltog/vim-powerline'
"Bundle 'millermedeiros/vim-statline'
"Bundle 'millermedeiros/vim-statline'

" C++ stuff
" .h to .cpp switching and vice versa
Bundle 'derekwyatt/vim-fswitch' 
" creating implementation of defined functions in cpp files
Bundle 'derekwyatt/vim-protodef' 

Bundle 'pydave/AsyncCommand'

" TODO: test
Bundle 'Shougo/neocomplcache'
Bundle 'Shougo/neocomplcache-snippets-complete'
""""

filetype plugin indent on     " required! for vundle to work

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vundle end
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

if has('win32')
    language messages en
    let vimfiles_dir=expand("$HOME/vimfiles/")
else
    language messages en_US.UTF-8
    let vimfiles_dir=expand("$HOME/.vim/")
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Many ideas taken from http://amix.dk/vim/vimrc.html
" and from http://konishchevdmitry.blogspot.com/2008/07/howto-vim.html
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700

set nocompatible
"set nobackup

" When vimrc is edited, reload it
" autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc
"Command autocomplete
set showcmd
set complete-=i
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Editing
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
filetype plugin indent on

" Настраиваем переключение раскладок клавиатуры по <C-^>
"set keymap=russian-jcukenwin
" Default keyboard layout - english
"set iminsert=0
"set imsearch=-1

set nowrap
set selection=exclusive " Like in windows
set autowrite

set hlsearch 	" highlight found items
set incsearch " incremental search
set ic " case insensitive search
set smartcase
nnoremap <silent><esc> :noh<return><esc>


set hid " just abandon the buffer rather than hide it
" will delete over line breaks, or automatically-inserted indentation, 
" or the place where insert mode started
set backspace=indent,eol,start

set whichwrap+=<,>,h,l  "go beyond of start/end of line also with h,j,k,l keys

set autoindent
set smartindent

set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set showmatch " when a bracket is inserted briefly highlight a matching one
set matchtime=5 " tens of second

" do not indent preprocessor directives to the first column!!!
set cinkeys="0{,0},0),:,!^F,o,O,e" "default value is: 0{,0},0),:,0#,!^F,o,O,e.

" Turn on folding
set foldenable
" Make folding indent sensitive
set foldmethod=syntax

" Don't autofold anything (but I can still fold manually)
set foldlevel=7
set foldminlines=3

set encoding=utf8
"set nohidden

" map all the commands starting with : to ;
"nnoremap ; :

" Easy window navigation
map <C-l> <esc>zo
map <C-h> <esc>zc
"map <S-h> <C-w>h
"map <C-S-j> <C-w>j
"map <C-S-k> <C-w>k
"map <C-S-l> <C-w>l

"map <F4>  <esc>:call SwitchFold()<cr>
"function! SwitchFold()
"    if &foldmethod=="syntax"
"        set foldmethod=indent
"        return
"    endif
"    if &foldmethod=="indent"
"        set foldmethod=manual
"        return
"    endif
"    if &foldmethod=="manual"
"        set foldmethod=syntax
"        return
"    endif
"endfunction

map <C-j> 8j
map <C-k> 8k
" map <C-j> <esc>:call NextSameIndent(1)<cr>
" map <C-k> <esc>:call NextSameIndent(-1)<cr>

"a trick by Steve Losh for when you forgot to sudo before editing a file that requires 
" root privileges (typically /etc/hosts). This lets you use w!! to do that after you opened the file already:
cmap w!! w !sudo tee % >/dev/null

set so=7 " number of lines between cursor and screen border to keep while scrolling

set virtualedit=block

try
  set switchbuf=usetab " if a buffer is present in another tab, switch to it instead of replacing contents of the current window
catch
endtry

set textwidth=0
let mapleader=","

set sessionoptions=curdir,buffers,help,resize,slash,unix,winpos,winsize
if version >= 700
    " и табы
    set sessionoptions+=tabpages
endif

"if has('gui')
"    if has('win32')
"        autocmd VimLeavePre * silent mksession! ~/vimfiles/lastSession.vim
"    else
"        autocmd VimLeavePre * silent mksession! ~/.vim/lastSession.vim
"    endif
"endif

"set ttyscroll=3
set pastetoggle=<F4>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" User interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

if has("gui") && &term == "builtin_gui"
    colorscheme inkpot
else
    colorscheme lucius
endif
hi link EasyMotionTarget ErrorMsg
hi link EasyMotionShade  Comment

set lazyredraw
set guioptions-=T " no toolbar
set guioptions-=e " Use text tab headers
set guioptions-=m " Use text tab headers

set ruler
set number

set mouse=a

if has("win32") || has ("win64") || has("win32unix")
	set guifont=consolas:h9:cRUSSIAN
else
    "set guifont=Consolas
endif

"set langmap=йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],фa,ыs,вd,аf,пg,рh,оj,лk,дl,э',яz,чx,сc,мv,иb,тn,ьm,б\\,,ю.,ё`,ЙQ,ЦW,УE,КR,ЕT,НY,ГU,ШI,ЩO,ЗP,Х{,Ъ},ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Э\",ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б\<,Ю\>,Ё\~

if has('gui_macvim')
    " To make tabs more readable, the label only contains the tail of the file
    " name and the buffer modified flag.
    set guitablabel=%M%t
endif

set wildmode=longest,list,full
set wildmenu

set wildignore=.hg,.git,.svn,*.o,*.lib,.tmp

try
    set stal=2 " show tab list always
catch
endtry

" Copying to system buffer on MAC

if has("mac")
    map <F5> :!pbcopy<CR>u
endif

map <silent><leader>ev :e ~/.vim/.vimrc<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" No error sounds or visual blinking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set noerrorbells
autocmd GUIEnter * set vb t_vb= " turn off verything after GUI starts. Nothing else seems to be working in GVim

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Syntax debugging
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Echo all syntax rules in a stack applied to the current character.
" Taken from http://groups.google.com/group/vim_use/t/7e8fd55cb1606765
nmap <F10>
\ :echo '<'.synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name').'> from:' <bar>
\ let indent = '' <bar>
\ for syn_id in synstack(line('.'), col('.')) <bar>
\ 	echo indent.'<'.synIDattr(syn_id,"name").'>' <bar>
\ 	let indent .= ' ' <bar>
\ endfor <bar>
\ unlet indent<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" moving between tabs and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smart way to move btw. windows
"map <C-j> <C-W>j
"map <C-k> <C-W>k
"map <C-h> <C-W>h
"map <C-l> <C-W>l

if !has("win32")
    map z] gt
    map z[ gT
else
    map <C-Tab> gt
    map <S-Tab> gT
endif

map <right> :if &buftype != "nofile"<cr>:bn<cr>:endif<cr><cr>
map <left>  :if &buftype != "nofile"<cr>:bp<cr>:endif<cr><cr>

" Tab configuration
map <Leader>tn :tabnew<cr>
map <Leader>te :tabedit
map <Leader>tc :tabclose<cr>
map <Leader>tm :tabmove

" When pressing <leader>cd switch to the directory of the open buffer
map <Leader>cd :cd %:p:h<cr>

" faster creation of new tabs
" map <C-T> :tabnew<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Compile'n'fix settings

map <silent><Leader>ma :make -j<CR>

"open the quickfix list and place it in the bottom of the screen
map <silent><Leader>co :copen<CR> <C-W>J 
map <silent><Leader>cl :cclose<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Plugin key mappings
let g:CommandTMatchWindowAtTop = 1
let g:CommandTCancelMap=['<C-x>', '<Esc>']
"unmap! <Leader>t
"unmap! <Leader>b
nnoremap <leader>ct :CommandT<CR>
nnoremap <leader>cb :CommandTBuffer<CR>
nnoremap <leader>cj :CommandTJump<CR>
nnoremap <leader>cg :CommandTTag<CR>
nnoremap <leader>cf :CommandTFlush<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fuzzy finder keys

map <silent><Leader>ma :make -j12<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"nerd tree 
nmap <Leader>nt		:NERDTreeToggle<CR>
let NERDTreeShowHidden=1
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.py\$class$', '\.obj$',
            \ '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$']


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fuzzy finder keys

nmap <silent> <Leader>ff	:FufFile<CR>
nmap <silent> <Leader>fd	:FufDir<CR>
nmap <silent> <Leader>fco	:FufCoverageFile<CR>

nmap <silent> <Leader>fbu 	:FufBuffer<CR>

nmap <silent> <Leader>fbd	:FufBookmarkDir<CR>
nmap <silent> <Leader>fba 	:FufBookmarkDirAdd<CR>

nmap <silent> <Leader>fmf   :FufMruFile<CR>
nmap <silent> <Leader>fmc   :FufMruCmd<CR>

nmap <silent> <Leader>fta   :FufTag<CR>
nmap <silent> <Leader>fbt   :FufBufferTag<CR>
nmap <silent> <Leader>ftf   :FufTaggedFile<CR>

nmap <silent> <Leader>fj    :FufJumpList<CR>
nmap <silent> <Leader>fch   :FufChangeList<CR>
nmap <silent> <Leader>fq    :FufQuickfix<CR>
nmap <silent> <Leader>fl    :FufLine<CR>
nmap <silent> <Leader>fh    :FufHelp<CR>

" turn on MRU and MRU cmds modes by default
let g:fuf_modesDisable = []   
let g:fuf_coveragefile_exclude = '\v\~$|\.(o|exe|dll|bak|orig|swp)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Bufexplorer settings
let g:bufExplorerSplitVertSize=10

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ctags
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <F8> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --exclude=".*.html" --languages=C++,C,Python .<CR> " 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Statusline
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Always show the statusline
set laststatus=2

" Format the statusline
set statusline=\ %{HasPaste()}\ \ %F\ \ %m%r%w%q\ \ CWD:\ %{CurDir()}\ \ \ Line:\ %l/%L:%c


function! CurDir()
    let curdir = substitute(getcwd(), '/Users/guardian/', "~/", "g")
    return curdir
endfunction

function! HasPaste()
    if &paste
        return '[PASTE]  '
    else
        return ''
    endif
endfunction

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Development settings {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 'Shell cmd args...' will show shell cmd in a scratch buffer
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
function! s:RunShellCommand(cmdline)
    echo a:cmdline
    let expanded_cmdline = a:cmdline
        for part in split(a:cmdline, ' ')
            if part[0] =~ '\v[%#<]'
                let expanded_part = fnameescape(expand(part))
                let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
            endif
        endfor
    botright new
    setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
    call setline(1, 'You entered:    ' . a:cmdline)
    call setline(2, 'Expanded Form:  ' .expanded_cmdline)
    call setline(3,substitute(getline(2),'.','=','g'))
    execute '$read !'. expanded_cmdline
    setlocal nomodifiable
    1
endfunction

if has("mac") || has("unix")
    if &shell == "/bin/bash"
        " this will make bash to read config file on startup
        set shellcmdflag=-login\ -c
    endif
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Development settings {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"FSwitch to jump between header and source
nnoremap <silent>,jh :FSLeft<CR>
nnoremap <silent>,jj :FSHere<CR>
nnoremap <silent>,jk :FSRight<CR>

function! SetAutochDir()
    if &buftype == ""
        setlocal autochdir
    endif
endfunction
au BufEnter  * call SetAutochDir()

augroup prog
    "echo 123
    "au!
    au BufRead *.c,*.cc,*.cpp,*.h,*.java set formatoptions=croql cindent nowrap nofoldenable

    " Don't expand tabs to spaces in Makefiles
    au BufEnter  [Mm]akefile*  set noet
    au BufLeave  [Mm]akefile*  set et

    " Set up folding for python
    au FileType python setlocal foldenable foldmethod=indent keywordprg=pydoc
    if has("mac")
        au FileType python set keywordprg=~/.scripts/yandex-find.py\ python
    elseif !has("win32")
        au FileType python set keywordprg=pydoc
    endif

    au FileType html set foldenable foldmethod=indent noautoindent

    " Cpp
    au BufNewFile,BufRead,BufEnter *.cpp,*.hpp setlocal omnifunc=omni#cpp#complete#Main

    let OmniCpp_NamespaceSearch = 1
    let OmniCpp_GlobalScopeSearch = 1
    let OmniCpp_ShowAccess = 1
    let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
    let OmniCpp_MayCompleteDot = 1 " autocomplete after .
    let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
    let OmniCpp_MayCompleteScope = 0 " autocomplete after ::
    let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
    " automatically open and close the popup menu / preview window
    au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
    set completeopt=menuone,menu,longest,preview
augroup END
" }}}


" Reread configuration of Vim if .vimrc is saved {{{
augroup VimConfig
    au!
    "autocmd BufWritePost ~/.vimrc       so ~/.vimrc
    autocmd BufWritePost .vimrc         so ~/.vimrc
    autocmd BufWritePost vimrc          so ~/.vimrc
augroup END
" }}}

command! CloseHiddenBuffers call s:CloseHiddenBuffers()
function! s:CloseHiddenBuffers()
    let open_buffers = []

    for i in range(tabpagenr('$'))
        call extend(open_buffers, tabpagebuflist(i + 1))
    endfor

    for num in range(1, bufnr("$") + 1)
        if buflisted(num) && index(open_buffers, num) == -1
            exec "bdelete ".num
        endif
    endfor
endfunction


let tmp_dir=vimfiles_dir.'.tmp/'
let tag_dir=tmp_dir.'tags/'
let s:cpp_tag_dir=tag_dir.'cpp/'

if exists('*mkdir')
    if !isdirectory(tmp_dir)
        call mkdir(tmp_dir)
    endif

    if !isdirectory(tag_dir)
        call mkdir(tag_dir)
    endif
endif

set noswapfile
" то же самое для бэкапов
set nobackup      " keep a backup file


" то же самое для undo
if version >= 703
    set undofile
    let undo_dir=tmp_dir.'undofiles'

    if !isdirectory(undo_dir) && exists('*mkdir')
        call mkdir(undo_dir)
    endif

    if isdirectory(undo_dir)
        let &undodir=undo_dir.'/'
    endif
endif

" Use Ack for searching
if executable("ack-grep")
    set grepprg=ack-grep\ -H
elseif executable("ack")
    set grepprg=ack\ -H
    "set grepprg=ack\ -H\ --nogroup\ --nocolor\ --ignore-dir=tmp\ --ignore-dir=coverage
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" tagbar plugin
""
"nmap <silent> <Leader>tb	 :TagbarOpenAutoClose<CR>
"let g:tagbar_autoclose=1
"let g:tagbar_autoshowtag = 1

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" project plugin configuration
"nmap <silent> <F9> <Plug>ToggleProject
"let g:proj_flags="bcimsSLT"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Minibuf explorer
"let g:miniBufExplModSelTarget = 1
"let g:miniBufExplorerMoreThanOne = 1
"let g:miniBufExplMapCTabSwitchWindows = 1
"let g:miniBufExplUseSingleClick = 1
"hi link MBEVisibleChangedActive Keyword 
"let g:miniBufExplMapWindowNavVim = 0
"let g:miniBufExplVSplit = 25
"let g:miniBufExplSplitBelow=0

"let g:bufExplorerSortBy = "name"

" autocmd BufRead,BufNew :call UMiniBufExplorer

"map <silent> <leader>u :TMiniBufExplorer<cr>