-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
532 lines (428 loc) · 15.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
set nocompatible " Don't sacrifice anything for Vi compatibility.
set encoding=utf-8 " In case $LANG doesn't have a sensible value.
" pathogem.vim lets us keep plugins etc in their own folders under ~/.vim/bundle.
" http://www.vim.org/scripts/script.php?script_id=2332
" filetype off and then on again afterwards for ftdetect files to work properly.
filetype off
call pathogen#infect()
filetype plugin indent on " Load plugin and indent settings for the detected filetype.
syntax on " Syntax highlighting.
set number " Show gutter with line numbers.
set ruler " Show line, column and scroll info in status line.
set laststatus=2 " Always show status bar.
set modelines=10 " Use modeline overrides.
set showcmd " Show partially typed command sequences.
set scrolloff=3 " Minimal number of lines to always show above/below the caret.
set hidden " Allow unsaved buffers to be put in the background
set shellcmdflag=-lc " Shell is to act as a login shell thus setting the evironment properly
" set up colorscheme
colorscheme hybrid " Default color scheme.
set background=dark
" 2 spaces indent.
set softtabstop=2
set shiftwidth=2
set expandtab
" No pipes in vertical split separators.
set fillchars=vert:\
" Searching.
set hlsearch " Highlight results.
set incsearch " Search-as-you-type.
set ignorecase " Case-insensitive…
set smartcase " …unless phrase includes uppercase.
set nojoinspaces " 1 space, not 2, when joining sentences.
set backspace=indent,eol,start " Allow backspacing over everything in insert mode.
set nowrap " don't wrap for anything
set nosol " Do not move cursor to first non-blank of the line
" Leader
let mapleader = " "
let localleader = "\\"
" Set completion configration
set completeopt=menu,longest
" Set diff options
set diffopt+=vertical
" easy access to vim modifications
map <leader>re :execute "edit " . $MYVIMRC<CR>
map <leader>rs :execute "source " . $MYVIMRC<CR>
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,tmp,public/uploads,.vimtags,*.class,.DS_Store,.gradle
" Gundo configuration
nnoremap <F5> :GundoToggle<CR>
" Extradite configuration
nnoremap <F2> :Extradite<CR>
" Toggle paste
set pastetoggle=<F8>
" Move to the last change
nnoremap gl `.
" Easier buffer swapping
nnoremap <bs> <C-^>
" Toggle line numbering
set nonumber
set relativenumber
nnoremap <silent> <F7> :exe'se'&nu+&rnu?'rnu!':'nu'<CR>
" Quickreturn
inoremap <c-cr> <esc>A<cr>
inoremap <s-cr> <esc>A:<cr>
" Easy Macro Application
nnoremap Q @q
vnoremap Q :norm @q<cr>
" Proper command mode navigation
cnoremap <c-k> <up>
cnoremap <c-j> <down>
" Configure leader for easymotion
let g:EasyMotion_leader_key = '<Leader>m'
" Resize splits when the window is resized
au VimResized * exe "normal! \<c-w>="
" Remember last location in file, but not for commit messages.
if has("autocmd")
au BufReadPost * if &filetype !~ 'commit\c' && line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
" OS X only due to use of `open`. Adapted from
" http://vim.wikia.com/wiki/Open_a_web-browser_with_the_URL_in_the_current_line
" Uses John Gruber's URL regexp: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
if has("ruby")
ruby << EOF
def open_uri
re = %r{(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))}
line = VIM::Buffer.current.line
urls = line.scan(re).flatten
if urls.empty?
VIM::message("No URI found in line.")
else
system("open", *urls)
VIM::message(urls.join(" and "))
end
end
EOF
endif
" Hit S in command mode to save, as :w<CR> is a mouthful and MacVim
" Command-S is a bad habit when using terminal Vim.
" We overload a command, but use 'cc' instead anyway.
noremap S :w<CR>
" Make Y consistent with C and D - yank to end of line, not full line.
nnoremap Y y$
" Inserts the path of the currently edited file into a command
" Command mode: Ctrl+P
cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
" Select (linewise) the text you just pasted (handy for modifying indentation):
nnoremap <leader>v V`]
" Move by screen lines instead of file lines.
" http://vim.wikia.com/wiki/Moving_by_screen_lines_instead_of_file_lines
noremap <Up> gk
noremap <Down> gj
noremap k gk
noremap j gj
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
" Save a file as root.
cabbrev w!! w !sudo tee % > /dev/null<CR>:e!<CR><CR>
" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
" Tab/shift-tab to indent/outdent in visual mode.
vmap <Tab> >gv
vmap <S-Tab> <gv
" Use sane regexes
autocmd VimEnter * nnoremap / /\v
vnoremap / /\v
" Directories for swp files
set backupdir=~/.vim/backup/
set directory=~/.vim/backup//
" Configure Tags {{{
set tags=.vimtags;
let Tlist_GainFocus_On_ToggleOpen = 1 " taglist window has focus when opened
let Tlist_Use_Horiz_Window=1 " Horizontal Tag list window
let Tlist_Show_One_File=1 " Only show the current buffers tags
let Tlist_Sort_Type = 'name' " Sort tags by name
let Tlist_Ctags_Cmd='/usr/local/bin/ctags' " Don't use OS X ctags
let g:autotagTagsFile='.vimtags'
let g:autotagCtagsCmd='/usr/local/bin/ctags'
map <F3> :Tlist<CR>
nnoremap <leader><cr> :silent !/usr/local/bin/ctags -R -f .vimtags .<cr>
" }}}
" Un-highlight search matches
nnoremap <leader>/ :noh<CR>
" Print highlighting scope at the current position.
" http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor
map <leader>S :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" Open URL from this line (OS X only).
map <leader>u :call OpenURI()<CR>
" AlignMap default for <leader>w= interferes with CamelCaseMotion
autocmd VimEnter * unmap <leader>w=
" Ag settings {{{
" Ag for the last search.
nnoremap <silent> <leader>? :execute "ag! '" . substitute(substitute(substitute(@/, "\\\\<", "\\\\b", ""), "\\\\>", "\\\\b", ""), "\\\\v", "", "") . "'"<CR>"'"'"
" }}}
" Quickfix windows
map <leader>q :cclose<CR>
" Previous fix and center line.
map - :cprev<CR> zz
" Next fix and center line.
map + :cnext<CR> zz
" Opens an edit command with the path of the currently edited file filled in
map <leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
" Use the current word under the cursor in a substitution.
:nnoremap <Leader>s :%s/\<<C-r><C-w>\>//g<Left><Left>
" Create a split on the given side.
" From http://technotales.wordpress.com/2010/04/29/vim-splits-a-guide-to-doing-exactly-what-you-want/ via joakimk.
nmap <leader><left> :leftabove vsp<CR>
nmap <leader><right> :rightbelow vsp<CR>
nmap <leader><up> :leftabove sp<CR>
nmap <leader><down> :rightbelow sp<CR>
" {{{ Leader shortcuts for system clipboard
vmap <leader>y "+y
vmap <leader>d "+d
nmap <leader>y "+y
nmap <leader>d "+d
nmap <leader>p "+p
nmap <leader>P "+P
vmap <leader>p "+p
vmap <leader>P "+P
" }}}
" Invisible characters
set listchars=trail:.,tab:>-,eol:$
set nolist
:noremap <leader>i :set list!<CR> " Toggle invisible chars"
" Remove octal from number formats so numbers with leading 0s increment
" properly
set nrformats=hex
" Configure Java Syntax
let java_highlight_java_lang_ids=1
let java_highlight_java_io=1
" Settings for VimClojure
let vimclojure#HighlightBuiltins=1 " Highlight Clojure's builtins
let vimclojure#ParenRainbow=1 " Rainbow parentheses'!
" Setup folding {{{
set foldmethod=syntax
set foldcolumn=0
nnoremap <leader>z zMzvzz
" Enter to toggle folds, unless in Quickfix
nnoremap <silent> <CR> za
vnoremap <silent> <CR> za
autocmd CmdwinEnter * nnoremap <buffer> <cr> <cr>
autocmd FileType qf nnoremap <buffer> <cr> <cr>
" }}}
" Change Case
inoremap <C-u> <esc>gUiwea
" Clean trailing whitespace
nnoremap <leader>w :%s/\s\+$//<cr>:let @/=''<cr>
" Send visual selection to gist.github.com as a private, filetyped Gist
" Requires the gist command line too (brew install gist)
vnoremap <leader>G :w !gist -p -t %:e \| pbcopy<cr>
" Set preferences for Perl {{{
augroup ft_vim
au!
:let perl_fold=1
:let perl_include_pod=1
nnoremap <silent> _t :%!perltidy -q<Enter>
vnoremap <silent> _t :!perltidy -q<Enter>
augroup END
" }}}
if has("autocmd") && has("gui_macvim")
au FileType ruby map <buffer> <D-r> :call RubyRun()<CR>
au FileType ruby imap <buffer> <D-r> <Esc>:call RubyRun()<CR>
au FileType ruby-runner map <buffer> <D-r> ZZ
endif
au BufNewFile,BufRead *.gradle setf groovy
au BufRead,BufNewFile *.t set filetype=perl | compiler perlprove
" Syntastic Settings {{{
let g:syntastic_enable_perl_checker = 1
let g:syntastic_perl_interpreter = '~/.plenv/shims/perl'
let g:syntastic_ruby_exec = '~/.rbenv/shims/ruby'
" }}}
" Airline Settings {{{
let g:airline_powerline_fonts = 1
let g:airline_theme='tomorrow'
" }}}
" CtrlP Settings {{{
let g:ctrlp_match_window_bottom = 0
let g:ctrlp_match_window_reversed = 0
let g:ctrlp_map = '<leader><space>'
let g:ctrlp_working_path_mode = 0
let g:ctrlp_split_window = 0
let g:ctrlp_max_height = 20
let g:ctrlp_mruf_relative = 1
let g:ctrlp_mruf_last_entered = 1
let g:ctrlp_mruf_exclude = 'tmp/.*\|temp/.*\|\.git/.*'
let g:ctrlp_prompt_mappings = {
\ 'PrtSelectMove("j")': ['<c-j>', '<down>', '<s-tab>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>', '<tab>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'ToggleFocus()': ['<c-tab>'],
\ }
let g:ctrlp_extensions = ['tag']
let g:ctrlp_root_markers = ['.lvimrc'] " add the local lvimrc to to top of root markers
let g:ctrlp_custom_ignore = {
\ 'dir': 'build\|target\|bin'
\ }
nnoremap <leader>. :CtrlPBufTag<cr>
autocmd BufEnter,BufUnload * call ctrlp#mrufiles#list(expand('<abuf>', 1)) " sort the buffer list by last entered
function! CtrlpSeed()
:let g:ctrlp_default_input = tolower(expand('<cword>'))
:CtrlP
:let g:ctrlp_default_input = ''
endfunction
nnoremap <silent> <leader>g :call CtrlpSeed()<cr>
let g:ctrlp_user_command = 'ag %s -i --nocolor --nogroup --hidden
\ -g ""'
" }}}
" Next and Last {{{
" Motion for "next/last object". "Last" here means "previous", not "final".
" Unfortunately the "p" motion was already taken for paragraphs.
"
" Next acts on the next object of the given type in the current line, last acts
" on the previous object of the given type in the current line.
"
" Currently only works for (, [, {, b, r, B, ', and ".
"
" Some examples (C marks cursor positions, V means visually selected):
"
" din' -> delete in next single quotes foo = bar('spam')
" C
" foo = bar('')
" C
"
" canb -> change around next parens foo = bar('spam')
" C
" foo = bar
" C
"
" vil" -> select inside last double quotes print "hello ", name
" C
" print "hello ", name
" VVVVVV
onoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
xnoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
onoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
xnoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
onoremap al :<c-u>call <SID>NextTextObject('a', 'F')<cr>
xnoremap al :<c-u>call <SID>NextTextObject('a', 'F')<cr>
onoremap il :<c-u>call <SID>NextTextObject('i', 'F')<cr>
xnoremap il :<c-u>call <SID>NextTextObject('i', 'F')<cr>
function! s:NextTextObject(motion, dir)
let c = nr2char(getchar())
if c ==# "b"
let c = "("
elseif c ==# "B"
let c = "{"
elseif c ==# "r"
let c = "["
endif
exe "normal! ".a:dir.c."v".a:motion.c
endfunction
" }}}
" Vim {{{
augroup ft_vim
au!
au FileType vim setlocal foldmethod=marker
au FileType help setlocal textwidth=78
augroup END
" }}}
" Error toggles ----------------------------------------------------------- {{{
command! ErrorsToggle call ErrorsToggle()
function! ErrorsToggle() " {{{
if exists("w:is_error_window")
unlet w:is_error_window
exec "q"
else
exec "Errors"
lopen
let w:is_error_window = 1
endif
endfunction " }}}
nmap <silent> <f4> :ErrorsToggle<cr>
" }}}
" Configure gitgutter {{{
" }}}
" Can autocomplete CSS classes etc with dashes. {{{
" Also changes the "w" small word motion not to stop at dashes,
" but use https://github.com/henrik/CamelCaseMotion for that.
set iskeyword+=-
" }}}
" Help File speedups, <enter> to follow tag, delete for back
au filetype help nnoremap <buffer><cr> <c-]>
au filetype help nnoremap <buffer><bs> <c-T>
au filetype help nnoremap <buffer>q :q<CR>
au filetype help set nonumber
set splitbelow " Split windows, ie Help, make more sense to me below
au filetype help wincmd _ " Maximze the help on open
au FileType gitcommit setlocal spell
" Command Window Editing {{{
" have enter mean enter in command window
autocmd CmdwinEnter * nnoremap <buffer> <cr> <cr>
" Have <esc> leave cmdline-window
autocmd CmdwinEnter * nnoremap <buffer> <esc> :q<cr>
" }}}
" Navigate Tabs {{{
map <D-S-]> gt
map <D-S-[> gT
map <D-1> 1gt
map <D-2> 2gt
map <D-3> 3gt
map <D-4> 4gt
map <D-5> 5gt
map <D-6> 6gt
map <D-7> 7gt
map <D-8> 8gt
map <D-9> 9gt
map <D-0> :tablast<CR>
" }}}
" YouCompleteMe {{{
let g:ycm_key_list_select_completion = ['<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
" }}}
" Highlight trailing whitespace {{{
highlight ExtraWhitespace guibg=DarkCyan ctermbg=Blue
au ColorScheme * highlight ExtraWhitespace guibg=DarkCyan ctermbg=Blue
au BufWinEnter * match ExtraWhitespace /\s\+$\| \+\ze\t/
au BufWrite * match ExtraWhitespace /\s\+$\| \+\ze\t/
" }}}
" UltiSnips {{{
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
" }}}
" EasyAlign {{{
"" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
vmap <Leader>a <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. <Leader>aip)
nmap <Leader>a <Plug>(EasyAlign)
" }}}
" SQL {{{
let g:sql_type_default = 'sqlany'
au BufNewFile,BufRead *.spl setf sql
au BufNewFile,BufRead *.btq setf sql
" }}}
" Sayonara {{{
nnoremap gs :Sayonara<cr>
nnoremap gS :Sayonara!<cr>
" }}}
"
function! OpenChangedFiles()
only " Close all windows, unless they're modified
let status = system('git status -s | grep "^ \?\(M\|A\)" | cut -d " " -f 3')
let filenames = split(status, "\n")
let topdir = split(system('git rev-parse --show-toplevel'), "\n")[0]
if len(filenames) < 1
let status = system('git show --pretty="format:" --name-only')
let filenames = split(status, "\n")
endif
exec "edit " . topdir . "/" . filenames[0]
for filename in filenames[1:]
if len(filenames) > 4
exec "tabedit " . topdir . "/" . filename
else
exec "sp " . topdir . "/" . filename
endif
endfor
endfunction
command! OpenChangedFiles :call OpenChangedFiles()
noremap<Leader>O :OpenChangedFiles <CR>
runtime macros/matchit.vim
"