根据我在Vim的任务,我有几个选项卡打开。
如何保存不同的会话以供以后使用?
根据我在Vim的任务,我有几个选项卡打开。
如何保存不同的会话以供以后使用?
当前回答
就我个人而言,我只是包装了Tim Pope的Obsession插件,以允许定义一个sessiondir,并避免输入路径:
let g:sessiondir = $HOME . ".vim/sessions"
command! -nargs=1 MkSession call MkSession(<f-args>)
function! MkSession(sessionfile)
if !isdirectory(g:sessiondir)
call mkdir(g:sessiondir, "p")
endif
exe 'Obsession' g:sessiondir . '/' . a:sessionfile
endfunction
command! -nargs=1 LoadSession call LoadSession(<f-args>)
function! LoadSession(sessionfile)
let a:sessionpath = g:sessiondir . a:sessionfile
if (filereadable(a:sessionpath))
exe 'source ' a:sessionpath
else
echo "No session loaded."
endif
endfunction
其他回答
就我个人而言,我只是包装了Tim Pope的Obsession插件,以允许定义一个sessiondir,并避免输入路径:
let g:sessiondir = $HOME . ".vim/sessions"
command! -nargs=1 MkSession call MkSession(<f-args>)
function! MkSession(sessionfile)
if !isdirectory(g:sessiondir)
call mkdir(g:sessiondir, "p")
endif
exe 'Obsession' g:sessiondir . '/' . a:sessionfile
endfunction
command! -nargs=1 LoadSession call LoadSession(<f-args>)
function! LoadSession(sessionfile)
let a:sessionpath = g:sessiondir . a:sessionfile
if (filereadable(a:sessionpath))
exe 'source ' a:sessionpath
else
echo "No session loaded."
endif
endfunction
你想要的是
:mksession ~/mysession.vim
然后你可以源vim文件,你会有你的旧会话回来:
:source ~/mysession.vim
或者使用-S选项打开vim:
$ vim -S ~/mysession.vim
您可能希望在vimrc中设置这些会话选项。特别是当您在保存会话之后更改了vimrc时,选项非常烦人。
set ssop-=options " do not store global and local values in a session
set ssop-=folds " do not store folds
由于@mathielo 下面是来自@mathielo的例子,我在.vimrc中添加了下面的行来保存活动会话(如果有的话):
au VimLeave * if this_session != "" | exe "mksession! ".this_session
如果你想放更多的行,你需要使用endif:
au VimLeave * if v:this_session != ""
au VimLeave * exe "mksession! ".this_session
au VimLeave * endif
您只需要在vim with中保存一个新会话
:mks [Session filename]
开始之后
$ vim -S [Session filename]
Vim将启动会话,您不必担心每次关闭Vim时都要保存会话。
如果没有活动会话,vimrc将不会做任何事情。像以前一样。
这就是我要找的!再次感谢@mathielo!
你可以把会话存储在任何你想要的地方。
Ex:
:mksession! D:/session.ses
这将会话存储在D驱动器中。
这可以通过输入打开
:so D:/session.ses
在任何vim文件中。