-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-fold.vim
More file actions
75 lines (57 loc) · 2.5 KB
/
Copy pathcode-fold.vim
File metadata and controls
75 lines (57 loc) · 2.5 KB
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
""""""""""""""""""""""""""""""""""""""""""""
" let VERSION = '0.0.7'
" let AUTHOR = 'Mike Tang'
" let EMAIL = '[email protected]'
""""""""""""""""""""""""""""""""""""""""""""
set foldenable
set foldmethod=manual
set foldlevel=99
set viewdir=$HOME/.vim/view
se fcs=vert:\|
au BufWinLeave *.* call MMkView() " mkview 1
au BufWinEnter *.* call MLoadView() " silent! loadview 1
function! MMkView()
call InitPlugin()
" most system file starts with '__'
if system("var='" . expand('%:f') . "'; if [[ ${var:0:2} == '__' ]]; then echo 1; else echo 0; fi") == 1
return
endif
let currentFile = system('echo $(echo ' . expand('%:p') . ' | sed "s/[[:space:]]/=/g")"\c"')
let isGit = system('d=`pwd`; while [ "$d" != "" ]; do [ -d "$d"/.git ] && echo 1 && exit; d=${d%/*}; done; echo 0; exit;')
if isGit == 1
let wfile = system('echo ' . '$(echo ${$(echo ' . currentFile . ')//\//=}"\c")-$(git branch | grep "*" | cut -d " " -f2).vim"\c"')
else
let wfile = system('echo ' . '$(echo ${$(echo ' . currentFile . ')//\//=}"\c").vim"\c"')
endif
let command = 'mkview! ' . "~/.vim/view/" . wfile
execute command
endfunction
function! MLoadView()
call InitPlugin()
" most system file starts with '__'
if system("var='" . expand('%:f') . "'; if [[ ${var:0:2} == '__' ]]; then echo 1; else echo 0; fi") == 1
return
endif
let currentFile = system('echo $(echo ' . expand('%:p') . ' | sed "s/[[:space:]]/=/g")"\c"')
let isGit = system('d=`pwd`; while [ "$d" != "" ]; do [ -d "$d"/.git ] && echo 1 && exit; d=${d%/*}; done; echo 0; exit;')
if isGit == 1
let rfile = system('echo ' . '$(echo ${$(echo ' . currentFile . ')//\//=}"\c")-$(git branch | grep "*" | cut -d " " -f2).vim"\c"')
else
let rfile = system('echo ' . '$(echo ${$(echo ' . currentFile . ')//\//=}"\c").vim"\c"')
endif
let rfile = $HOME . "/.vim/view/" . rfile
let fileExists = system('if [ -f ' . rfile . ' ]; then echo 1; else echo 0; fi')
if fileExists == 1
let command = 'source ' . rfile
execute command
endif
endfunction
function! InitPlugin()
let isInit = system('if [ -d ~/.vim/view ]; then echo 1; else echo 0; fi')
if isInit == 0
echo 'This is the first time to set the code fold plugin, create ~/.vim/view folder'
let res = system('mkdir ~/.vim/view')
endif
endfunction
map <leader>zz @=((foldclosed(line('.')) < 0) ? 'zf' : 'zd')<CR>
map ff @=((foldclosed(line('.')) < 0) ? 'zf' : 'zd')<CR>