ELLIOTTCABLE
ELLIOTTCABLE

Reputation: 18108

MacVim blank screen on startup with simple session-restore function

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:

enter image description here

I'm not sure what I'm doing wrong in my function to cause that. Any help?

Upvotes: 1

Views: 587

Answers (1)

romainl
romainl

Reputation: 196926

  1. You can and should drop the initial : in

    :call delete(sessionFile)
    
  2. 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'
    
  3. Why did you put source in the file path anyway? You could simply do the following:

    execute "source " . sessionFile
    

Upvotes: 2

Related Questions