重新打开(Mac)Vim,并在关闭时打开文件 [英] Making (Mac)Vim reopen with files open when closed
问题描述
用例:
MacVim窗口中显示2-3个文件.您按ctrl + Q,MacVim关闭. 重新启动MacVim时,它将打开,显示与关闭时相同的文件.
You have 2-3 files displayed in your MacVim window(s). You press ctrl+Q and MacVim closes. When you restart MacVim it opens displaying the same files you had when you closed it.
你怎么做到的?
- ANSWER
我在.vmirc中添加了以下内容
I added the following to my .vmirc
"save and close all files and save global session
nnoremap <leader>q :mksession! ~/.vim/Session.vim<CR>:wqa<CR>
"close all files without saving and save global session
nnoremap <leader>www :mksession! ~/.vim/Session.vim<CR>:qa!<CR>
function! RestoreSession()
if argc() == 0 "vim called without arguments
execute 'source ~/.vim/Session.vim'
end
endfunction
autocmd VimEnter * call RestoreSession()
有了这个,我几乎有了我想要的确切行为,唯一的麻烦是我以后仍然需要按Command-q,但这是MacO,而不是vim....
With this I almost have the exact behavior I wanted, the only minor nuisance is that I still need to press command-q afterwards but that's MacOs, not vim....
推荐答案
我建议您阅读有关会话:help session
的信息,这应该可以回答您的问题.甚至还有用于处理会话的漂亮脚本.
I suggest you read about sessions :help session
,that should answer your question. There are even nice scripts to deal with sessions.
这篇关于重新打开(Mac)Vim,并在关闭时打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!