Reputation: 18108
So, I've added this function to my gvimrc
, trying to get MacVim to re-open the same windows / same files, when rebooting.
" http://stackoverflow.com/questions/7955232/making-macvim-reopen-with-files-open-when-closed
" save and close all files and save global session
nnoremap <leader>q :mksession! ~/.vim/gvim-session.vim<CR>:wqa<CR>
" close all files without saving and save global session
nnoremap <leader>www :mksession! ~/.vim/gvim-session.vim<CR>:qa!<CR>
function! RestoreSession()
if argc() == 0 " vim called without arguments
let sessionFile='source ~/.vim/gvim-session.vim'
execute sessionFile
:call delete(sessionFile)
end
endfunction
autocmd VimEnter * call RestoreSession()
However, now, when I open MacVim, I get a completely blank window (that is, not even the ~~~
s denoting blank lines, nor a status-bar or sign column or anything else) until I hit the return key:
I'm not sure what I'm doing wrong in my function to cause that. Any help?
Upvotes: 1
Views: 587
Reputation: 196926
You can and should drop the initial :
in
:call delete(sessionFile)
delete()
deletes a file but sessionFile
doesn't point to a file:
let sessionFile='source ~/.vim/gvim-session.vim'
It should look like that:
let sessionFile='~/.vim/gvim-session.vim'
Why did you put source
in the file path anyway? You could simply do the following:
execute "source " . sessionFile
Upvotes: 2