forked from pixelhandler/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
executable file
·521 lines (404 loc) · 14.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
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible " Use vim, no vi defaults
" ----------------------------------------------------------
" Pathogen Initialization
" This loads all the plugins in ~/.vim/bundle
" Use tpope's pathogen plugin to manage all other plugins
" Filetype detection must be off when you run the commands
filetype off
call pathogen#runtime_append_all_bundles()
"call pathogen#infect()
call pathogen#helptags()
" ----------------------------------------------------------
" based on tutorial for best practices
" https://danielmiessler.com/study/vim/
inoremap jk <ESC>
let mapleader = "\<Space>"
filetype plugin indent on
syntax on
set encoding=utf-8
" ----------------------------------------------------------
" Git
" Integration with Git, perhaps add to status line %{fugitive#statusline()}
" Fugitive commands...
" Gblame: This allows you to view a line by line comparison of who the last person to touch that line of code is.
" Gwrite: This will stage your file for commit, basically doing git add <filename>
" Gread: This will basically run a git checkout <filename>
" Gcommit: This will just run git commit. Since its in a vim buffer, you can use keyword completion (Ctrl-N), like test_all<Ctrl-N> to find the method name in your buffer and complete it for the commit message. You can also use + and - on the filenames in the message to stage/unstage them for the commit.
" ----------------------------------------------------------
" Tab Completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*
" ctags
" /usr/bin/ctags or /usr/local/bin/jsctags
" `jsctags -R .` similar to `ctags -R --exclude='.git' .`
set tags=./.tags,~/.tags,/vagrant/.tags;
set tags+=.tags;/
let $Tlist_Ctags_Cmd='/usr/bin/ctags'
autocmd FileType javascript let $Tlist_Ctags_Cmd='/usr/local/bin/jsctags'
function! UpdateTags()
execute ":!ctags -a -R -f .tags"
echohl StatusLine | echo "ctags updated" | echohl None
endfunction
nnoremap <F4> :call UpdateTags()
" Turning omnicompletion completion on
" <C-p> <C-n>
" <C-x><C-o>
"set ofu=syntaxcomplete#Complete
set omnifunc=syntaxcomplete#Complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType sass set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_DisplayMode = 1
let OmniCpp_ShowScopeInAbbr = 0 "do not show namespace in pop-up
let OmniCpp_ShowPrototypeInAbbr = 1 "show prototype in pop-up
let OmniCpp_ShowAccess = 1 "show access in pop-up
let OmniCpp_SelectFirstItem = 1 "select first item in pop-up
set completeopt=menuone,menu,longest
let g:SuperTabDefaultCompletionType = "context"
set completeopt=menuone,longest,preview
if version >= 700
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
highlight clear
highlight Pmenu ctermfg=0 ctermbg=2
highlight PmenuSel ctermfg=0 ctermbg=7
highlight PmenuSbar ctermfg=7 ctermbg=0
highlight PmenuThumb ctermfg=0 ctermbg=7
endif
" Code Navigation
" Buffers, minibufexpl plugin
" You can switch between the buffers using b<number>, such as :b1 for the first buffer.
" You can also use its name to match, so you can type :b mod<tab>
" To close a buffer you use :bd or :bw.
" snipmate
source ~/.vim/bundle/snipmate/after/plugin/snipMate.vim
" let g:snips_author="Bill Heaton"
let g:snippets_dir="~/.vim/bundle/snipmate/snippets,~/.vim/snippets"
" ----------------------------------------------------------
" Mappings and bundle settings
" Graph your Vim undo tree in style, gundo.vim
nnoremap <F5> :GundoToggle<CR>
" Task lists, TaskList.vim
map <leader>td <Plug>TaskList
" Gundo plugin
map <leader>g :GundoToggle<CR>
" File Browser, NERDTree
map <leader>n :NERDTreeToggle<CR>
let NERDTreeShowHidden=1
" Searching, Ack
nmap <leader>a <Esc>:Ack!
" Window Splits, bind Ctrl+<movement> keys to move around the windows,
" instead of using Ctrl+w + <movement>:
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
" Map ctrl-movement keys to window switching
map <C-k> <C-w><Up>
map <C-j> <C-w><Down>
map <C-l> <C-w><Right>
map <C-h> <C-w><Left>
" Switch to alternate file
map <C-Tab> :bnext<CR>
map <C-S-Tab> :bprevious<CR>
" Map keys to switch buffers
map <leader>) :bn<cr>
map <leader>( :bp<cr>
" map <leader>d :bd<cr>
" 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 %
map <C-\> :tnext<CR>
" Opens an edit command with the path of the currently edited file filled in
" Normal mode: <Leader>e
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
" Opens a tab edit command with the path of the currently edited file filled in
" Normal mode: <Leader>t
map <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
" Shortcut to rapidly toggle `set list`
nmap <leader>l :set list!<CR>
" 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 %%
" 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
" find merge conflict markers
nmap <silent> <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
" 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
" 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
" Map Coffeescript commands using kchmck/vim-coffee-script
"map <C-Tab> :bnext<CR>
"map <C-S-Tab> :bprevious<CR>
map <leader>fcc :compiler coffee<CR>
map <leader>fm :make<CR>
map <leader>fsm :silent make<CR>
map <leader>fsm! :silent make!<CR>
map <leader>fmq :make | cwindow
map <leader>fc :CoffeeCompile | vert cwindow
map <leader>fw :CoffeeWatch vert<CR>
map <leader>sb :setl scrollbind<CR>
map <leader>fr :CoffeeRun<CR>
map <leader>fl :CoffeeLint! | cwindow
" compile on write
" au BufWritePost *.coffee silent make!
" au BufWritePost *.coffee silent make! -b | cwindow | redraw!
" ctrlp.vim
set runtimepath^=~/.vim/bundle/ctrlp.vim
" <LocalLeader>
let g:maplocalleader = ';'
" vim-mustache-handlebars
let g:mustache_abbreviations = 1
" vim-json
let g:vim_json_syntax_conceal = 0
" ----------------------------------------------------------
" Backup and swap files
set backupdir=~/.vim/_backup// " where to put backup files.
set directory=~/.vim/_temp// " where to put swap files.
" ----------------------------------------------------------
" General Config
set encoding=utf-8 "Set default encoding to UTF-8
set number "Line numbers are good
set ruler "Show line and column number
set backspace=indent,eol,start "Allow backspace in insert mode
set history=1000 "Store lots of :cmdline history
set showcmd "Show incomplete cmds down the bottom
set showmode "Show current mode down the bottom
set gcr=a:blinkon0 "Disable cursor blink
set visualbell "No sounds
set autoread "Reload files changed outside vim
" This makes vim act like all other editors, buffers can
" exist in the background without being in a window.
" http://items.sjbach.com/319/configuring-vim-right
set hidden
" ----------------------------------------------------------
" White Space
" Indentation
set autoindent
set smartindent
set smarttab
set shiftwidth=4
set softtabstop=4
set tabstop=4
set expandtab
" (needed for snipmate filetype plugin on)
"filetype plugin on
"filetype indent on
" Display tabs and trailing spaces visually
set list listchars=tab:\ \ ,trail:·
set nowrap "Don't wrap lines
set linebreak "Wrap lines at convenient points
set list listchars=tab:▸\ ,trail:·
" Set tabstop, softtabstop and shiftwidth to the same value
command! -nargs=* Stab call Stab()
function! Stab()
let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
if l:tabstop > 0
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
endif
call SummarizeTabs()
endfunction
function! SummarizeTabs()
try
echohl ModeMsg
echon 'tabstop='.&l:ts
echon ' shiftwidth='.&l:sw
echon ' softtabstop='.&l:sts
if &l:et
echon ' expandtab'
else
echon ' noexpandtab'
endif
finally
echohl None
endtry
endfunction
" Some file types should wrap their text
function! s:setupWrapping()
set wrap
set linebreak
set textwidth=72
set nolist
endfunction
" tagbar - http://majutsushi.github.com/tagbar/
nmap <F8> :TagbarToggle<CR>
" Allow paste without multiple indents
" Conflicts with snipMate.vim plugin; perhaps manually use `set paste` instead
" set paste
" ----------------------------------------------------------
" Folds
set foldmethod=indent "Fold based on indent
set foldnestmax=3 "Deepest fold is 3 levels
set nofoldenable "Don't fold by default
" ----------------------------------------------------------
" Syntax Highlighting and Validation
"syntax on " syntax highlighing
syntax enable " Turn on syntax highlighting allowing local overrides
"filetype on " try to detect filetypes
"filetype plugin indent on " enable loading indent file for filetype
" PHP highlighting extras
" https://github.com/Apreche/vim/blob/master/vimrc
let php_sql_query = 1
let php_htmlInStrings = 1
let php_baselib = 1
let php_noShortTags=1
" let php_folding=1
"warning when going over 79 characters per line
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%80v.*/
" Only do this part when compiled with support for autocommands
if has("autocmd")
" Enable file type detection
filetype on
" In Makefiles, use real tabs, not tabs expanded to spaces
autocmd FileType make setlocal noexpandtab
" Make sure all markdown files have the correct filetype set and setup wrapping
autocmd BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn,txt} setf markdown | call s:setupWrapping()
" Syntax of these languages is fussy over tabs Vs spaces
autocmd FileType make setlocal ts=8 sts=8 sw=8 noexpandtab
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
" Customisations based on house-style (arbitrary)
autocmd FileType html setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType css setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType less setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType javascript setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType php setlocal noexpandtab ts=4 sts=4 sw=4
autocmd FileType php let g:syntastic_enable_highlighting=0
autocmd FileType php let g:syntastic_quiet_warnings=1
autocmd BufNewFile,BufRead *.sass setfiletype css
autocmd BufNewFile,BufRead *.json setfiletype javascript
autocmd BufNewFile,BufRead *.php setfiletype php
autocmd BufNewFile,BufRead *.phtml setfiletype html
autocmd BufNewFile,BufRead *.hbs setfiletype html
" Treat .rss files as XML
autocmd BufNewFile,BufRead *.rss,*.atom setfiletype xml
" Treat .less files
"autocmd BufNewFile,BufRead *.less setfiletype less "setf less
endif
" Turn on jslint errors by default, 0 to disable
let g:JSLintHighlightErrorLine = 0
" ----------------------------------------------------------
" Colors
" to find a new color scheme just go to http://code.google.com/p/vimcolorschemetest/
set background=dark
"set background=light
" colorscheme darkmate
colorscheme madeofcode
" colorscheme ir_black
" colorscheme mayansmoke
" colorscheme mustang
" colorscheme peaksea
" colorscheme pyte
" Hybrid
" let g:hybrid_use_Xresources = 1
" colorscheme hybrid
" Solarized
" colorscheme solarized
" let g:solarized_termtrans=1
" let g:solarized_degrade=0
" let g:solarized_bold=1
" let g:solarized_underline=1
" let g:solarized_italic=1
" let g:solarized_termcolors=256
" let g:solarized_diffmode="normal"
" let g:solarized_hitrail=0
" let g:solarized_menu=1
" let g:solarized_contrast="high" "default value is normal
" let g:solarized_visibility="high" "default value is normal
" to check vim colors use :echo &t_Co
let &t_Co=256
" ----------------------------------------------------------
" tmux settings
if exists('$TMUX')
set term=screen-256color
endif
if exists('$ITERM_PROFILE')
if exists('$TMUX')
let &t_SI = "\<Esc>[3 q"
let &t_EI = "\<Esc>[0 q"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
end
" for tmux to automatically set paste and nopaste mode at the time pasting (as happens in VIM UI)
function! WrapForTmux(s)
if !exists('$TMUX')
return a:s
endif
let tmux_start = "\<Esc>Ptmux;"
let tmux_end = "\<Esc>\\"
return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
endfunction
let &t_SI .= WrapForTmux("\<Esc>[?2004h")
let &t_EI .= WrapForTmux("\<Esc>[?2004l")
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
" ----------------------------------------------------------
" Status bar
if has("statusline") && !&cp
set laststatus=2 " always show the status bar
" Start the status line
set statusline=%f\ %m\ %r
set statusline+=Line:%l/%L[%p%%]
set statusline+=Col:%v
set statusline+=Buf:#%n
set statusline+=[%b][0x%B]
endif
" Show (partial) command in the status line
set showcmd