-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
629 lines (520 loc) · 17.7 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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
set nocompatible " We're running Vim, not Vi!
" use proper ruby
let g:ruby_path=$RUBY_BIN
" system specific
execute pathogen#infect()
syntax on " Enable syntax highlighting
filetype plugin indent on " Enable filetype-specific indenting and plugins
set showmatch "show matching surround
set hidden "allow hiding buffers without save
" only for `vim` command, `mvim` uses ~/.gvimrc color settings
set background=dark
let g:solarized_termcolors=256
let g:solarized_termtrans=1
let g:solarized_contrast="hight"
colorscheme solarized
" https://github.com/xolox/vim-colorscheme-switcher
" :NextColorScheme
" :PrevColorScheme
" :RandomColorScheme
let g:colorscheme_switcher_exclude = ['default', 'blue', 'darkblue', 'elflord', 'evening', 'koehler']
let g:colorscheme_switcher_exclude_builtins = 1
" don't leave backup files scattered about.
set updatecount=0
set nobackup
set nowritebackup
set backupcopy=yes
" set dir=~/tmp " swap file storage directory
set nowrap "no text wrapping
set selectmode=key "shifted arrows for selection
set nonu "don't show line numbers
set foldcolumn=0 "little space on the left.
set nofoldenable " disable folding
set tabstop=2
set shiftwidth=2
set softtabstop=2
set ai "auto indent
set expandtab
set smarttab
set smartcase " ignore case in searches unless specific case is given
set wrapscan " wrap searches
set ww=<,>,[,],h,l "wrap on movement keys
let mapleader = ","
" highlight searches, clear with spacebar
set hlsearch
set hl=l:Visual
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" Fast editing of the .vimrc
" map <leader>e :e! ~/.vimrc<cr>
" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>
function! CurDir()
let curdir = substitute(getcwd(), '/home/adam/', "~/", "g")
return curdir
endfunction
" Always show status line
set laststatus=2
" objective-c and clang
" http://objvimmer.com/blog/2012/08/17/objective-c-code-completion-in-vim/
" https://github.com/Rip-Rip/clang_complete
let g:clang_library_path = '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib'
" golang
let g:go_fmt_command = "goimports"
" javascript js
let g:javascript_enable_domhtmlcss = 1
let g:jsx_ext_required = 0
" markdown / Pencil
let g:vim_markdown_frontmatter = 1 " jekyll
let g:markdown_fenced_languages = ['html', 'python', 'javascript', 'ruby', 'bash=sh']
" To disable markdown syntax concealing add the following to your vimrc:
" let g:markdown_syntax_conceal = 0
" ale replaces Syntastic
let g:ale_linters = {
\ 'javascript': ['eslint'],
\}
" Only run linters named in ale_linters settings.
" let g:ale_linters_explicit = 1
" " Syntastic
" " set statusline+=%0*\ %{g:colors_name}
" " set statusline+=%#warningmsg#
" " set statusline+=%{SyntasticStatuslineFlag()}
" " set statusline+=%*
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" let g:syntastic_check_on_open = 1
" let g:syntastic_check_on_wq = 0
" let g:syntastic_coffeescript_checkers=['jshint']
" let g:syntastic_enable_balloons=0
" let g:syntastic_enable_signs=0
" let g:syntastic_javascript_checkers=['eslint']
" let g:syntastic_javascript_eslint_exe='$(yarn bin)/eslint'
" let g:syntastic_loc_list_height=4
" let g:syntastic_scss_checkers=['scss-lint']
" " cpp / Ardunio
" let g:syntastic_cpp_no_include_search = 1
" let g:syntastic_cpp_remove_include_errors = 1
" " let g:syntastic_go_checkers = ['golint', 'gotype', 'govet']
" let g:syntastic_debug=0
" " let g:syntastic_auto_jump=0
" " let g:syntastic_disabled_filetypes = ['html', 'xhtml', 'sass', 'scss', 'feature']
" let g:syntastic_mode_map = { 'mode': 'active',
" \ 'active_filetypes': ['ruby', 'coffee', 'javascript', 'css', 'less'],
" \ 'passive_filetypes': ['html', 'xhtml', 'sass', 'scss', 'erlang'] }
" let g:syntastic_ruby_mri_quiet_messages = { "level": "warnings",
" \ "type": "style",
" \ "regex": '\mambiguous' }
" let g:syntastic_eruby_ruby_quiet_messages = {'regex': 'possibly useless use of a variable in void context'}
" " let g:syntastic_quiet_messages = { "level": "warnings" }
" Intuitive backspacing in insert mode
set backspace=indent,eol,start
" highlight cursor line in INSERT mode.
autocmd InsertLeave * se nocul
autocmd InsertEnter * se cul
"clean trailing spaces, convert tabs to spaces
noremap <silent> <leader>v mv:%s/\s\+$//e<CR>:%s/\t/ /e<CR>`v
" clean trailing spaces automatically before save
autocmd BufWritePre * call StripTrailingWhite()
function! StripTrailingWhite()
let l:winview = winsaveview()
silent! %s/\s\+$//
call winrestview(l:winview)
endfunction
" autocmd BufWritePre * :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
" don't continue comments when pushing o/O
set formatoptions-=o
"some stuff to get the mouse going in term
set mouse=a
set ttymouse=xterm2
"tell the term has 256 colors
set t_Co=256
" assume the /g flag on :s substitutions to replace all matches in a line
set gdefault
" keep 3 lines visible at top and bottom
set scrolloff=3
" read per-project vimrc files
set exrc
" NerdTree
let NERDTreeShowBookmarks=0
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
" BufExplorer
let g:bufExplorerSortBy='mru'
" ctrlp (supercedes Command-T (supercedes FuzzyFinderTextMate))
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
map <leader>f :CtrlPClearCache<CR>
map <leader>t :CtrlP<CR>
map <C-t> :CtrlP<CR>
" fuzzy finders ignoring things
" set wildmode=list:longest,list:full
set wildignore+=*.log,*.o,*.sassc,*.png,*.jpg,*.db,*.gif,*.jpeg,*.swf,*.class,*.scssc,*.pdf,node_modules/*,public/*,log/*
" 'c' - the directory of the current file.
" 'r' - the nearest ancestor that contains one of these directories or files: .git .hg .svn .bzr _darcs
" 'a' - like c, but only if the current working directory outside of CtrlP is not a direct ancestor of the directory of the current file.
" 0 or '' (empty string) - disable this feature.
let g:ctrlp_working_path_mode = 'ra'
" let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)|(node_modules/|vendor/|public/|Godeps|tmp/cache)'
let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:25,results:25'
let g:ctrlp_root_markers = ['package.json', 'Gemfile', 'Pipfile', 'Rakefile']
" Use a custom file listing command:
" let g:ctrlp_user_command = 'find %s -type f' " MacOSX/Linux
" Ack search
let g:ackprg = 'ag --nogroup --nocolor --column -p /Users/adam/.agignore'
map <leader>a :Ack<space>
vmap <leader>a "ay:Ack<space><C-r>a<CR>
" close quickfix buffer
map <leader>x :ccl<CR>
if has("mac")
" create window splits with <Command-w>{s,v}
map <D-w>s <C-w>s
" in case I fat finger it
map <D-w><D-s> <C-w>s
map <D-w>q <C-w>q
map <D-w><D-q> <C-w>q
map <D-w>v <C-w>v
map <D-w><D-v> <C-w>v
" create window splits with <Command-w>{s,v}
imap <D-w>s <esc><C-w>s
" in case I fat finger it
imap <D-w><D-s> <esc><C-w>s
imap <D-w>q <esc><C-w>q
imap <D-w><D-q> <esc><C-w>q
imap <D-w>v <esc><C-w>v
imap <D-w><D-v> <esc><C-w>v
imap <D-w> <C-w>
imap <D-p> <C-p>
imap <D-n> <C-n>
" map <D-t> :CommandT<CR>
" noremap <D-t> :CommandT<CR>
" inoremap <D-t> :CommandT<CR>
map <D-t> :CtrlP<CR>
noremap <D-t> :CtrlP<CR>
inoremap <D-t> :CtrlP<CR>
" paste current yank buffer
inoremap <D-V> <esc>""pi
map <D-s> :w<CR> " just save
imap <D-s> <esc>:w<CR> " save and return to normal mode (saves a keystroke)
vmap <D-s> <esc>:w<CR>gv " save and return to previous visual selection
" navigate splits quickly with the normal movement keys
inoremap <D-h> <esc><C-w><C-h>
inoremap <D-j> <esc><C-w><C-j>
inoremap <D-k> <esc><C-w><C-k>
inoremap <D-l> <esc><C-w><C-l>
noremap <D-h> <C-w><C-h>
noremap <D-j> <C-w><C-j>
noremap <D-k> <C-w><C-k>
noremap <D-l> <C-w><C-l>
" esc
inoremap <D-[> <esc>
" format paragraph
map <D-p> vipgq
map <leader>w= <C-w>=
noremap <leader>w= <C-w>=
noremap <D-w>= <C-w>=
" https://github.com/mattn/emmet-vim formerly Zen-Coding
map <D-y> <C-y>
map <D-y>, <C-y>,
endif
" prettify
nmap <leader>p gg=G
" Key Mappings
" reload vimrc
nmap <leader>r :source ~/.vimrc<CR>
nmap <leader>g :source ~/.gvimrc<CR>
" Tab and Shift-Tab indent and unindent
inoremap <S-Tab> <esc>mp<<2h`pa
noremap <Tab> >>
noremap <S-Tab> <<
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
" window nav
inoremap <C-h> <esc><C-w><C-h>
inoremap <C-j> <esc><C-w><C-j>
inoremap <C-k> <esc><C-w><C-k>
inoremap <C-l> <esc><C-w><C-l>
noremap <C-h> <C-w><C-h>
noremap <C-j> <C-w><C-j>
noremap <C-k> <C-w><C-k>
noremap <C-l> <C-w><C-l>
" Copy paste using system clipboard
vmap <C-y> "+y
vmap <C-u> "+p
nmap <C-u> "+p
imap <C-u> <esc>"+p
imap <C-v> <esc>pa
" Home/end like emacs and bash
nmap <C-e> $
imap <C-e> <End>
nmap <C-a> ggVG
"nmap <C-a> 0
"imap <C-a> <Home>
" CTRL-S is Save
noremap <C-s> :w<CR>
inoremap <C-s> <esc>:w<CR>
" leader s also saves
noremap <leader>s :w<CR>
inoremap <leader><leader>s <esc>:w<CR>
" in case of fatfinger
command! W :w
" ,bd to close buffer without changing window layout.
" let g:BufClose_AltBuffer = '"#"' " make sure bufclose doesn't create blank buffers
" nmap <leader>bd :BufClose<CR>
" imap <C-b>d <esc>:BufClose<CR>
nmap <leader>bd :BW<CR>
imap <C-b>d <esc>:BW<CR>
" select current definition
nmap <leader>vm <esc>[mmd]MV'd
" shift up / down moves the selection cursor
vmap <S-up> <up>
vmap <S-down> <down>
nmap <S-up> V<up>
nmap <S-down> V<down>
nmap <S-right> v<right>
nmap <S-left> v<left>
inoremap <S-up> <esc>v<up>
inoremap <S-down> <esc>v<down>
inoremap <S-right> <esc>v<right>
inoremap <S-left> <esc>v<left>
" S-home in insert acts like ^ in normal
inoremap <S-home> <esc>^i
" unmap shift-k
vmap K <up>
nmap K <up>
" toggle numbers
nmap <leader>n :set nonu!<CR>
" hashrocket!
imap hh =>
" esc from insert mode with this uncommon keystroke
imap jj <esc>
" tabularize on =
vmap <leader>= :Tabularize /=<CR>
" titleize selection (linewise, crap)
" vnoremap <silent> T :s/\v^.\|<%(is>\|in>\|the>\|at>\|with>\|a>)@!./\U&/<CR>:nohlsearch<Bar>:echo<CR>
"""" System specific or plugin related """"
" ZenCoding: http://mattn.github.com/zencoding-vim
let g:user_zen_settings = {
\ 'indentation' : ' ',
\ 'perl' : {
\ 'aliases' : {
\ 'req' : 'require '
\ },
\ 'snippets' : {
\ 'use' : "use strict\nuse warnings\n\n",
\ 'warn' : "warn \"|\";",
\ }
\ }
\}
let g:user_zen_leader_key = '<C-z>'
let g:user_zen_expandabbr_key = '<C-e>'
" Load matchit (% to bounce from do to end, etc.)
runtime! macros/matchit.vim
" gist-vim defaults
if has("mac")
let g:gist_clip_command = 'pbcopy'
elseif has("unix")
let g:gist_clip_command = 'xclip -selection clipboard'
endif
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
" Use modeline overrides
set modeline
set modelines=10
map <leader>h <esc>:call ProjectionMode()<CR>
function! ProjectionMode()
if has("mac")
set gfn=Inconsolata:h16
else
set gfn=Inconsolata\ 16
endif
set laststatus=0
set showcmd
endfunction
" noremap <silent> <Leader>w :call ToggleWrap()<CR>
" function ToggleWrap()
" if &wrap
" echo "Wrap OFF"
" setlocal nowrap
" set virtualedit=all
" silent! nunmap <buffer> <Up>
" silent! nunmap <buffer> <Down>
" silent! nunmap <buffer> <Home>
" silent! nunmap <buffer> <End>
" silent! iunmap <buffer> <Up>
" silent! iunmap <buffer> <Down>
" silent! iunmap <buffer> <Home>
" silent! iunmap <buffer> <End>
" silent! ounmap <buffer> j
" silent! ounmap <buffer> k
" else
" echo "Wrap ON"
" setlocal wrap linebreak nolist
" set virtualedit=
" setlocal display+=lastline
" noremap <buffer> <silent> <Up> gk
" noremap <buffer> <silent> <Down> gj
" noremap <buffer> <silent> <Home> g<Home>
" noremap <buffer> <silent> <End> g<End>
" inoremap <buffer> <silent> <Up> <C-o>gk
" inoremap <buffer> <silent> <Down> <C-o>gj
" inoremap <buffer> <silent> <Home> <C-o>g<Home>
" inoremap <buffer> <silent> <End> <C-o>g<End>
" onoremap <buffer> <silent> j gj
" onoremap <buffer> <silent> k gk
" endif
" endfunction
" function! WrapMode()
" setlocal formatoptions=tcq
" setlocal textwidth=80
" setlocal wrap
" setlocal lbr
" "setlocal foldmethod=manual
" "setlocal spell
"
" " treat long wrapped lines (paragraphs) like short lines.
" " i.e., directional keys move directly up and down visually
" " and movement keys wrap to the next visual line, not the
" " next line break.
" map <buffer> <up> gk
" imap <buffer> <up> <C-o>gk
" map <buffer> <down> gj
" imap <buffer> <down> <C-o>gj
" map <buffer> <home> g<home>
" imap <buffer> <home> <C-o>g<home>
" map <buffer> <end> g<end>
" imap <buffer> <end> <C-o>g<end>
" map <buffer> j gj
" map <buffer> k gk
" endfunction
"""""" Filetype Specific Settings
augroup myfiletypes
" Clear old autocmds in group
autocmd!
" lcd to current rails project root
autocmd BufRead *.as set filetype=actionscript
autocmd BufRead *.mxml set filetype=mxml
autocmd BufRead *.rtex set filetype=tex
autocmd BufRead *.clj set filetype=clojure
autocmd BufRead *.jst set filetype=jst
autocmd BufRead *.ejs set filetype=jst
autocmd BufRead *.mustache set filetype=mustache
autocmd BufRead,BufNewFile *.md set filetype=markdown
autocmd BufRead,BufNewFile *.md.erb set filetype=markdown
autocmd BufRead,BufNewFile *.ru set filetype=ruby
autocmd BufRead,BufNewFile Gemfile set filetype=ruby
autocmd BufRead,BufNewFile Rakefile set filetype=ruby
autocmd BufRead,BufNewFile Capfile set filetype=ruby
autocmd BufRead,BufNewFile Guardfile set filetype=ruby
autocmd BufRead,BufNewFile *.jbuilder set filetype=ruby
autocmd BufRead,BufNewFile *.scss set filetype=scss
autocmd FileType java,c,cpp,c++ call s:MyCLikeSettings()
autocmd FileType objc call s:MyObjcSettings()
autocmd FileType ruby,eruby call s:MyRubySettings()
autocmd FileType vim call s:MyVimSettings()
autocmd FileType python call s:MyPythonSettings()
autocmd FileType clojure call s:MyClojureSettings()
autocmd FileType go call s:MyGoSettings()
autocmd FileType markdown call s:MyMarkdownSettings()
augroup END
augroup myprojectdirs
autocmd!
" autocmd BufNewFile,BufRead /Users/adam/projects/adafruit/io-node/* set background=light
" au BufWinLeave /Users/adam/projects/adafruit/io-api/*.json mkview
" au BufWinEnter /Users/adam/projects/adafruit/io-api/*.json silent loadview
augroup END
" Clear all comment markers (one rule for all languages)
map <leader>_ :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>:nohlsearch<CR>
function! s:MyCLikeSettings()
" Insert comments markers
map - :s/^/\/\//<CR>:nohlsearch<CR>
endfunction
function! s:MyVimSettings()
" Insert comments markers
map - :s/^/\"/<CR>:nohlsearch<CR>
endfunction
function! s:MyRubySettings()
set ai sw=2 sts=2 et
"improve autocomplete menu color
let g:closetag_html_style=1
" Insert comments markers
map - :s/^/#/<CR>:nohlsearch<CR>
" wrap selected text in ERB escape tag
vnoremap <leader>m "zdi<%= <C-R>z %><ESC>
" Get rid of rails format.html { } blocks
map <silent> <leader>rf :%s/[a-z]*\.[a-z]* { \([^}]*\) }/\1<CR>
endfunction
function! s:MyClojureSettings()
" let g:clj_highlight_builtins=1 " Highlight Clojure's builtins
" let g:clj_paren_rainbow=1 " Rainbow parentheses'!
let g:vimclojure#HighlightBuiltins=1 " Highlight Clojure's builtins
let g:vimclojure#ParenRainbow=1 " Rainbow parentheses'!
let g:vimclojure#DynamicHighlighting=1 " Dynamically highlight functions
endfunction
function! s:MyObjcSettings()
set ai sw=4 sts=4 et
let c_no_curly_error = 1
endfunction
" json is javascript
autocmd BufNewFile,BufReadPost,BufEnter *.json set filetype=javascript
function! s:MyPythonSettings()
set ai sw=4 sts=4 et
" insert comments marker
map - :s/^/#/<CR>:nohlsearch<CR>
set foldmethod=marker "auto fold
endfunction
" golang
function! s:MyGoSettings()
" autocmd BufWritePre,FileWritePre *.go :SyntasticCheck
" autocmd BufWritePost *.go :SyntasticCheck
" autocmd BufWritePost,FileWritePost *.go execute 'GoBuild' | cwindow
nnoremap <leader>gi :%! goimports %<CR>
nnoremap <leader>gd :GoDef<CR>
nnoremap <leader>gs :sp<CR>:GoDef<CR>
endfunction
function! s:MyMarkdownSettings()
setlocal autoindent
setlocal colorcolumn=0
setlocal linebreak
setlocal nonumber
setlocal shiftwidth=4
setlocal spell
setlocal tabstop=4
setlocal wrap
noremap <silent> k gk
noremap <silent> j gj
noremap <silent> 0 g0
noremap <silent> ^ g^
noremap <silent> $ g$
endfunction
" lcd to current rails project root
map <silent> <leader>r :if exists("b:rails_root")<CR>:Rlcd<CR>:endif<CR>
" lcd to current file path
map <silent> <leader>R :lcd %:p:h<CR>
" Enable closetag macro all the time
let b:unaryTagsStack=""
let b:closetag_html_style=1
let b:closetag_disable_synID=1
source ~/.vim/macros/closetag.vim
" Usage:
"
" :Me ~/path/to/my/new/file.txt
"
" creates /home/username/path/to/my/new with `mkdir -p` if it doesn't exist
" and then opens file.txt
"
function! Mkdire(path)
let l:newpath = fnamemodify(expand(a:path), ":p:h")
let l:newfile = expand(a:path)
if !isdirectory(l:newpath)
call mkdir(l:newpath, "p")
endif
execute "e " . l:newfile
endfunction
command! -nargs=1 -complete=file Me call Mkdire(<f-args>)
" you can also automatically call the function before save (on every write)
" au BufWritePre,FileWritePre * call Mkdire('%')
" Use project-local vim config
let b:thisdir=expand("%:p:h")
let b:vim=b:thisdir."/.vim"
if (filereadable(b:vim))
execute "source ".b:vim
endif