/
functions.vim
50 lines (46 loc) · 1.34 KB
/
functions.vim
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
" Modularized configuration for vim
" Randy Morris <randy.morris@archlinux.us>
" Functions
function! OpenFoldOnRestore() "{{{
if exists("b:doopenfold")
execute "normal zv"
if(b:doopenfold > 1)
execute "+".1
endif
unlet b:doopenfold
endif
endfunction
"}}}
function! RestoreCursorPos() "{{{
if expand("<afile>:p:h") !=? $TEMP
if line("'\"") > 1 && line("'\"") <= line("$")
let line_num = line("'\"")
let b:doopenfold = 1
if (foldlevel(line_num) > foldlevel(line_num - 1))
let line_num = line_num - 1
let b:doopenfold = 2
endif
execute line_num
endif
endif
endfunction
"}}}
"{{{ Be lazy and 'remap' lowercase commands
"
" Expects a list g:command_line_substitutes which contains two element
" lists of regular expressions which are used as search and replace
" expressions that are completed on the current command line text before
" executing it.
function! CommandLineSubstitute()
let cl = getcmdline()
if exists('g:command_line_substitutes') && getcmdtype() == ':'
for [k, v] in g:command_line_substitutes
if match(cl, k) == 0
let cl = substitute(cl, k, v, "")
break
endif
endfor
endif
return cl
endfunction
"}}}