-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvimrc
453 lines (349 loc) · 10.5 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
" vim: foldmethod=marker foldcolumn=3
" .vimrc
" Aleksandar Dimitrov
"
" Tue May 29 17:07:37 CEST 2007
"
" Remove all existing autocmds
autocmd!
" Keymappings {{{1
"" Misc {{{2
let mapleader = ","
map ; :
nmap <F9> :diffup<CR>
nmap <leader>$ :call Preserve("%s/\\s\\+$//e")<CR>
nmap <leader>= :call Preserve("normal gg=G")<CR>
set mouse="a"
set backspace=indent,eol,start
" Quick write, but only if changed. I have a nervous pinky.
nmap <CR> :update<CR>
" find files in new buffer
nnoremap gf <C-W>gf
" open file under cursor, create if necessary
nnoremap gF :view <cfile><cr>
set pastetoggle=<F11>
nmap <F12> :tabnew
imap <C-z>n <Esc>:tabnext<cr>
imap <C-z>p <Esc>:tabprev<cr>
" Insert a single character and go back to command mode
noremap S i<Space><Esc>r
" Make Y behave like other capitals
map Y y$
map K k
""" Vim Help Files: make [Return] follow a link
autocmd FileType help nmap <buffer> <Return> <C-]>
"" Abbreviations {{{2
cabbrev Wq wq
cabbrev Q q
cabbrev W w
cabbrev mke make
cabbrev maek make
cabbrev ant Ant
cabbrev want :w<CR>:Ant
abbreviate teh the
"" Turn the file into canonical hexadecimal display {{{2
nnoremap <leader>xh :%!xxd<CR>
nnoremap <leader>xH :%!xxd -r<CR>
"" open files in same directory (vimcasts.org) {{{2
map <leader>ee :e <C-R>=expand("%:p:h") . "/" <CR>
map <leader>es :sp <C-R>=expand("%:p:h") . "/" <CR>
map <leader>et :tabe <C-R>=expand("%:p:h") . "/" <CR>
"" better ex line editing {{{2
cnoremap <C-j> <t_kd>
cnoremap <C-k> <t_ku>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
"" Search {{{2
set gdefault " by default, substitute everything on a line for s//
set smartcase
set incsearch
"" Don't hlsearch, but when I do search for something set hlsearch, then
"" remove it when entering insert mode
set nohlsearch
noremap <leader>sss /
map / :set hlsearch<CR><leader>sss
au InsertEnter * :set nohlsearch
noremap <leader>nnn n
noremap <leader>NNN N
map n :set hlsearch<CR><leader>nnn
map N :set hlsearch<CR><leader>NNN
"" Digraphs {{{2
if has("digraphs")
digraph ., 8230
endif
" Plugins {{{1
filetype plugin indent on
"" Pathogen {{{2
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
"" Fugitive {{{2
"" Fugitive
autocmd BufReadPost fugitive://* set bufhidden=delete
map <leader>gd :Gdiff<CR>
map <leader>gc :Gcommit<CR>
map <leader>gs :Gstatus<CR>
map <leader>gw :Gwrite<CR>
map <leader>gl :Glog<CR>
"" Tagbar {{{2
set showfulltag
set tags=tags;/
nnoremap <silent> <F8> :TagbarToggle<CR>
let g:tagbar_width=25
let g:tagbar_compact=1
"" Tabularize {{{2
if exists(":Tabularize")
nmap <Leader>t= :Tabularize /=<CR>
vmap <Leader>t= :Tabularize /=<CR>
endif
"" Powerline {{{2
let g:Powerline_symbols = 'fancy'
"" Syntastic {{{2
let g:syntastic_mode_map = { 'mode' : 'passive'
\ , 'active_filetypes': ['latex','c']
\ , 'passive_filetypes': ['haskell,java'] }
"" GUndo {{{2
nmap <F5> :GundoToggle<CR>
" Interface {{{1
"" Misc {{{2
"
" Scroll with context"
set scrolloff=3
set sidescrolloff=3
if ((has('syntax') && (&t_Co > 2)) || has('gui_running'))
syntax on
endif
set showmatch mat=3 " Show matching parens for 300ms
colorscheme lucius
set background=dark
set showcmd
set ruler
set lazyredraw
set shortmess=ilmnrwxIat
set nocompatible
set cursorline
if &term =~ "rxvt-unicode"
if (&termencoding == "")
set termencoding=utf-8
endif
" change cursor colour depending on mode state (for term only)
if exists('&t_SI')
let &t_SI = "\<Esc>]12;lightgoldenrod\x7"
let &t_EI = "\<Esc>]12;grey80\x7"
endif
endif
"" Tabbing {{{2
if exists("&showtabline")
set showtabline=2 " always show a tabline
set switchbuf=usetab
endif
"" Line numbers {{{2
set rnu
au InsertEnter * :set nu
au InsertLeave * :set rnu
au FocusLost * :set nu
au FocusGained * :set rnu
function! g:ToggleNuMode()
if (&rnu == 1)
set nu
else
set rnu
endif
endfun
"" Listchars {{{2
" Stolen from http://docs.google.com/View?docid=dfkkkxv5_65d5p3nk
" This enables you to see tab characters and stray whitespace
" Show tabs and trailing whitespace visually
if (&termencoding == "utf-8") || has("gui_running")
set list listchars=tab:▸\ ,trail:·,extends:…,nbsp:‗,eol:¶
else
set list listchars=tab:>\ ,trail:.,extends:>,nbsp:_,eol:¶
endif
nmap <leader>l :set list!<CR>
"" Status bar {{{2
set laststatus=2
set statusline=%t\ %y
set statusline+=%= " right align
set statusline+=%{fugitive#statusline()}%l/%L,%c%m(%P)
"" Indentation {{{2
set smarttab
set ai " No, not Artificial Intelligence...
set ts=8 noet " we want tabs and by default they are 8 spaces long. And TABS!
set cinoptions+=(0,u0 " paren indentation
"" Globbing {{{2
set wildmenu
set wildignore=*.o,*.obj,*.bak,*.exe,*.so,*.class,*~,*.hi
set wildmode=longest,list:longest,full
set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.class
"" Folding {{{2
set foldmethod=syntax
nmap <space> za
vmap <space> zf
set foldtext=MyFoldText()
" Folds preserving indentation and without clutter
function! MyFoldText()
let i = indent(v:foldstart)
return repeat(' ', i) . substitute(getline(v:foldstart), '^\s\+', '', '')
endfunction
" Reload folding and syntax (on entering the buffer)
nmap <F3> :syn sync fromstart<cr>
autocmd BufEnter * syntax sync fromstart
" Languages {{{1
"" XML {{{2
let g:xml_syntax_folding=1
au FileType xml setlocal foldmethod=syntax
" only for apertium:
au BufEnter *dix set ft=xml
"" JSON {{{2
au! BufRead,BufNewFile *.json set filetype=json
augroup json_autocmd
autocmd!
autocmd FileType json set autoindent
autocmd FileType json set formatoptions=tcq2l
autocmd FileType json set textwidth=78 shiftwidth=2
autocmd FileType json set softtabstop=2 tabstop=8
autocmd FileType json set expandtab
autocmd FileType json set foldmethod=syntax
augroup END
"" Java {{{2
let java_highlight_all = 1
" Anonymous classes
set cinoptions+=j1
autocmd FileType java set sw=5 ts=5
""" Eclim {{{3
let g:EclimBrowser='firefox'
autocmd FileType java nmap <leader>i :JavaImport<CR>
autocmd FileType java nmap <leader>d :JavaDocSearch<CR>
autocmd FileType java nmap <Leader>c :JavaCorrect<CR>
autocmd FileType java nnoremap <silent> <buffer> <Leader><CR> :JavaSearchContext<CR>
autocmd FileType java nnoremap <silent> <buffer> <Leader>j :lne<CR>
autocmd FileType java nnoremap <silent> <buffer> <Leader>k :lpre<CR>
autocmd FileType java nnoremap <silent> <buffer> <Leader><Space> :lopen<CR>
"" Lua {{{2
autocmd FileType lua set sw=5 ts=5
"" Prolog {{{2
hi Flicker ctermfg=white cterm=bold
au BufNewFile,BufRead *.pl set filetype=prolog "Perl sucks anyway
au FileType prolog au CursorMoved * exe 'match Flicker /\V\<'.escape(expand('<cword>'), '/').'\>/'
au FileType prolog setlocal suffixesadd=.pl,.plt
"" Haskell {{{2
""" Haskell
" WARNING: this seems to fail in Haskell code when you move around the string
" (\()
" au FileType haskell au CursorMoved * exe 'match ModeMsg /\V\<'.escape(expand('<cword>'), '/').'\>/'
au BufEnter *.cabal,*.hs set expandtab shiftwidth=4
au FileType haskell let b:ghcmod_use_basedir = getcwd()
au FileType lhaskell nnoremap <leader>h1 yyp:s/./=/<CR>
au FileType lhaskell nnoremap <leader>h2 yyp:s/./-/<CR>
nnoremap <leader>ht :GhcModType<CR>
nnoremap <leader>hc :GhcModTypeClear<CR>
nnoremap <leader>hw :GhcModCheckAndLintAsync<CR>
nnoremap <leader>he :GhcModExpand<CR>
au BufNewFile *.cabal 0read ~/.vim/skellies/cabal
let g:ghcmod_use_basedir = getcwd()
"" Fruit salad is tasty.
let hs_highlight_all_types = 1
let hs_highlight_debug = 1
let hs_highlight_toplevel_fundefs = 1
"" Vim2Hs {{{2
let g:haskell_autotags = 1
let g:haskell_tags_generator = 'fast-tags'
"" Perl {{{2
let perl_extended_vars=1 " highlight advanced perl vars inside strings
"" C, C++ {{{2
autocmd BufEnter *.c,*.h abbr FOR for (i = 0; i < 3; ++i)<CR>{<CR>}<Esc>O
autocmd BufLeave *.c,*.h unabbr FOR
au BufEnter *.c,*.h set shiftwidth=5 tabstop=5
"" PHP {{{2
autocmd FileType php let php_folding=1
"" Vimscript {{{2
let g:vimsyn_folding='af'
function! ShowSynStack()
for id in synstack(line("."), col("."))
echo synIDattr(id, "name")
endfor
endfunction
"" Helper functions for writing syntax highlighting code for Vim
nnoremap <Leader><S-S> :call ShowSynStack()<CR>
nnoremap <Leader>s :echo synIDattr(synID(line("."), col("."), 1), "name")<CR>
"" TeX {{{2
function! ReadTeXSkeleton()
if match(bufname("%"),'pres\.tex') >= 0
0read ~/.vim/skellies/pres
else
0read ~/.vim/skellies/tex
endif
endfunction
au BufNewFile *.tex exec ReadTeXSkeleton()
let g:tex_flavor = "latex"
autocmd FileType tex,latex,plaintex iabbrev ... \ldots{}
set grepprg=grep\ -nH\ $*
au FileType tex setlocal iskeyword+=:
"" Text files {{{2
autocmd FileType mail,text,html,xhtml,plaintex,tex,latex setlocal textwidth=80 sw=2 " WordWrap for 'text' files @ 80
set ignorecase
set infercase
autocmd FileType mail,text,plaintex,tex,latex setlocal spell spelllang=en_US
autocmd FileType mail,text nmap <F8> :set spelllang=
" Misc {{{1
" Persistent undo (since 7.3)
if ('persistent_undo')
set undofile
set undodir=~/.vim/undo
endif
" Enable a nice big viminfo file
set viminfo='1000,f1,:1000,/1000
set history=500
set noerrorbells " No concerts, please
set backup
set complete=.,b,u,],i,d,w
" Save and return to normal mode on FocusLost
au FocusLost * :silent! wall " save
au FocusLost * call feedkeys("\<C-\>\<C-n>") " return to normal mode
" Functions {{{1
" Exec command, preserving search pattern and cursor position. {{{2
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
"" Number conversion functions {{{2
"" Print decimal number in Binary
fun! Dec2Bin(nr)
return Dec2Base(a:nr,2)
endfun
"" Print decimal number in hexadecimal
fun! Dec2Hex(nr)
return Dec2Base(a:nr,16)
endfun
"" Print a number in a certain base (max 16)
fun! Dec2Base(nr,base)
let n=a:nr
let r = ""
while n
let r = '0123456789ABCDEF'[n % a:base] . r
let n = n / a:base
endwhile
return r
endfun
"" Print characters in binary (separated by dashes)
fun! String2Bin(str)
return PrintChars(a:str,function("Dec2Bin"))
endfun
"" Print characters in hexadecimal
fun! String2Hex(str)
return PrintChars(a:str,function("Dec2Hex"))
endfun
"" Print characters in given base
fun! PrintChars(str,f)
let out = ''
for ix in range(strlen(a:str))
let out = out . '-' . a:f(char2nr(a:str[ix]))
endfor
return out[1:]
endfun