-
Notifications
You must be signed in to change notification settings - Fork 2
/
buffersessions.vim
58 lines (47 loc) · 1.33 KB
/
buffersessions.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
51
52
53
54
55
56
57
58
" Simple sessions for Vim
"
" https://github.com/epeli/vimconfig/blob/master/after/plugin/buffersessions.vim
"
" (c) Esa-Matti Suuronen <esa-matti@suuronen.org>
" Lisence: WTFPL
"
" Default Vim session management tries to be too clever. I want just to save a
" list of open buffers.
"
" Usage:
" Use :SaveSession to save buffer list to BUFS file in the current working
" directory. Vim will now open that list of buffers when the file is found
" from the directory where Vim is launched. It will be read only if Vim is
" called without any arguments
"
" Installation:
" Put this file to ~/.vim/after/plugin/
"
let g:SessionAutoSave = 0
function! SaveSess()
if filereadable('BUFS')
!rm BUFS
endif
" Save buffer list to BUFS file in cwd
bufdo silent !echo :e % >> BUFS
" Command spawning messes up Vim for some reason. Fix it.
redraw!
let g:SessionAutoSave = 1
endfunction
" TODO: requires too many enter presses
function! RestoreSess()
if filereadable('BUFS') && argv() == []
!echo && cat BUFS
if confirm("Load these buffers?", "&Yes\n&No") == 1
source BUFS
redraw!
let g:SessionAutoSave = 1
endif
endif
endfunction
command SaveSession call SaveSess()
call RestoreSess()
autocmd VimLeave *
\ if g:SessionAutoSave |
\ exe "SaveSession" |
\ endif