-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
533 lines (432 loc) · 12.3 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
" # [@petrh](http://github.com/petrh)'s vim configuration
"
" To use this vim configuration:
"
" 1. Clone the repository:
"
" git clone https://github.com/petrh/vimfiles.git ~/.vim
"
" 2. Download the plugin submodules:
"
" cd ~/.vim && git submodule init && git submodule update
"
" 3. Make sure Vim finds the vimrc file by either symlinking it:
"
" ln -s ~/.vim/vimrc ~/.vimrc
"
" or by sourcing it from your own `~/.vimrc`:
"
" source ~/.vim/vimrc
"
" Modeline and Notes {
" vim: set foldmarker={,} foldlevel=0 foldmethod=marker :
" }
" ## Bundles
" Using [Pathogen](https://github.com/tpope/vim-pathogen) package format for
" vim _packages_.
" Call infect to get the bundle handling started
call pathogen#infect()
" ## Basic Setup
" Use vim, not vi defaults.
set nocompatible
" Set default encoding to UTF-8.
set encoding=utf-8
" Show line numbers.
set number
" Show line and column number.
set ruler
" Turn on syntax highlighting allowing local overrides.
syntax on
" ### Whitespace
" Don't wrap lines.
set nowrap
" Highligh all characters past 78 columns.
augroup vimrc_autocmds
autocmd BufEnter * highlight OverLength ctermbg=darkred guibg=#FFD9D9
autocmd BufEnter * match OverLength /\%78v.*/
augroup END
" Use 2 spaces for indentation.
set shiftwidth=2
set tabstop=2
set softtabstop=2
set expandtab
" Show invisible characters.
set list
" Backspace through everything in insert mode.
set backspace=indent,eol,start
" List chars
set listchars="" " Reset the listchars
"set listchars=tab:\ \ a tab should display as " ", trailing whitespace as "."
set listchars=tab:▸\ " a tab should display as "▸"
set listchars+=trail:· " show trailing spaces as "·"
"set listchars+=eol:¬
set listchars+=extends:◄ " The character to show in the last column when wrap is off and the line continues beyond the right of the screen
set listchars+=precedes:► " The character to show in the last column when wrap is off and the line continues beyond the right of the screen
" ### Searching
" Highlight search matches.
set hlsearch
" Use incremental search.
set incsearch
" Search is case insensitive...
set ignorecase
" ...unless it contains at least one capital letter
set smartcase
" ### Wild settings
" TODO: Investigate the precise meaning of these settings
" set wildmode=list:longest,list:full
" Disable output and VCS files.
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
" Disable archive files.
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
" Disable bundler and sass cache.
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
" Disable temp and backup files.
set wildignore+=*.swp,*~,._*
" ### Backup and swap files
" No backup files.
set nobackup
" No swap files.
set noswapfile
" ## Autocommands
if has("autocmd")
if exists("g:autosave_on_blur")
au FocusLost * silent! wall
endif
endif
" ## Filetypes
" Some file types should wrap their text
function! s:setupWrapping()
set wrap
set linebreak
set textwidth=72
set nolist
endfunction
filetype plugin indent on " Turn on filetype plugins (:help filetype-plugin)
if has("autocmd")
" In Makefiles, use real tabs, not tabs expanded to spaces
au FileType make set noexpandtab
" Make sure all Markdown files have the correct filetype set and setup wrapping
au BufNewFile,BufRead *.{md,markdown,mdown,mkd,mkdn,txt,tex} setf markdown | call s:setupWrapping()
" Treat JSON files like JavaScript
au BufNewFile,BufRead *.json set ft=javascript
" Make Python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ )
au FileType python set softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79
" Enable autoindent for Dart
au FileType dart set autoindent
" Remember last location in file, but not for commit messages.
au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g`\"" | endif
" Switch to working directory of the open file
au BufEnter * if expand('%:p') !~ '://' | cd %:p:h | endif
endif
" ## User interface
" Command line
if has('cmdline_info')
set ruler
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%)
set showcmd
endif
" Status bar
if has('statusline')
set laststatus=2
" Broken down into easily includeable segments
set statusline=%<%f\ " Filename
set statusline+=%w%h%m%r " Options
"set statusline+=%{fugitive#statusline()} " Git Hotness
"set statusline+=\ [%{&ff}/%Y] " filetype
"set statusline+=\ [%{getcwd()}] " current dir
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_enable_signs=1
set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info
endif
if exists("g:enable_mvim_shift_arrow")
let macvim_hig_shift_movement = 1 " mvim shift-arrow-keys
endif
" Graphical user interface
color molokai
if has("gui_running")
" Use nice fonts
set guifont=Menlo\ 9
" Start without the toolbar
set guioptions-=T
" Start without the menu
set guioptions-=m
" Default color scheme
color molokai
if has("autocmd")
" Automatically resize splits when resizing MacVim window
autocmd VimResized * wincmd =
endif
if has("gui_macvim")
macmenu &File.New\ Tab key=<D-S-t>
endif
endif
" ## Mappings
" ### General Mappings (Normal, Visual, Operator-pending)
" use :w!! to write to a file using sudo if you forgot to 'sudo vim file'
" (it will prompt for sudo password when writing)
cmap w!! %!sudo tee > /dev/null %
" Toggle paste mode
nmap <silent> <F4> :set invpaste<CR>:set paste?<CR>
imap <silent> <F4> <ESC>:set invpaste<CR>:set paste?<CR>
" Set the keys to turn spell checking on/off
nmap <silent> <F8> <Esc>:setlocal spell spelllang=en_us<CR>
nmap <silent> <S-F8> <Esc>:setlocal nospell<CR>
" format the entire file
nmap <leader>fef ggVG=
" upper/lower word
nmap <leader>u mQviwU`Q
nmap <leader>l mQviwu`Q
" upper/lower first char of word
nmap <leader>U mQgewvU`Q
nmap <leader>L mQgewvu`Q
" cd to the directory containing the file in the buffer
nmap <silent> <leader>cd :lcd %:h<CR>
" Create the directory containing the file in the buffer
nmap <silent> <leader>md :!mkdir -p %:p:h<CR>
" Some helpers to edit mode
" http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%
" Swap two words
nmap <silent> gw :s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<CR>`'
" Underline the current line with '='
nmap <silent> <leader>ul :t.\|s/./=/g\|:nohls<cr>
" set text wrapping toggles
nmap <silent> <leader>tw :set invwrap<CR>:set wrap?<CR>
" find merge conflict markers
nmap <silent> <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
" Map the arrow keys to be based on display lines, not physical lines
map <Down> gj
map <Up> gk
" Toggle hlsearch with <leader>hs
nmap <leader>hs :set hlsearch! hlsearch?<CR>
" Adjust viewports to the same size
map <Leader>= <C-w>=
if has("gui_macvim") && has("gui_running")
" Map command-[ and command-] to indenting or outdenting while keeping the original selection in visual mode
vmap <D-]> >gv
vmap <D-[> <gv
nmap <D-]> >>
nmap <D-[> <<
omap <D-]> >>
omap <D-[> <<
imap <D-]> <Esc>>>i
imap <D-[> <Esc><<i
" Bubble single lines
nmap <D-Up> [e
nmap <D-Down> ]e
nmap <D-k> [e
nmap <D-j> ]e
" Bubble multiple lines
vmap <D-Up> [egv
vmap <D-Down> ]egv
vmap <D-k> [egv
vmap <D-j> ]egv
" Map Command-# to switch tabs
map <D-0> 0gt
imap <D-0> <Esc>0gt
map <D-1> 1gt
imap <D-1> <Esc>1gt
map <D-2> 2gt
imap <D-2> <Esc>2gt
map <D-3> 3gt
imap <D-3> <Esc>3gt
map <D-4> 4gt
imap <D-4> <Esc>4gt
map <D-5> 5gt
imap <D-5> <Esc>5gt
map <D-6> 6gt
imap <D-6> <Esc>6gt
map <D-7> 7gt
imap <D-7> <Esc>7gt
map <D-8> 8gt
imap <D-8> <Esc>8gt
map <D-9> 9gt
imap <D-9> <Esc>9gt
else
" Map command-[ and command-] to indenting or outdenting while keeping the original selection in visual mode
vmap <A-]> >gv
vmap <A-[> <gv
nmap <A-]> >>
nmap <A-[> <<
omap <A-]> >>
omap <A-[> <<
imap <A-]> <Esc>>>i
imap <A-[> <Esc><<i
" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
nmap <C-k> [e
nmap <C-j> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
vmap <C-k> [egv
vmap <C-j> ]egv
" Make shift-insert work like in Xterm
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>
" Tab control
nnoremap <S-C-T> :tabnew<CR>
nnoremap <S-C-left> :tabprev<CR>
nnoremap <S-C-right> :tabnext<CR>
noremap <S-l> gt
nnoremap <S-h> gT
"map <C-W> :tabclose<CR>
" Map Control-# to switch tabs
map <C-0> 0gt
imap <C-0> <Esc>0gt
map <C-1> 1gt
imap <C-1> <Esc>1gt
map <C-2> 2gt
imap <C-2> <Esc>2gt
map <C-3> 3gt
imap <C-3> <Esc>3gt
map <C-4> 4gt
imap <C-4> <Esc>4gt
map <C-5> 5gt
imap <C-5> <Esc>5gt
map <C-6> 6gt
imap <C-6> <Esc>6gt
map <C-7> 7gt
imap <C-7> <Esc>7gt
map <C-8> 8gt
imap <C-8> <Esc>8gt
map <C-9> 9gt
imap <C-9> <Esc>9gt
endif
" ### Command-Line Mappings
" Insert the current directory into a command-line path
cmap <C-P> <C-R>=expand("%:p:h") . "/"<CR>
" ## Plugins
" ### Ack
if has("gui_macvim") && has("gui_running")
" Command-Shift-F on OSX
map <D-F> :Ack<space>
else
" Define <C-F> to a dummy value to see if it would set <C-f> as well.
map <C-F> :dummy
if maparg("<C-f>") == ":dummy"
" <leader>f on systems where <C-f> == <C-F>
map <leader>f :Ack<space>
else
" <C-F> if we can still map <C-f> to <S-Down>
map <C-F> :Ack<space>
endif
map <C-f> <S-Down>
endif
" ### CtrlP
let g:ctrlp_map = ''
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$',
\ 'file': '\.pyc$\|\.pyo$\|\.rbc$|\.rbo$\|\.class$\|\.o$\|\~$\',
\ }
if has("gui_macvim") && has("gui_running")
map <C-p> :CtrlP<CR>
imap <C-p> <ESC>:CtrlP<CR>
else
map <C-p> :CtrlP<CR>
imap <C-p> <ESC>:CtrlP<CR>
endif
" ### Fugitive
nmap <leader>gb :Gblame<CR>
nmap <leader>gs :Gstatus<CR>
nmap <leader>gd :Gdiff<CR>
nmap <leader>gl :Glog<CR>
nmap <leader>gc :Gcommit<CR>
nmap <leader>gp :Git push<CR>
" ### Gist
if executable("pbcopy")
" The copy command
let g:gist_clip_command = 'pbcopy'
elseif executable("xclip")
" The copy command
let g:gist_clip_command = 'xclip -selection clipboard'
elseif executable("putclip")
" The copy command
let g:gist_clip_command = 'putclip'
end
" Detect filetype if vim failed auto-detection
let g:gist_detect_filetype = 1
" ### Gundo
" Toggle Gundo
nmap <F5> :GundoToggle<CR>
imap <F5> <ESC>:GundoToggle<CR>
" ### NERDCommenter
if has("gui_macvim") && has("gui_running")
map <D-/> <plug>NERDCommenterToggle<CR>
imap <D-/> <ESC><plug>NERDCommenterToggle<CR>i
else
map <Leader>/ <plug>NERDCommenterToggle<CR>
imap <Leader>/ <ESC><plug>NERDCommenterToggle<CR>i
endif
" ### NERDTree
let NERDTreeIgnore=['\.pyc$', '\.pyo$', '\.rbc$', '\.rbo$', '\.class$', '\.o$', '\~$']
let NERDTreeHijackNetrw = 0
" Default mapping
map <F9> :NERDTreeToggle<CR>
augroup AuNERDTreeCmd
autocmd AuNERDTreeCmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
autocmd AuNERDTreeCmd FocusGained * call s:UpdateNERDTree()
" If the parameter is a directory, cd into it
function s:CdIfDirectory(directory)
let explicitDirectory = isdirectory(a:directory)
let directory = explicitDirectory || empty(a:directory)
if explicitDirectory
exe "cd " . fnameescape(a:directory)
endif
" Allows reading from stdin
" ex: git diff | mvim -R -
if strlen(a:directory) == 0
return
endif
if directory
NERDTree
wincmd p
bd
endif
if explicitDirectory
wincmd p
endif
endfunction
" NERDTree utility function
function s:UpdateNERDTree(...)
let stay = 0
if(exists("a:1"))
let stay = a:1
end
if exists("t:NERDTreeBufName")
let nr = bufwinnr(t:NERDTreeBufName)
if nr != -1
exe nr . "wincmd w"
exe substitute(mapcheck("R"), "<CR>", "", "")
if !stay
wincmd p
end
endif
endif
endfunction
" ### Syntastic
let g:syntastic_enable_signs = 1
let g:syntastic_quiet_warnings = 0
let g:syntastic_auto_loc_list = 2
" ### Tagbar
" Toggle Tagbar
nmap <F7> :TagbarToggle<CR>
imap <F7> <ESC>:TagbarToggle<CR>
" ### Unimpaired
" Normal Mode: Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
" Visual Mode: Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
" ### ZoomWin
" Map <Leader><Leader> to ZoomWin
map <Leader>zw :ZoomWin<CR>