-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting_vimrc
504 lines (412 loc) · 13.5 KB
/
setting_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
"Use Vim settings, rather then Vi settings (much better!).
"This must be first, because it changes other options as a side effect.
set nocompatible
"load ftplugins and indent files
filetype plugin on
filetype indent on
"turn on syntax highlighting
syntax on
"allow backspacing over everything in insert mode
set backspace=indent,eol,start
"store lots of :cmdline history
set history=1000
set showcmd "show incomplete cmds down the bottom
set showmode "show current mode down the bottom
set incsearch "find the next match as we type the search
set hlsearch "hilight searches by default
set number "add line numbers
set showbreak=...
set wrap linebreak nolist ruler
"The default leader is '\', but many people prefer ',' as it's in a standard
""location
let mapleader = ','
au BufWinLeave * silent! mkview "make vim save view (state) (folds, cursor, etc)
au BufWinEnter * silent! loadview "make vim load view (state) (folds, cursor, etc)
"add some line space for easy reading
set linespace=4
"disable visual bell
set visualbell t_vb=
"try to make possible to navigate within lines of wrapped lines
nmap <Down> gj
nmap <Up> gk
set fo=l
"statusline setup
set statusline=%t "tail of the filename
"Git
set statusline+=%{fugitive#statusline()}
"set statusline+=\ [%{getcwd()}] " current dir
"RVM
set statusline+=%{exists('g:loaded_rvm')?rvm#statusline():''}
set statusline+=%= "left/right separator
set statusline+=%c, "cursor column
set statusline+=%l/%L "cursor line/total lines
set statusline+=\ %P "percent through file
set laststatus=2
"turn off needless toolbar on gvim/mvim
set guioptions-=T
"recalculate the trailing whitespace warning when idle, and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
"return '[\s]' if trailing white space is detected
"return '' otherwise
function! StatuslineTrailingSpaceWarning()
if !exists("b:statusline_trailing_space_warning")
if search('\s\+$', 'nw') != 0
let b:statusline_trailing_space_warning = '[\s]'
else
let b:statusline_trailing_space_warning = ''
endif
endif
return b:statusline_trailing_space_warning
endfunction
"return the syntax highlight group under the cursor ''
function! StatuslineCurrentHighlight()
let name = synIDattr(synID(line('.'),col('.'),1),'name')
if name == ''
return ''
else
return '[' . name . ']'
endif
endfunction
"recalculate the tab warning flag when idle and after writing
autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
"return '[&et]' if &et is set wrong
"return '[mixed-indenting]' if spaces and tabs are used to indent
"return an empty string if everything is fine
function! StatuslineTabWarning()
if !exists("b:statusline_tab_warning")
let tabs = search('^\t', 'nw') != 0
let spaces = search('^ ', 'nw') != 0
if tabs && spaces
let b:statusline_tab_warning = '[mixed-indenting]'
elseif (spaces && !&et) || (tabs && &et)
let b:statusline_tab_warning = '[&et]'
else
let b:statusline_tab_warning = ''
endif
endif
return b:statusline_tab_warning
endfunction
"recalculate the long line warning when idle and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
"return a warning for "long lines" where "long" is either &textwidth or 80 (if
"no &textwidth is set)
"
"return '' if no long lines
"return '[#x,my,$z] if long lines are found, were x is the number of long
"lines, y is the median length of the long lines and z is the length of the
"longest line
function! StatuslineLongLineWarning()
if !exists("b:statusline_long_line_warning")
let long_line_lens = s:LongLines()
if len(long_line_lens) > 0
let b:statusline_long_line_warning = "[" .
\ '#' . len(long_line_lens) . "," .
\ 'm' . s:Median(long_line_lens) . "," .
\ '$' . max(long_line_lens) . "]"
else
let b:statusline_long_line_warning = ""
endif
endif
return b:statusline_long_line_warning
endfunction
"return a list containing the lengths of the long lines in this buffer
function! s:LongLines()
let threshold = (&tw ? &tw : 80)
let spaces = repeat(" ", &ts)
let long_line_lens = []
let i = 1
while i <= line("$")
let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
if len > threshold
call add(long_line_lens, len)
endif
let i += 1
endwhile
return long_line_lens
endfunction
"find the median of the given array of numbers
function! s:Median(nums)
let nums = sort(a:nums)
let l = len(nums)
if l % 2 == 1
let i = (l-1) / 2
return nums[i]
else
return (nums[l/2] + nums[(l/2)-1]) / 2
endif
endfunction
"indent settings
set shiftwidth=2
set softtabstop=2
set expandtab
set autoindent
"folding settings
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default
set wildmode=list:longest "make cmdline tab completion similar to bash
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
"display tabs and trailing spaces
"set list
"set listchars=tab:\ \ ,extends:>,precedes:<
" disabling list because it interferes with soft wrap
set formatoptions-=o "dont continue comments when pushing o/O
"vertical/horizontal scroll off settings
set scrolloff=3
set sidescrolloff=7
set sidescroll=1
"some stuff to get the mouse going in term
set mouse=a
set ttymouse=xterm2
"hide buffers when not displayed
set hidden
"Command-T configuration
let g:CommandTMaxHeight=10
let g:CommandTMatchWindowAtTop=1
if has("gui_running")
"tell the term has 256 colors
set t_Co=256
colorscheme railscasts
set guitablabel=%M%t
set lines=45
set columns=165
if has("gui_gnome")
set term=gnome-256color
colorscheme railscasts
set guifont=Monospace\ Bold\ 12
endif
if has("gui_mac") || has("gui_macvim")
set guifont=Menlo:h14
" key binding for Command-T to behave properly
" uncomment to replace the Mac Command-T key to Command-T plugin
"macmenu &File.New\ Tab key=<nop>
map <C-t> :CommandT<CR>
" make Mac's Option key behave as the Meta key
set invmmta
try
set transparency=5
catch
endtry
endif
if has("gui_win32") || has("gui_win32s")
set guifont=Consolas:h12
set enc=utf-8
endif
else
"dont load csapprox if there is no gui support - silences an annoying warning
let g:CSApprox_loaded = 1
"set railscasts colorscheme when running vim in gnome terminal
if $COLORTERM == 'gnome-terminal'
set term=gnome-256color
colorscheme railscasts
else
colorscheme default
endif
endif
" PeepOpen uses <Leader>p as well so you will need to redefine it so something
" else in your ~/.vimrc file, such as:
" nmap <silent> <Leader>q <Plug>PeepOpen
let NERDTreeIgnore = ['\.lo$', '\.la$', '\.slo$']
silent! nmap <silent> <C-e> :NERDTreeToggle<CR>
"make <c-l> clear the highlight as well as redraw
nnoremap <C-L> :nohls<CR><C-L>
inoremap <C-L> <C-O>:nohls<CR>
"map to bufexplorer
nnoremap <silent> <F2> :BufExplorer<cr>
"map to CommandT TextMate style finder
nnoremap <leader>T :CommandT<CR>
"map Q to something useful
noremap Q gq
"make Y consistent with C and D
nnoremap Y y$
"bindings for ragtag
inoremap <M-o> <Esc>o
inoremap <C-j> <Down>
let g:ragtag_global_maps = 1
"mark syntax errors with :signs
let g:syntastic_enable_signs=1
"key mapping for vimgrep result navigation
map <A-o> :copen<CR>
map <A-q> :cclose<CR>
map <A-j> :cnext<CR>
map <A-k> :cprevious<CR>
"visual search mappings
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
"jump to last cursor position when opening a file
"dont do it when writing a commit log entry
autocmd BufReadPost * call SetCursorPosition()
function! SetCursorPosition()
if &filetype !~ 'commit\c'
if line("'\"") > 0 && line("'\"") <= line("$")
exe "normal! g`\""
normal! zz
endif
end
endfunction
"define :HighlightLongLines command to highlight the offending parts of
"lines that are longer than the specified length (defaulting to 80)
command! -nargs=? HighlightLongLines call s:HighlightLongLines('<args>')
function! s:HighlightLongLines(width)
let targetWidth = a:width != '' ? a:width : 79
if targetWidth > 0
exec 'match Todo /\%>' . (targetWidth) . 'v/'
else
echomsg "Usage: HighlightLongLines [natural number]"
endif
endfunction
"key mapping for window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
"key mapping for saving file
nmap <C-s> :w<CR>
"key mapping for tab navigation
nmap <Tab> gt
nmap <S-Tab> gT
"Key mapping for textmate-like indentation
nmap <D-[> <<
nmap <D-]> >>
vmap <D-[> <gv
vmap <D-]> >gv
let ScreenShot = {'Icon':0, 'Credits':0, 'force_background':'#FFFFFF'}
""""""""""""""""""""""""""""""""
" bash key binding "
""""""""""""""""""""""""""""""""
"enable key binding of bash in command mode
cmap <c-a> <home>
cmap <c-e> <end>
""""""""""""""""""""""""""""""""
" taglist "
""""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
set tags+=tags
let Tlist_Show_One_File = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_Use_Right_Window = 1
nnoremap <silent> <F7> :TlistToggle<CR>
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" 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 on
filetype plugin on
filetype indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" 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).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
"vimdiff
if &diff
colorscheme blue
endif
set diffopt+=iwhite
""""""""""""""""""""""""""""""""""""""""""
" xptemplate "
""""""""""""""""""""""""""""""""""""""""""
" avoid key conflict
let g:SuperTabMappingForward = '<Plug>supertabKey'
" if nothing matched in xpt, try supertab
let g:xptemplate_fallback = '<Plug>supertabKey'
" xpt uses <Tab> as trigger key
"let g:xptemplate_key = '<Tab>'
" " use <tab>/<S-tab> to navigate through pum. Optional
" let g:xptemplate_pum_tab_nav = 1
" " xpt triggers only when you typed whole name of a snippet. Optional
" let g:xptemplate_minimal_prefix = 'full'
let g:xptemplate_vars="SParg=&[email protected]&$author=mingxiang.zhang&$copyright=atlantis.jp"
let g:xptemplate_brace_complete = ''
" bufexplorer configuration
" only show buffers for this tab, not all buffers
let g:bufExplorerShowTabBuffer=1
""""""""""""""""""""""""""""""""""""""""""""
" NERDTree "
""""""""""""""""""""""""""""""""""""""""""""
let NERDTreeIgnore += ['\.pyc$', '\.orig']
" not working ---- maximize window and return to previouse split structure "
nnoremap <C-W>o :call MaximizeToggle()<CR>
nnoremap <C-W><C-O> :call MaximizeToggle()<CR>
function! MaximizeToggle()
if exists("s:maximize_session")
exec "source " . s:maximize_session
call delete(s:maximize_session)
unlet s:maximize_session
let &hidden=s:maximize_hidden_save
unlet s:maximize_hidden_save
else
let s:maximize_hidden_save = &hidden
let s:maximize_session = tempname()
set hidden
exec "mksession! " . s:maximize_session
only
endif
endfunction
"gundo
map <leader>g :GundoToggle<CR>
"pyflakes
let g:pyflakes_use_quickfix = 0
"python pep8
let g:pep8_map='<leader>8'
"rope
map <leader>j :RopeGotoDefinition<CR>
map <leader>r :RopeRename<CR>
" Add the virtualenv's site-packages to vim path
py << EOF
import os.path
import sys
import vim
if 'VIRTUAL_ENV' in os.environ:
project_base_dir = os.environ['VIRTUAL_ENV']
sys.path.insert(0, project_base_dir)
activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
EOF
" used by vimdiff
if &diff
set t_Co=256
set background=dark
colorscheme blue
endif
function! DiffWithFileFromDisk()
let filename=expand('%')
let nopathfilename=expand('%:t')
let diffname = '/tmp/'.nopathfilename.'.fileFromBuffer'
exec 'saveas! '.diffname
diffthis
vsplit
exec 'edit '.filename
diffthis
endfunction
:nmap <F6> :call DiffWithFileFromDisk()<cr>
if system('uname')=~'Darwin'
let s:clang_library_path='/Library/Developer/CommandLineTools/usr/lib'
if isdirectory(s:clang_library_path)
let g:clang_library_path=s:clang_library_path
endif
endif
set backupdir=~/tmp/vim/
set directory=~/tmp/vim/