-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvimrc
475 lines (404 loc) · 12.9 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
" .vimrc
" Rich Healey 10-11
" A few of these mappings make assumptions about other plugins being
"
" installedness, but in the meantime you can retrieve the script I use to pull
" them all from
" http://github.com/richo/dotfiles
" The datfile is in code/ext/vim/pull_data
" and the script to retrieve them is in bin/pull_ext
set nocompatible
runtime bundle/pathogen/autoload/pathogen.vim
execute pathogen#infect()
" Strangely this doesn't work properly unless declared early
filetype on
filetype indent on
filetype plugin on
set magic
set ff=unix
set wildmode=longest,list,full
set wildmenu
set showcmd
set nohlsearch
set foldmethod=marker
syntax on
set ai
"set nu
set ts=4
set et
set sw=4
set backspace=indent
set ffs=unix,dos
set pastetoggle=<C-\\>
set cpoptions+=$
set tabpagemax=256
let g:jellybeans_background_color = "000000"
let g:jellybeans_overrides = {
\ 'Todo': { 'guifg': '303030', 'guibg': 'f0f000',
\ 'ctermfg': 'Black', 'ctermbg': 'Yellow',
\ 'attr': 'bold' },
\ 'Tabline': { 'guifg': 'c0c0c0', 'guibg': '505050',
\ 'ctermfg': 'Black', 'ctermbg': 'Yellow', },
\ 'TabLineFill': { 'guifg': '000000', 'guibg': '505050',
\ 'ctermfg': 'Black', 'ctermbg': 'Yellow',
\ 'attr': 'bold' },
\ 'TabLineSel': { 'guifg': '404040', 'guibg': '00cccc',
\ 'ctermfg': 'Black', 'ctermbg': 'Yellow',
\ 'attr': 'bold' },
\}
" From the sample vimrc, brought to my attention by Thilo Six
command! DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
" Highlight lines longer than 80 chars.
" I just flick this on if I'm writing docs or emails, generally.
command! LongL call LONGL()
function! LONGL()
if !exists("b:long")
let b:long="matching"
let w:m1=matchadd('Search', '\%<81v.\%>77v', -1)
let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
else
unlet b:long
:call matchdelete(w:m1)
:call matchdelete(w:m2)
endif
endfunction
if executable("sudo") " and $visudo ?
command! W w !sudo tee % > /dev/null
else
" XXX This will overwrite other files
" :W somefile -> :w ???
"command W w
endif
set directory=./.swap,~/.vim/swap,.,/tmp
set backupdir=./.swap,~/.vim/swap,.,/tmp
let g:fugitive_abbreviate_branches = '2'
let g:gist_detect_filetype = 1
" Hax to let us have multiple highlights within a single file
" http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file
" This took me so long to find and get working properly.
function! TextEnableCodeSnip(filetype,start,end,textSnipHl) abort "{{{
let ft=toupper(a:filetype)
let group='textGroup'.ft
if exists('b:current_syntax')
let s:current_syntax=b:current_syntax
" Remove current syntax definition, as some syntax files (e.g. cpp.vim)
" do nothing if b:current_syntax is defined.
unlet b:current_syntax
endif
execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
try
execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
catch
endtry
if exists('s:current_syntax')
let b:current_syntax=s:current_syntax
else
unlet b:current_syntax
endif
execute 'syntax region textSnip'.ft.'
\ matchgroup='.a:textSnipHl.'
\ start="'.a:start.'" end="'.a:end.'"
\ contains=@'.group.'
\ containedin=ALL'
" XXX ^^ This is needed for PHP, everything in a <?PHP ... ?> block is part
" of a highlighting group, which breaks the rule as per vanilla in the wiki.
endfunction "}}}
"Python Trickery {{{
" This is a hack for sql files that define plpython functions
" .plpy is probably a better extension now I think of it...
" I wrote a lot of functions that lived in a PostgreSQL database in python
" This was a rule to let the scripts look half decent on screen.
function! CONFIGPYSQL()
set ft=sql
call TextEnableCodeSnip('python', '#@<py', '#@</py', 'SpecialComment' )
endfunction
au BufRead,BufNewFile *.py{c,w,o,x} set ft=python
"}}}
" Varnish hax {{{
au BufRead,BufNewFile *.vcl set ft=vcl
" }}}
" HAML hax {{{
" Haml likes indents of 2 spaces, just like our ruby.
au FileType haml call TwoSpace()
" }}}
" Brainfuck hax {{{
" Brainfuck is excellent. Winrar!
au BufNewFile,BufRead *.bf set filetype=brainfuck
" }}}
" Executables Hax {{{
function! ExecutableOrWarn(bin)
if executable(a:bin)
return 1
else
echo a:bin . " not available"
return 0
endif
endfunction
"}}}
" Ruby Hax {{{
" Prawn files are includes for a pdf rendering library
au BufNewFile,BufRead *.prawn set filetype=ruby
" This is specific to rails apps, but I will not bind it to a particular
" filetype
function! TwoSpace()
setlocal ts=2
setlocal sw=2
endfunction
au FileType ruby call TwoSpace()
au FileType coffee call TwoSpace()
au FileType vim call TwoSpace()
au FileType javascript call TwoSpace()
au BufNewFile,BufRead *.erb call TwoSpace()
" }}}
" Makefile Hax {{{
"
" In Makefile, automatically convert eight spaces at the beginning
" of line to tab, as you type (or paste).
au FileType make :inoremap <buffer><silent><Space> <Space><c-o>:call MapSpaceInMakefile()<CR>
function! MapSpaceInMakefile()
" if this space is 8th space from the beginning of line, replace 8 spaces with
" one tab (only at the beginning of file)
let line = getline('.')
let col = col('.')
if strpart(line, 0, 8) == ' '
let new = "\t" . strpart(line,8)
call setline('.', new )
endif
return ""
endfunction
" }}}
" XML Hax {{{
" http://vim.wikia.com/wiki/Vim_as_XML_Editor
" I can't fathom why this isn't a default
let g:xml_syntax_folding=1
au FileType xml setlocal foldmethod=syntax
au FileType xml normal zR
" Wix is xml..
au BufNewFile,BufRead *.wxs set filetype=xml
" }}}
" {{{ svn hax
command! SVNa !svn add %
" }}}
"Crazy hack to update screen sessions..
" TODO I Really want to have the [+-] stuff to show modified :(
" Show number of buffers if >1
" Also, doesn't show hostname on remotes
let g:win_title = $t_prefix
let g:m_title = ''
function! GetTitle()
if $t_prefix == ''
if filereadable(".title") || filereadable(".git/description") || filereadable(".git")
let g:m_title=system("title") . ": "
endif
endif
call UpT()
endfunction
let g:debug_status = ''
function! UpT()
" Set this up to ignore some dud expansions like NERD*
if expand("%:t") !~ 'NERD_tree'
let &titlestring = g:m_title . g:win_title . expand("%:t") . g:debug_status
endif
endfunction
au BufEnter * call UpT()
if $INSCREEN != "" && $USER != "root"
"This is profoundly broken if we're not in screen.
set t_ts=k
set t_fs=\
let &titleold=$sTITLE
set title
else
let g:m_title = 'VIM: '
endif
" Sometimes I have some context for a window: allow us to set that.
function! SETT(title)
let g:win_title = a:title . ': '
call UpT()
endfunction
command! -nargs=1 Tag call SETT(<f-args>)
" This will almost certainly break shit..
if $VIM256 != "" && $USER != "root"
set t_Co=256
colorscheme jellybeans
endif
" SToring for reference, fix broken/missing terminfo for 16colors
"if has("terminfo")
"set t_Co=8
"set t_Sf=[3%p1%dm
"set t_Sb=[4%p1%dm
"else
"set t_Co=8
"set t_Sf=[3%dm
"set t_Sb=[4%dm
"endif
" Remap some keys to be a little more screenlike
nnoremap <C-c> <C-a>
nnoremap <C-a> <C-w>
" XXX Don't forget that C-M-p is now paste in my urxvt, so I can
" only rebind that in gvim..
"
" Evidently I have to choose between these and the tab ones
" ^W is a lot easier to use than the awkward tab commands
"nnoremap <C-n> <C-w>l
"nnoremap <C-p> <C-w>h
" Tab support?
nmap <C-n> :tabnext<cr>
nmap <C-p> :tabprevious<cr>
nmap <leader>n :set number!<cr>
nmap cv :Gcommit -v<cr>
vmap <BS><BS> <Bslash><Bslash>
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css 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
if exists('g:fugitive_abbreviate_branches')
if ! match(g:fugitive_abbreviate_branches, '^[0-9]+')
" Spit out a warning about invalid values?
let g:fugitive_abbreviate_branches = '1'
endif
let g:abbreviate_pattern = '\([0-9A-Za-z_-]\{1,' . g:fugitive_abbreviate_branches . '}\)[^/]*/'
endif
" I believe this should effectively be a hook that runs after all loads
function! AFTERLOAD()
" {{{ Fugitive kludges
" XXX This only gets loaded for known filetypes.. wrong?
"
" Statusline?
set statusline=%f\ %h%m%r
set laststatus=2
if exists('g:loaded_fugitive')
if exists('g:abbreviate_pattern')
" let status = substitute(status, g:abbreviate_pattern, '\1/', 'g')
set statusline+=[%{substitute(FugitiveHead(7),g:abbreviate_pattern,'\\1\\2/','g')}]
else
set statusline+=%{fugitive#statusline()}
endif
endif
if exists('g:loaded_rvm')
set statusline+=%<%{rvm#statusline()}
endif
set statusline+=%=%-5.(%l,%c%V%)\ %P
" }}}
endfunction
autocmd FileType * call AFTERLOAD()
function! FixWhiteSpaceAndReturn()
if expand('%') == '.git/addp-hunk-edit.diff'
return
endif
normal mz
" Hack for my mail :/
:%s/^-- $/-- BUTTS/e
:%s/\s\+$//e
:%s/^-- BUTTS$/-- /e
normal `z
endfunction
autocmd BufWritePre * call FixWhiteSpaceAndReturn()
" Kludge to put titles back after using fugitive to commit
autocmd BufWritePost COMMIT_EDITMSG set title
command! StatusDebug set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
command! StatusNormal call AFTERLOAD()
autocmd BufNewFile,BufReadPost * if match(expand("%:p:h"), "/opencog") >= 0 && &filetype == "cpp" | set ts=4 sw=4 tw=80 ff=unix cindent expandtab | endif
autocmd User chdir Rvm
autocmd User chdir call GetTitle()
autocmd BufNewFile * silent! 0r ~/.templates/%:t
autocmd BufNewFile * silent! 0r ~/.templates/%:e
map <leader>e :NERDTreeToggle<CR>
map <leader>ge :NERDTreeFind<CR>
" Configure NERD
let NERDTreeMinimalUI=1
let NERDTreeDirArrows=1
let NERDTreeIgnore=['\.pyc$']
"^^ Not totally sold on this
map <leader>q :tabclose<CR>
map <leader>tt :!ctags -R .<CR>
" vsplits 'n shit
map <leader>vgf :vertical wincmd f<CR>
map <leader>wgf :wincmd f<CR>
map <leader>tgf :wincmd gf<CR>
map <leader>wt :sp<cr>
map <leader>vt :vsp<cr>
" Goto template {{{
function! GetTemplate(file)
" TODO - Make this configurable
return "templates/" . substitute(a:file, 'php', 'tpl', '')
endfunction
function! GetJavsacript(file)
" TODO - Make this configurable
return "Javascript/" . substitute(a:file, 'php', 'js', '')
endfunction
function! GotoTemplateC(action)
let template = GetTemplate(expand("%"))
execute a:action . " " . template
endfunction
function! GotoJavascriptC(action)
let template = GetJavsacript(expand("%"))
execute a:action . " " . template
endfunction
function! GotoTemplateF(action)
normal "byiw
let template = GetTemplate(@b)
echo a:action . " " . template
endfunction
function! GotoJavascriptF(action)
normal "byiw
let template = GetTemplate(@b)
echo a:action . " " . template
endfunction
" Current file
map <leader>gt :call GotoTemplateC("edit")<cr>
map <leader>vgt :call GotoTemplateC("vsplit")<cr>
map <leader>tgt :call GotoTemplateC("tabedit")<cr>
map <leader>sgt :call GotoTemplateC("split")<cr>
map <leader>gj :call GotoJavascriptC("edit")<cr>
map <leader>vgj :call GotoJavascriptC("vsplit")<cr>
map <leader>tgj :call GotoJavascriptC("tabedit")<cr>
map <leader>sgj :call GotoJavascriptC("split")<cr>
" File under cursor
" These do work.. kinda. Honestly I don't think it's ready.
" map <leader>gft :call GotoTemplateF("edit")<cr>
" map <leader>vgft :call GotoTemplateF("vsplit")<cr>
" map <leader>tgft :call GotoTemplateF("tabedit")<cr>
" map <leader>sgft :call GotoTemplateF("split")<cr>
" }}}
map <leader>c :checktime <CR>
" Not sure about this, although I pretty rarely type jj afaik
inoremap jj <ESC>
inoremap JJ <Esc>A
" I'm suggesting this is pretty safe
inoremap <% <% %><Esc>hhi
" {{{ Project finding kludges
function! StartCoding()
let l:dir = expand("$HOME/code/ext")
exec "chdir" l:dir
NERDTree
endfunction
if isdirectory(expand("$HOME/code/ext"))
nmap <leader>s :call StartCoding()<CR>
endif
" }}}
" TOhtml
let html_use_css = 1
augroup hbs
au!
autocmd BufNewFile,BufRead *.html.hbs set syntax=html
augroup END
let g:indent_guides_start_level = 2
let g:indent_guides_guide_size = 1
" let g:indent_guides_enable_on_vim_startup = 1
map <leader>m :IndentGuidesToggle<cr>
" Syntastic
let g:syntastic_python_checker_args="--max-complexity=12 --ignore=E126,E123,E128"
" Turns on checking of rust tests
let g:rust_cargo_check_tests = 1
if filereadable(expand("$HOME/.vimrc.local"))
source ~/.vimrc.local
endif
if isdirectory(expand("$HOME/code/ext"))
set cdpath+=~/code/ext
endif
if isdirectory(expand("$BOOM_SRC"))
set cdpath+=$BOOM_SRC
endif