0

I use Vim mostly through OS X's MacVim application, but I also use it from within Terminal. However, since I use the following vim code in order to make use of session to keep previous files always open in next session:

In ~/.vimrc:

function! RestoreSession()
  if argc() == 0 "vim called without arguments
    execute 'source ~/.vim/Session.vim'
  end
endfunction
autocmd VimEnter * call RestoreSession()

when I use MacVim, there are no issues there, but when I use Vim from within Terminal, whenever I type in commands (vim) and start to use it, I first got a lot of error messages like Error detected while processing /Users/myUserName/.vim/Session.vim: line 265: "path/to/my/file.js" 19L, 626C

So I wonder what is the best way to cope with the above issue:

  • Always use Vim only on MacVim (which I don't like...)

  • Modify the above code snippet a bit to make it valid only through MacVim if it is feasible

  • Stand those error messages (I can use Vim after seeing those errors - I just don't like seeing it and typing "ENTER" a lot whenever I use it in Terminal)

I'd like to take the second solution if it is feasible, but how can I do it? And are there other solutions that you know are better in this situation?

Thanks.

2
  • What command is in line 265?! Nov 27, 2013 at 7:43
  • Do you use MacVim's CLI executable or some other, like the default one?
    – romainl
    Nov 27, 2013 at 8:18

2 Answers 2

1

Unless you can figure out what's the root cause of the errors (and as you're apparently content with the restore even with those errors), you can suppress them via:

silent! execute 'source ~/.vim/Session.vim'
2
  • So my question is, how can I silent those errors only when I use it from within Terminal, but NOT from MacVim?
    – Blaszard
    Nov 27, 2013 at 7:58
  • 1
    Add a conditional, e.g. execute (has('gui_running') ? 'silent!' : '') 'source ~/.vim/Session.vim' Nov 27, 2013 at 8:06
0

Put any settings that you only want to use in the GUI version into a .gvimrc file instead.

1
  • Thanks. But then I cannot use the session functionality when I use it from within Terminal - I want to only avoid those error messages while making use of sessions.
    – Blaszard
    Nov 27, 2013 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.