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
if has("mac") && &term == "xterm"
    set t_Co=8
else
    set t_Co=256
endif

call pathogen#infect()

set nocompatible

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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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 hlsearch 	" highlight found items
set incsearch " incremental search
set ic " case insensitive search

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 ; :

map <C-l> <esc>2zo
map <C-h> <esc>2zc

"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

function! ToggleSlowConnection( )
    if &ttyfast
        set nottyfast
        echo "Setting slow terminal connection"
    else
        set ttyfast
        echo "Setting fast terminal connection"
    endif
endfunction
map <silent><F4> :call ToggleSlowConnection()<CR>


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

"#if has("gui")
"#    set bg=dark
"#else
"#    set bg=light
"#endif
"colorscheme solarized
colorscheme mustang
"colorscheme molokai


set lazyredraw
set guioptions-=T " no toolbar

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

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


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" No error sounds or visual blinking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
":call Errorbells_off("beep") -- turns off beeps
":call Errorbells_off("flash") -- turns off flashes
":call Errorbells_off() -- turns off both

function! Errorbells_off(...)
  " control Vim's audio and visual warnings
  " * Arguments:
  " "beep": turn off just beeping
  " "flash": turn off just flashing
  " (empty): both off
  " * Must be initialized after the GUI starts!
  " off
  if a:0 == 0
    let myeb = ""
  else
    let myeb = a:1
  endif
  if myeb ==? "flash"
    " audibly beep on error messages
    set errorbells
    " Screen flash on error (See also 't_vb')
    set novisualbell
    set t_vb=
  elseif myeb ==? "beep"
    " audibly beep on error messages
    set noerrorbells
    " Screen flash on error (See also 't_vb')
    set visualbell
    set t_vb&
  elseif myeb ==? ""
    " audibly beep on error messages
    set noerrorbells
    " Screen flash on error (See also 't_vb')
    set visualbell
    set t_vb=
  endif
endfunction

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 <F2> gT
    map <F3> 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>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Plugin key mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

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

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" taskbar 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"

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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)($|[/\\])'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Minibuffer explorer configuration

"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>


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

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Copying to system buffer on MAC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("mac")
    map <F5> :!pbcopy<CR>u
endif

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

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


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

function! HasPaste()
    if &paste
        return 'PASTE MODE  '
    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 {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

augroup prog
    "echo 123
    "au!
    au BufRead *.c,*.cc,*.cpp,*.h,*.java set formatoptions=croql cindent nowrap nofoldenable
    au BufEnter *.java      map <C-Return> :w\|:!javac %<CR>
    au BufEnter *.c         map <C-Return> :w\|:!gcc %<CR>
    au BufEnter *.cc,*.cpp  map <C-Return> :w\|:!g++ %<CR>
    au BufLeave *.java,*.c,*.cc unmap <C-Return>

    " 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 set 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 = 1 " 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