4

I installed sessionman, and it works fine. But I lose session when reload the X session twice (logout/login, reboot, etc), because when KDE restores Gvim, it does not load session automatically, but only last file, and then saves this under the last session name on next reload. If I did not run SessionOpen then on next reload my last session is lost.

I configured session autosave already. It would be nice if Gvim can load last session automatically too. However, this feature does not work for me even manually. When I restart Gvim, SessionShowLast prints "Last session is undefined, current session is """.

The sessionman documentation says: "The name of an opened session is saved in g:LAST_SESSION variable which is saved in the viminfo file if 'viminfo' option contains '!'". But I have not found any clear explanation what is "viminfo option", where it should contain '!', and how do I set it. Also I'm not sure how to execute SessionOpenLast from vimrc.

If the way I'm trying to fix the problem is wrong then please correct me.

raacer
  • 5,302
  • 3
  • 27
  • 46

2 Answers2

6

viminfo is a variable that describes what data should be stored in the viminfo file.

For full details, run :help 'viminfo' (note the quotes) in vim:

    !       When included, save and restore global variables that start
            with an uppercase letter, and don't contain a lowercase
            letter.  Thus "KEEPTHIS and "K_L_M" are stored, but "KeepThis"
            and "_K_L_M" are not.  Nested List and Dict items may not be
            read back correctly, you end up with a string representation
            instead.                                

Use :set viminfo to see the current value of your viminfo setting. Modify it in your ~/.vimrc file.

set viminfo='100,<500,s10,h,!

Because vimrc is loaded before plugins, adding SessionOpenLast to vimrc will not work. To solve this, create an auto-command:

autocmd VimEnter * SessionOpenLast
sarnold
  • 102,305
  • 22
  • 181
  • 238
  • The quotes in ":help 'viminfo'" command is what I really missed! Thanks )) – raacer Oct 22 '11 at 09:49
  • I Added "!" to default value "'100,<500,s10,h" (for linux) in vimrc: set viminfo='100,<500,s10,h,! And it works. Now looking for the way to run SessionOpenLast from vimrc. – raacer Oct 22 '11 at 09:51
  • I don't know anything about the `sessionman` plugin, but are you lucky enough to just add `SessionOpenLast` to the end of your vimrc? – sarnold Oct 22 '11 at 09:54
  • Error detected while processing /home/artem/.vimrc: line 114: E492: Not an editor command: SessionOpenLast – raacer Oct 22 '11 at 10:02
  • Nice! I suggest adding it as an answer so you can mark it Accepted, so someone else in the future can find it that much more easily. – sarnold Oct 22 '11 at 10:11
  • The problem is described [here](http://stackoverflow.com/questions/6821033/vim-how-to-run-a-command-immediately-when-starting-vim/6821698#6821698) – raacer Oct 22 '11 at 10:11
  • Done. You probably should accept the changes to make them visible to all. – raacer Oct 22 '11 at 10:35
  • Did you edit my answer? If you did, it looks like it didn't survive the edit suggestion moderation queue. (Which does mean a duplication of work to re-write it...) But I actually meant for you to write your own new answer here with full details -- it's perfectly acceptable to answer your own questions. :) – sarnold Oct 22 '11 at 23:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4473/discussion-between-raacer-and-sarnold) – raacer Oct 23 '11 at 20:02
1
  "My Sessionman Conf
  set viminfo='100,<500,s10,h,!
  let sessionman_save_on_exit = 1

  function! ReadSession()
  SessionOpenLast
  endfunction

  " if no file args then open the last session
  autocmd VimEnter * if argc() == 0 | call ReadSession() | endif
byte-pirate
  • 71
  • 1
  • 5