-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
484 lines (449 loc) · 13.8 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
filetype plugin on
filetype indent on
syntax on
set runtimepath+=/usr/share/vim/vimfiles
source /usr/share/vim/vimfiles/plugin/comments.vim
colorscheme darkZ
if hostname() == "archpad" "smaller font for laptop
set guifont=terminus\ 8
set mouse=a
set ttymouse=xterm2 "for scrolling with urxvt
else
set mouse=a
set ttymouse=xterm2 "for scrolling with urxvt
set guifont=xos4\ Terminus\ 12
endif
set hlsearch
set guioptions-=m
set guioptions-=T
set guioptions+=c "show simple dialogs in commandline
set directory=/home/peter/.vim/swp,.,/tmp,/var/tmp
set backupdir=~/.vim/backup "backup dir
set incsearch "start searching as you type
set showcmd "show the number of bytes marked in visual mode
set swapsync= "dont fsync swap file on every change
set showbreak=¤
set t_Co=256 "Use 256 colors instead of 8 or 16
"let g:mapleader = '½'
"let g:maplocalleader = '½'
"set spell
let spell_auto_type="tex,doc,mail"
"General mappings
nnoremap <F8> :buffers<CR>:buffer<Space>
nnoremap <C-t> :TlistToggle<CR>
nnoremap æ :bp!<CR>
nnoremap ø :bn!<CR>
nnoremap å :cclose<CR>
noremap <C-q> <Esc>:confirm bd<CR>
nnoremap <C-k> <C-w><C-k>
nnoremap <C-j> <C-w><C-j>
nnoremap <C-l> <C-w><C-l>
nnoremap <C-h> <C-w><C-h>
"alt-a decrease number under cursor
nnoremap ª :normal! <C-x><CR>
nnoremap á :normal! <C-x><CR>
"alt-g
noremap ŋ
noremap ç
"Completekey for ctags
imap ½ <C-r>=CompleteKey("\<C-x>\<C-o>")<CR>
"Cursor change color in console vim when entering/leaving insert mode
if &term =~ "urxvt"
"Set the cursor white in cmd-mode and orange in insert mode
let &t_EI = "\<Esc>]12;green\x9c"
let &t_SI = "\<Esc>]12;orange\x9c"
"We normally start in cmd-mode
silent !echo -e "\e]12;green\x9c"
endif
"minibufexplorer settings
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplModSelTarget = 1
"let g:miniBufExplForceSyntaxEnable = 1
let g:miniBufExplTabWrap = 1
hi MBEChanged guifg=red ctermbg=darkblue
hi MBEVisibleNormal guifg=blue ctermbg=darkblue
hi MBEVisibleChanged guifg=red ctermbg=darkblue
"buftabs settings
let g:buftabs_only_basename=1
set wildmenu "better menu completion
set wildmode=list:longest,full
set tabstop=4
set smartindent
set ignorecase
set smartcase "Dont ignorecase when upper case is used
set shiftwidth=4
set scrolloff=4
"supertab completion
"let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
"let g:SuperTabLongestHighlight=1
"
set completeopt=menu,longest
"more info for statusline
set laststatus=2
if has("statusline")
set statusline=%<%f\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ %h%m%r%=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"}%k\ %-14.(%l,%c%V%)\ %P
endif
if has("gui_running")
set columns=81
else
"better highlighting for spell checker in console vim
highlight clear SpellBad
highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline
highlight clear SpellCap
highlight SpellCap term=underline cterm=underline
highlight clear SpellRare
highlight SpellRare term=underline cterm=underline
highlight clear SpellLocal
highlight SpellLocal term=underline cterm=underline
endif
"Quckfix window size
au FileType qf call AdjustWindowHeight(3, 8)
function! AdjustWindowHeight(minheight, maxheight)
exe max([min([line("$"), a:maxheight]), a:minheight]) . "wincmd _"
endfunction
""""""""""""""""
""""" c, c++
""""""""""""""""
autocmd Filetype c,cpp call Autocmd_c()
function! Autocmd_c()
setlocal omnifunc=LundComplete
setlocal colorcolumn=80
let b:lundCompleteTagsCmd = "ctags -f /tmp/tagslocal --c++-kinds=+pl ".
\"--language-force=c++ --fields=+iaS --extra=+q /tmp/tagslocal_source"
let b:lundCompleteOmnifunc = "omni#cpp#complete#Main"
call UseTags("ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .")
call UseFunctionPreview()
call UseFunctionHighlighting()
endfunction
" Searching local variables do not require brackets to be in first column
let OmniCpp_LocalSearchDecl = 1
let OmniCpp_ShowAccess = 0 " Do not show access modifiers ('+', '#', '-')
let OmniCpp_ShowPrototypeInAbbr = 1 " Show prototype in popup menu
"""""""""""""""""""""""""
""""""""Python specific
""""""""""""""""""""""""
autocmd FileType python call Autocmd_Python()
function! Autocmd_Python()
setlocal expandtab
set colorcolumn=80
highlight ColorColumn ctermbg=darkred guibg=darkgreen
"ropevim settings
let g:ropevim_codeassist_maxfixes=10
let g:ropevim_guess_project=1
let g:ropevim_vim_completion=1
let g:ropevim_enable_autoimport=1
let g:ropevim_extended_complete=1
"call UseTags
" \("/usr/lib/python2.6/Tools/scripts/ptags.py $(find . -name '*.py')")
"imap <buffer> ½ <C-R>=CompleteKey(
" \"<C-v><C-R>=RopeCodeAssistInsertMode()<C-v><CR><C-v><C-p>")<CR>
"source /usr/share/vim/vimfiles/plugin/ropevim.vim
inoremap <buffer> # X#
endfunction
function! CustomCodeAssistInsertMode()
call RopeCodeAssistInsertMode()
if pumvisible()
return "\<C-L>\<Down>"
else
return ''
endif
endfunction
function! TabWrapperComplete()
let cursyn = synID(line('.'), col('.') - 1, 1)
if pumvisible()
return "\<C-Y>"
endif
if strpart(getline('.'), 0, col('.')-1) =~ '^\s*$' || cursyn != 0
return "\<Tab>"
else
return "\<C-R>=CustomCodeAssistInsertMode()\<CR>"
endif
endfunction
"""""""""""""""""""""""""
"""""""" JAVA specific
"""""""""""""""""""""""""
autocmd FileType java call Autocmd_Java()
function! Autocmd_Java()
nnoremap <silent> <buffer> <cr> :JavaSearchContext<cr>
nnoremap <silent> <buffer> <leader>d :JavaDocSearch -x declarations<cr>
nnoremap <silent> <buffer> <leader>i :JavaImport<cr>
setlocal omnifunc=javacomplete#Complete
call UseTags("ctags -R --fields=+iaS --extra=+q .")
call UseFunctionPreview()
call UseFunctionHighlighting()
endfunction
" other languages
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
autocmd FileType php setlocal omnifunc=phpcomplete#CompletePHP
" Used funcitons
function! UseFunctionHighlighting()
syntax match Function excludenl /\h\w*\s*(/me=e-1
highlight Function ctermfg=2 guifg=Cyan
endfunction
"""""""""""""""""""""""""
"""""""" LATEX options
"""""""""""""""""""""""""
set grepprg=egrep\ -nH\ $*
let g:tex_flavor='latex'
let g:Tex_FormatDependency = 'pdf'
let g:Tex_Leader = '`'
let g:Tex_DefaultTargetFormat = 'pdf'
let g:Tex_CompileRule_pdf = 'make figs; make figs; latexmk -pdf -silent -latexoption=--synctex=1 $*'
"let g:Tex_CompileRule_pdf = 'pdflatex --synctex=1 -interaction=nonstopmode $*'
let g:Tex_MultipleCompileFormats = 'pdf'
"let g:Tex_ViewRule_pdf = 'evince'
let g:Tex_GotoError = 0
let g:Tex_UseMakefile = 0
autocmd BufRead,BufNewFile *.tex setlocal filetype=tex
autocmd BufEnter main.tex setlocal filetype=tex
autocmd BufReadPost main.aux setlocal nobuflisted
autocmd BufReadPost main.log setlocal nobuflisted
autocmd FileType tex call Autocmd_Tex()
function! Autocmd_Tex()
set omnifunc=syntaxcomplete#Complete
syntax spell toplevel
"set fileencoding=latin1
setlocal spell spelllang=en
setlocal textwidth=80
inoremap <buffer> ½2 <Esc>:call TexClosePrev(0)<CR>a
inoremap <buffer> ½h <Esc>:call TexMacro("ac")<CR>a
nmap <F3> :call Tex_CompileLatex()<CR>
nmap <F4> :call EVS_Sync()<CR>
call IMAP('HSI', '\SI{<++>}{<++>}<++>', 'tex')
call IMAP('HSS', '_|<++>|<++>','tex')
call IMAP('||', '|<++>|<++>','tex')
endfunction
function! TexMacro(macro)
exec 'normal a £'
normal gEa}
execute "normal bi\\" . a:macro . "{"
call search("£")
normal Xs
endfunction
"environment macros
let g:Tex_PromptedEnvironments = "align,align*,figure,equation,minipage,table,tabular,enumerate,itemize"
let g:Tex_Env_figure = "\
\\begin{figure}[htbp]\<CR>\
\\centering\\includegraphics[width=<++>\\textwidth]{<++>}\<CR>\
\\caption{<++>}\<CR>\
\\label{fig:<++>}\<CR>\
\\end{figure}\<CR><++>"
let g:Tex_Env_minipage = "\
\\begin{figure}[htbp]\<CR>\
\\centering\<CR>\
\\begin{minipage}[c]{0.47\\textwidth}\<CR>\
\\centering\<CR>\
\\includegraphics[width=1\\textwidth]{<++>}\<CR>\
\\caption{<++>}\<CR>\
\\label{fig:<++>}\<CR>\
\\end{minipage}\\hfill\<CR>\
\\begin{minipage}[c]{0.47\\textwidth}\<CR>\
\\centering\<CR>\
\\includegraphics[width=1\\textwidth]{<++>}\<CR>\
\\caption{<++>}\<CR>\
\\label{fig:<++>}\<CR>\
\\end{minipage}\<CR>\
\\end{figure}\<CR><++>"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Autocompletion, tags, etc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! CompleteKey(key)
if pumvisible()
return "\<C-n>"
else
return a:key
endif
endfunction
" ctags
function! UseTags(tagsCmd)
let b:tagsCmd = a:tagsCmd
map <buffer> <silent> <F2> :call GenerateTags(1)<CR>
endfunction
function! GenerateTags(force)
let l:tagsfound = 0
let l:origdir = getcwd()
while getcwd() != "/"
if filereadable("tags")
let l:tagsfound = 1
let l:tagfile = fnameescape(getcwd() . "/tags")
let &tags.=",".fnameescape(l:tagfile)
break
endif
cd ..
endwhile
if l:tagsfound != 1 && a:force
let l:tagdir = input("Tagdir: ",l:origdir,"dir")
if isdirectory(l:tagdir)
execute "cd " . fnameescape(l:tagdir)
let l:tagsfound = 1
let l:tagfile = fnameescape(getcwd() . "/tags")
let &tags.=",".fnameescape(l:tagfile)
else
echo "b:tagdir not a valid directory!"
endif
endif
if l:tagsfound == 1
call system(b:tagsCmd)
if a:force == 1
echo "Tags generated"
endif
endif
execute "cd " . fnameescape(l:origdir)
endfunction
function! LundComplete(findstart, base)
if a:findstart == 1
execute "return ".b:lundCompleteOmnifunc."(a:findstart, a:base)"
endif
" find range of the current function
let l:view = winsaveview()
normal [{
let l:firstline = line(".")
normal %
let l:lastline = line(".")
call winrestview(l:view)
" write to temporary file and generate tags
execute l:firstline.",".l:lastline." write! /tmp/tagslocal_source"
call system(b:lundCompleteTagsCmd)
execute "let l:result = ".b:lundCompleteOmnifunc."(a:findstart, a:base)"
call system("rm /tmp/tagslocal /tmp/tagslocal_source")
return l:result
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Show function prototypes
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! UseFunctionPreview()
imap <buffer> ) )<C-r>=ClosingParanthesis()<CR><BS>
imap <buffer> <F6> <Esc>:call PreviewPrototype()<CR>a
map <buffer> <F6> <Esc>:call PreviewPrototype()<CR>
let b:previewFunction = ""
endfunction
" returns 0 if function was complete and 1 else
function! IsFuncComplete(str,pos)
let l:level = 0
let l:pos = match(a:str, "[()]", a:pos)
while l:pos >= 0
if a:str[l:pos] == '('
let l:level = l:level + 1
elseif a:str[l:pos] == ')'
let l:level = l:level - 1
endif
if l:level == 0
break
endif
let l:pos = match(a:str, "[()]", l:pos+1)
endwhile
return l:level
endfunction
" get the name of the current open function
function! GetCurrentFunction()
let currline = getline(".")
let subline = strpart(currline, 0, col("."))
" start from the cursor
let l:pos = len(subline)
let l:complete = 0
while l:complete == 0 || l:funcstart == -1
" match last left paranthesis before l:pos
let l:end = match(strpart(subline,0,l:pos+1), "([^(]*$")
if l:end < 1
return ""
endif
" match the last function name before the left paranthesis
let l:funcstart = match(strpart(subline, 0,l:end+1), "[a-zA-Z][^ \t()]*[ \t]*([^(]*$")
if l:funcstart != -1
let l:complete = IsFuncComplete(subline, l:funcstart)
let l:pos = l:funcstart
else
let l:pos = l:end - 1
let l:complete = 1
endif
endwhile
" extract function name
let l:funcstr = matchstr(strpart(subline, 0, l:end+1),"[a-zA-Z][^ \t()]*[ \t]*([^(]*$")
return strpart(l:funcstr,0,len(l:funcstr)-1)
endfunction
function! ClosingParanthesis()
if GetCurrentFunction() != b:previewFunction
wincmd z
endif
endfunction
function! PreviewPrototype()
" Don't do this if inside a preview window
if &previewwindow
wincmd z
return
endif
" If a previewwindow already exists, just close it
for winNr in range(1, winnr("$"))
if getwinvar(winNr, "&previewwindow") == 1
wincmd z
return
endif
endfor
let b:previewFunction = GetCurrentFunction()
if b:previewFunction != ""
silent! execute ":ptag ".b:previewFunction
else
wincmd }
endif
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Make and build functions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set makeprg=
function! MakeWithMaketarget()
if exists("b:maketarget")
call Make(b:maketarget)
elseif exists("g:maketarget")
call Make(g:maketarget)
elseif exists("g:foldermaketarget")
call Make(g:foldermaketarget)
else
echoe "b:maketarget, maketarget og foldermaketarget not defined"
endif
endfunction
function! Make(...)
redraw " make sure any write's before Make() is shown
if exists("a:1")
let l:target = a:1
else
let l:target = ""
endif
if &l:makeprg != ""
execute "make! " . l:target
return
endif
let l:origdir = getcwd()
while 1
if filereadable("Makefile")
let &l:makeprg="make"
execute "make! " . l:target
let &l:makeprg=""
let l:winnr = winnr()
botright cwindow
execute l:winnr . "wincmd w"
for error in getqflist()
if error.valid == 1
crewind
break
endif
endfor
break
elseif filereadable("SConstruct")
let &l:makeprg="scons"
make!
break
elseif getcwd() == "/"
echo "Makefile not found"
break
endif
cd ..
endwhile
execute "cd " . fnameescape(l:origdir)
endfunction