-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
executable file
·432 lines (343 loc) · 11.4 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
set langmenu=ru_RU.UTF-8
set runtimepath=~/.vim,$VIMRUNTIME
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set showcmd " display incomplete commands
set incsearch " do incremental searching
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Load matchit (% to bounce from do to end, etc.)
runtime! macros/matchit.vim
" Only do this part when compiled with support for autocommands.
if has("autocmd")
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
"au FocusLost * :wa " save all on tabbing out of vim
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
augroup myfiletypes
" Clear old autocmds in group
autocmd!
" autoindent with two spaces, always expand tabs
autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 et
augroup END
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
"augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" end of standard stuff from vim distribution ==================================
" using pathogen. Tim, I love you!
filetype off
"call pathogen#helptags()
"call pathogen#runtime_append_all_bundles()
execute pathogen#infect()
filetype plugin indent on
" Functions ====================================================================
" tabs moving
function! MoveTabLeft()
let current_tab = tabpagenr()
if current_tab > 1
let current_tab = current_tab - 2
execute 'tabmove' current_tab
endif
endfunction
function! MoveTabRight()
let current_tab = tabpagenr()
execute 'tabmove' current_tab
endfunction
map <S-M-Left> :call MoveTabLeft()<CR>
map <S-M-Right> :call MoveTabRight()<CR>
" sudo writes
command! -nargs=0 -bang SudoSave :silent! w !sudo tee % &>/dev/null
cmap w!! w !sudo tee % >/dev/null
" Plugins ======================================================================
" Diable netrw
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
" plug lusty
map <Leader><Space> :LustyJuggler<CR>
let g:loaded_lustyexplorer = "I don't need LustyExplorer"
" plug CommandT
let g:CommandTMatchWindowAtTop=0
let g:CommandTMaxHeight=10
set wildignore+=*.class,*.o,.git,.svn,*.png,*.jpg
" plug TagList
"let Tlist_Ctags_Cmd = "/usr/local/bin/ctags"
""let Tlist_Show_One_File = 1
"let Tlist_Auto_Highlight_Tag = 1
"let Tlist_File_Fold_Auto_Close = 1
"let Tlist_Auto_Update = 1
"let Tlist_Display_Prototype = 0
"let Tlist_Display_Tag_Scope = 1
"let Tlist_Enable_Fold_Column = 1
"let Tlist_Exit_OnlyWindow =1
"let Tlist_GainFocus_On_ToggleOpen = 1
"let Tlist_Highlight_Tag_On_BufEnter = 0
"let Tlist_Process_File_Always = 0
"let Tlist_Show_Menu = 1
"let Tlist_Sort_Type = "name"
"let Tlist_Use_Right_Window = 1
"let Tlist_Use_SingleClick=1
"let Tlist_Inc_Winwidth=1
"let Tlist_File_Fold_Auto_Close = 1
"set title titlestring=%<%f\ %{tagbar#currenttag('[%s] ','')}
nmap <silent> <F4> :TagbarToggle<CR>
imap <silent> <F4> <Esc>:TagbarToggle<CR>i
"plug Project
let g:proj_flags="mst"
"plug NERD Commenter - XCode-like comments toggling
nmap <D-/> <Leader>c<space><Down>
vnoremap <D-/> <Esc><Leader>c<space>gv
"plug NERD Tree
let NERDChristmasTree = 1
let NERDTreeHijackNetrw = 0
let NERDTreeAutoCenter = 1
let NERDTreeChDirMode = 2
let NERDTreeShowBookmarks = 1
let NERDTreeShowHidden = 1
let NERDTreeMouseMode = 2
let g:NERDTreeMapPreview = '<Right>'
nmap <silent> <F3> :NERDTreeToggle<CR>
imap <silent> <F3> <Esc>:NERDTreeToggle<CR>i
" settings =======================================================
" mine customized one, based on desert
colorscheme kalisi
set diffopt=filler,vertical
" status line format with mapping indicator
set statusline=%<%n\|%f%h%1*%m%*%r%y%=%1*%k%*\ off=%o\ \ %l,%c%V\ %P
highlight User1 term=bold cterm=bold ctermfg=red ctermbg=white guifg=red guibg=white
set laststatus=2
set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz
"set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
" red cursor for alternate map
highlight lCursor guifg=NONE guibg=red
" recreate deleted files
autocmd FileChangedShell * if v:fcs_reason == 'deleted' | set modified | endif
" do not keep a backup files, use version control systems instead
set nobackup
set noswapfile
set cmdheight=2
set shortmess=aoOtTIA
"folding
set foldenable " enable folding
set foldcolumn=4 " add a fold column
set foldmethod=marker " detect triple-{ style fold markers
set foldlevelstart=99 " start out with everything unfolded
set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo
" which commands trigger auto-unfold
set background=dark
" redraw rarely
set lazyredraw
" show line numbers, exclude help
set number
autocmd! filetype help setlocal nonumber
" use wildmenu ...
set wildmenu
" ... with completion
set wildcharm=<TAB>
" reapply config after save
autocmd! bufwritepost .vimrc source $MYVIMRC
highlight WrongSpaces guibg=Grey40
" highlight trailing spaces
au BufNewFile,BufRead * let b:mtrailingws=matchadd('WrongSpaces', '\s\+$', -1)
" highlight tabs between spaces
au BufNewFile,BufRead * let b:mtabbeforesp=matchadd('WrongSpaces', '\v(\t+)\ze( +)', -1)
au BufNewFile,BufRead * let b:mtabaftersp=matchadd('WrongSpaces', '\v( +)\zs(\t+)', -1)
" make shebangs executable
au BufWritePost * if getline(1) =~ "^#!" | silent !chmod a+x <afile> | endif
" restart Passenger app
au BufWritePost * silent !test -f 'tmp/restart.txt' && touch 'tmp/restart.txt'
autocmd filetype java set noexpandtab
" ignore case in search pattern
set ignorecase
" but don't ignore for mixedcase pattern
set smartcase
" tab is 4 spaces
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set smarttab
" show at least n lines around cursor
set scrolloff=2
set sidescrolloff=2
" save all stuff to .viminfo
set viminfo+='1000,f1,<500,:1000,@1000,/1000,h,%
" and in session
set sessionoptions=curdir,folds,globals,help,localoptions,options,resize,winsize,winpos,tabpages
" enable mouse
set mouse=a
set mousemodel=popup_setpos
" break line after full word
set linebreak
" set terminal title
set title
" show matching brackets in insert mode
set showmatch
" set "" to "* (dafault to system)
set clipboard=unnamed
" plain text formatting
autocmd FileType text setlocal fo=atcroqn
autocmd FileType text setlocal textwidth=80
set autoindent
set smartindent
"vim 7.0 settings
set go=aegimrLtb
" keep spellchecker ready, but off by default
map <Leader>s :setlocal spell!<CR>
set nospell
set spelllang=ru_yo,en_us
set spellsuggest=best
set completeopt=menu,preview
" reread file after git checkout
set autoread
" Восстановление позиции курсора при повторном открытии файла
" set viewoptions=cursor,folds
" au BufWinLeave * mkview
" au BufWinEnter * silent loadview
" http://stevelosh.com/blog/2010/09/coming-home-to-vim/
" terminal's enc
set termencoding=utf-8
" all possible file encodings, internal vim's encoding
set fileencodings=ucs-bom,utf-8,cp1251,koi8-r,utf-16
set encoding=utf-8
" show modes, abandon buffers without questions, highlight line with cursor
set showmode
set hidden
set cursorline
" local usage, show pos in text, save undo across launches
set ttyfast
set ruler
set undofile
set undodir="~/.vim/undo"
" This turns off Vim’s crazy default regex characters and makes searches use normal regexes
"nnoremap / /\v
"vnoremap / /\v
" makes it easy to clear out a search
nnoremap <leader>/ :noh<cr>
" make the tab key match bracket pairs. I use this to move around all the time and
" <tab> is a hell of a lot easier to type than %
nnoremap <M-tab> %
vnoremap <M-tab> %
" wrap lines
set wrap
set formatoptions+="qrn"
" highlight 85'th column, exclude help
autocmd FileType help setlocal colorcolumn=""
set colorcolumn=85
hi ColorColumn ctermbg=lightgrey guibg=grey30
" Shortcut to rapidly toggle `set list`
nmap <leader>l :set list!<CR>
" highlight tabs and spaces, indicate presence of text around buffer
set listchars=tab:▸\ ,eol:¬,trail:-,precedes:<,extends:>
" turned off for security, I don't use it anyway
set modelines=0
" http://nvie.com/posts/how-i-boosted-my-vim/
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
set gdefault " search/replace 'globally' (on a line) by default
" http://writequit.org/blog/?p=195
" show full completion tags
set showfulltag
" do lots of scanning on tab completion
set complete=.,w,b,u,U,t,i,d
" Conflict markers {{{
" highlight conflict markers
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
" shortcut to jump to next conflict marker
nnoremap <silent> <leader>c /^\(<\\|=\\|>\)\{7\}\([^=].\+\)\?$<CR>
" }}}
" keybindings ==================================================================
" edit config
map <C-F12> :tabnew<Space>$MYVIMRC<CR>
" rebind F1 to Esc to never miss
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
" spell
nmap <F5> ]s
" line wrapping
nmap <S-F11> :set<Space>wrap!<CR>
imap <S-F11> <Esc>:set<Space>wrap!<CR>i
" paste formatted text
set pastetoggle=<M-F11>
" Insert mode completions
imap <C-Tab> <C-N>
imap <C-Space> <C-N>
" save
nmap <F2> :w<CR>
imap <F2> <Esc>:w<CR>a
nmap <S-F2> :wа<CR>
imap <S-F2> <Esc>:wа<CR>a
" more usable Page Up/Down
nmap <PageUp> <C-S-U><C-S-U>
imap <PageUp> <C-O><C-S-U><C-O><C-S-U>
nmap <PageDown> <C-S-D><C-S-D>
imap <PageDown> <C-O><C-S-D><C-O><C-S-D>
"smart home
nnoremap <silent><Home> :exe 'norm!' matchend(getline('.'),'^\s*')<col('.')-1 ? '^':'0'<CR>
imap <silent><Home> <C-O><Home>
"LESS like
nmap <BS> <C-S-U><C-S-U>
nmap <Space> <C-S-D><C-S-D>
" exit
map <F10> :q<CR>
imap <F10> <ESC>:q<CR>
map <S-F10> :tabclose<CR>
imap <S-F10> <ESC>:tabclose<CR>
" go to next/prev tab, useful in ssh+screen session to not interfer with iTerm's
" bindings
map <Leader>n :tabnext<CR>
map <Leader>p :tabprevious<CR>
map <S-Right> :tabnext<CR>
imap <S-Right> <Esc>:tabnext<CR>i
map <S-Left> :tabprevious<CR>
imap <S-Left> <Esc>:tabprevious<CR>i
"word-jump and selecting
nmap <M-Left> b
nmap <M-Right> e
imap <M-Left> <Esc>bi
imap <M-Right> <Esc>ea
imap <M-S-Left> <Esc>vb
imap <M-S-Right> <Esc>ve
" moving around splited windows
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
nnoremap <C-Left> <C-w>h
nnoremap <C-Down> <C-w>j
nnoremap <C-Up> <C-w>k
nnoremap <C-Right> <C-w>l
" visual last insert
map gv `[v`]
"nnoremap <leader>v V`]
" comment with Nerd Commenter
map <D-/> <Leader>c<Space>
vmap <D-/> <Leader>c<Space>
imap <D-/> <Esc><Leader>c<Space>i
nnoremap ; :