-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
508 lines (403 loc) · 12.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
call pathogen#runtime_append_all_bundles()
" Disable Generation of Backup Files
" ----------------------------------
" actually they are nice but vim is stable and doesn't crash :D
set nobackup
set noswapfile
" Some File Type Stuff
" --------------------
" Enable filetype plugins and disable indentation
syntax on
filetype on
filetype plugin on
filetype indent off
" Proper line breaking / word wrapping
" ------------------------------------
" Enable a proper word wrapping
set formatoptions=l
set lbr
" Leader
" ------
" sets leader to ',' and localleader to "\"
let mapleader=","
let maplocalleader="\\"
" User Interface
" --------------
" activate wildmenu, permanent ruler and disable Toolbar, and add line
" highlightng as well as numbers.
" also highlight current line and disable the blinking r.
set guioptions-=T
set guioptions-=m
set gcr=a:blinkon0
set ruler
set nocursorline
set wildmenu
" Set Better Indention
" --------------------
" go with smartindent if there is no plugin indent file.
" but don't outdent hashes
set smartindent
inoremap # X#
" indent comments correctly?
set fo+=c
set backspace=indent,eol,start
" set textwidth=120
" Statusbar and Linenumbers
" -------------------------
" Make the command line two lines heigh and change the statusline display to
" something that looks useful.
set cmdheight=2
set laststatus=2
set showcmd
set number
" To emulate the standard status line with 'ruler' set, use this:
"
" set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
"
runtime /home/ente/.vim/plugin/pythonhelper.vim
if !exists("*TagInStatusLine")
function TagInStatusLine()
return ''
endfunction
endif
if !exists("*haslocaldir")
function! HasLocalDir()
return ''
endfunction
else
function! HasLocalDir()
if haslocaldir()
return '[lcd]'
endif
return ''
endfunction
endif
set statusline= " my status line contains:
set statusline+=%n: " - buffer number, followed by a colon
set statusline+=%<%f " - relative filename, truncated from the left
set statusline+=\ " - a space
set statusline+=%h " - [Help] if this is a help buffer
set statusline+=%m " - [+] if modified, [-] if not modifiable
set statusline+=%r " - [RO] if readonly
set statusline+=\ " - a space
set statusline+=%1*%{TagInStatusLine()}%* " [current class/function]
set statusline+=\ " - a space
set statusline+=%= " - right-align the rest
set statusline+=%-10.(%l,%c%V%) " - line,column[-virtual column]
set statusline+=\ " - a space
set statusline+=%4L " - total number of lines in buffer
set statusline+=\ " - a space
set statusline+=%P " - position in buffer as percentage
" Tab Settings
" ------------
set smarttab
set tabstop=4
set shiftwidth=4
set softtabstop=4
" utf-8 default encoding
" ----------------------
set enc=utf-8
" The PC is fast enough, do syntax highlight syncing from start
autocmd BufEnter * :syntax sync fromstart
" python support
" --------------
" don't highlight exceptions and builtins. I love to override them in local
" scopes and it sucks ass if it's highlighted then. And for exceptions I
" don't really want to have different colors for my own exceptions ;-)
"
autocmd FileType python setlocal expandtab shiftwidth=4 tabstop=8 omnifunc=pythoncomplete#Complete
\ formatoptions+=croq softtabstop=4 smartindent
\ cinwords=if,elif,else,for,while,try,except,finally,def,class,with
let python_highlight_all=1
let python_highlight_exceptions=0
let python_highlight_builtins=0
" LessCSS Support
" ---------------
au BufNewFile,BufRead *.less set filetype=less
autocmd FileType less setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
" Scss Support
" ------------
au BufNewFile,BufRead *.scss set filetype=scss
autocmd FileType scss setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
" C/C++ Support
" -----------
autocmd FileType cpp setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
autocmd FileType c setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4 omnifunc=ccomplete#Complete
" C# Support
" ----------
autocmd FileType cs setlocal shiftwidth=8 tabstop=8 softtabstop=8
" CoffeeScript Support
" --------------------
" au BufNewFile,BufRead *.coffee set filetype=less
" autocmd FileType coffee setlocal shiftwidth=2 tabstop=2 softtabstop=2
au BufNewFile,BufRead *.coffee setl expandtab shiftwidth=2 tabstop=2 softtabstop=2
" Inyoka Syntax Support
" ---------------------
au BufRead,BufNewFile *.uu set filetype=inyoka
" template language support (SGML / XML too)
" ------------------------------------------
" and disable taht stupid html rendering (like making stuff bold etc)
fun! s:SelectHTML()
let n = 1
while n < 50 && n < line("$")
" check for jinja
if getline(n) =~ '{%\s*\(extends\|block\|macro\|set\|if\|for\|include\|trans\)\>'
set ft=htmljinja
return
endif
" check for django
if getline(n) =~ '{%\s*\(extends\|block\|comment\|ssi\|if\|for\|blocktrans\)\>'
set ft=htmldjango
return
endif
" check for mako
if getline(n) =~ '<%\(def\|inherit\)'
set ft=mako
return
endif
" check for genshi
if getline(n) =~ 'xmlns:py\|py:\(match\|for\|if\|def\|strip\|xmlns\)'
set ft=genshi
return
endif
let n = n + 1
endwhile
" go with html
set ft=html
endfun
autocmd FileType html,xhtml,htmldjango,htmljinja,eruby,mako setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2 omnifunc=htmlcomplete#CompleteTags
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd BufNewFile,BufRead *.rhtml setlocal ft=eruby
autocmd BufNewFile,BufRead *.mako setlocal ft=mako
autocmd BufNewFile,BufRead *.tmpl setlocal ft=htmljinja
autocmd BufNewFile,BufRead *.py_tmpl setlocal ft=python
autocmd BufNewFile,BufRead *.html,*.htm call s:SelectHTML()
let html_no_rendering=1
let g:closetag_default_xml=1
autocmd FileType html,htmldjango,htmljinja,eruby,mako let b:closetag_html_style=1
autocmd FileType html,xhtml,xml,htmldjango,htmljinja,eruby,mako source ~/.vim/scripts/closetag.vim
function! DoPrettyXML()
" save the filetype so we can restore it later
let l:origft = &ft
set ft=
" delete the xml header if it exists. This will
" permit us to surround the document with fake tags
" without creating invalid xml.
1s/<?xml .*?>//e
" insert fake tags around the entire document.
" This will permit us to pretty-format excerpts of
" XML that may contain multiple top-level elements.
0put ='<PrettyXML>'
$put ='</PrettyXML>'
silent %!xmllint --format -
" xmllint will insert an <?xml?> header. it's easy enough to delete
" if you don't want it.
" delete the fake tags
2d
$d
" restore the 'normal' indentation, which is one extra level
" too deep due to the extra tags we wrapped around the document.
silent %<
" back to home
1
" restore the filetype
exe "set ft=" . l:origft
endfunction
command! PrettyXML call DoPrettyXML()
" CSS
" ---
autocmd FileType css setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2 omnifunc=csscomplete#CompleteCSS
" rst
" ---
autocmd BufNewFile,BufRead *.rst setlocal ft=rst
autocmd FileType rst setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
" Inyoka
" ------
autocmd bufNewFile,BufRead *.txt setlocal ft=inyoka
autocmd FileType inyoka setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
" Javascript
" ----------
autocmd FileType javascript setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2 omnifunc=javascriptcomplete#CompleteJS
let javascript_enable_domhtmlcss=1
" SQL
" ---
autocmd FileType sql setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
" Sh and Makefile
" ---------------
autocmd FileType make,sh,ksh,zsh,csh,tcsh,bash setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
" LaTex
" -----
autocmd BufNewFile,BufRead *.tex setlocal ft=tex
autocmd FileType tex setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2 textwidth=78
" Vim Syntax
" ----------
autocmd FileType vim setlocal expandtab shiftwidth=2 tabstop=8 softtabstop=2
" Git Config
" ---------
autocmd BufNewFile,BufRead .gitconfig setlocal ft=gitconfig
autocmd FileType gitconfig setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
" JSON
" ----
au! BufRead,BufNewFile *.json setfiletype json
" Vagrantfile support
" -------------------
au BufRead,BufNewFile Vagrantfile set filetype=ruby
autocmd FileType ruby setlocal expandtab shiftwidth=4 tabstop=8
" Puppet support
" --------------
au BufRead,BufNewFile *.pp setfiletype puppet
" Clojure
autocmd FileType clojure setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
" Folding
" -------
"
" Some folding abbreviations as well as default saving
" and loading of fonts.
nmap <C-F> :fold<cr>
nmap <C-S-F> :foldopen<cr>
" au BufWinLeave * mkview
" au BufWinEnter * silent loadview
" File Browser
" ------------
" hide some files and remove stupid help
let g:explHideFiles='^\.,.*\.sw[po]$,.*\.$'
let g:explDetailedHelp=0
map :Explore!<CR>
" Command-T
" ---------
set wildignore+=*.o,*.obj,.git,*.pyc,*.pyo
" Better Search
" -------------
set hlsearch
set incsearch
set ignorecase
" Minibuffer
" ----------
" one click is enough and fix some funny bugs
let g:miniBufExplUseSingleClick = 1
" BufClose
" --------
" map :BufClose to :bq and ^Q
let g:BufClose_AltBuffer = '.'
cnoreabbr <expr> bq 'BufClose'
cnoreabbr <expr> bop 'buffer'
map :BufClose<cr>
" Supertab
" --------
" Some configuration for supertab
"let g:SuperTabDefaultCompletionType = 'context'
"let g:SuperTabCompletionContexts = ['s:ContextText', 's:ContextDiscover']
"let g:SuperTabContextTextOmniPrecedence = ['&omnifunc', '&completefunc']
let g:SuperTabDefaultCompletionType = "context"
" Misc Buffer Shortcuts/Configurations
" ------------------------------------
set hidden
nmap <C-Tab> :bnext<cr>
nmap <C-S-Tab> :bprev<cr>
nmap <C-S-Left> :bprev<cr>
nmap <C-S-Right> :bnext<cr>
set switchbuf=useopen " quickfix reuses open windows
" Mapping for removing that damned characters
" ----------------------------------------------
nmap <C-S-M> :%s///g<cr>
" Define better search mapping
" ----------------------------
" `*` searches the current selection forwards
" `#` searches the current selection backwards
" `gv` vimgrep' for the current selection
"
function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction
" From an idea by Michael Naumann
function! VisualSearch(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>
vnoremap <silent> gv :call VisualSearch('gv')<CR>
" Some omni completition hacking
" ------------------------------
" * Enter just selects the entry but don't apply it
set completeopt=menuone,longest,preview
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Some small NERDTree support
" ---------------------------
function ToggleNERDTree()
execute 'NERDTreeToggle ' . getcwd()
endfunction
nmap <F5> :call ToggleNERDTree()<cr>
" Buffer indexes :-)
" ------------------
noremap <A-1> :b 1<cr>
noremap <A-2> :b 2<cr>
noremap <A-3> :b 3<cr>
noremap <A-4> :b 4<cr>
noremap <A-5> :b 5<cr>
noremap <A-6> :b 6<cr>
noremap <A-7> :b 7<cr>
noremap <A-8> :b 8<cr>
noremap <A-9> :b 9<cr>
noremap <A-0> :b 10<cr>
noremap <A-q> :b 11<cr>
noremap <A-w> :b 12<cr>
noremap <A-e> :b 13<cr>
noremap <A-r> :b 14<cr>
noremap <A-t> :b 15<cr>
" Bug workarounds
" ---------------
" obviously there are some fancy bugs. Here are some workarounds:
" The r disappears in vertical split. This shortcut is able to restore it
map <C-L> :let &guifont=&guifont<cr>
" Lodgeit
" -------
"
" Copy to Lodgeit on ^p
map <C-p> :Lodgeit<CR>
" Virtualenv
" ----------
"
" Add the virtualenv's site-packages to vim path
py << EOF
import os.path
import sys
import vim
if 'VIRTUAL_ENV' in os.environ:
project_base_dir = os.environ['VIRTUAL_ENV']
sys.path.insert(0, project_base_dir)
activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
EOF
" Avoid scrolling problems
set lazyredraw
let g:solarized_termcolors=256
call togglebg#map("<F6>")
let g:solarized_visibility = 'low'
let g:solarized_contrast = 'high'
map <F12> :r! date +\%H:\%M<cr>
" Enable Syntax Colors
" --------------------
" in GUI mode we go with fruity and Consolas 10
" in CLI mode desert looks better (fruity is GUI only)
if has('gui_running')
set background=dark
set guifont=Consolas\ 13
colorscheme solarized
else
set background=dark
colorscheme desert
endif