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.

Blaszard
  • 30,954
  • 51
  • 153
  • 233

2 Answers2

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'
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 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 '13 at 07:58
  • 1
    Add a conditional, e.g. `execute (has('gui_running') ? 'silent!' : '') 'source ~/.vim/Session.vim'` – Ingo Karkat Nov 27 '13 at 08:06
0

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

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
  • 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 '13 at 08:20