Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

g:autosave option for saving if default session exists #42

Closed
nybblr opened this issue May 11, 2013 · 1 comment
Closed

g:autosave option for saving if default session exists #42

nybblr opened this issue May 11, 2013 · 1 comment

Comments

@nybblr
Copy link

nybblr commented May 11, 2013

I have a use case that doesn't seem too unusual that would be incredibly useful to myself: usually, I don't want to make a default.vim session in any directory I happen to open vim in, otherwise I litter my clean directories with sessions from random times I needed vim open. On the other hand, if I have been using sessions (e.g. default.vim exists) I would like the autosave functionality to be "yes" so that when I quit, default.vim reflects the state of vim before exiting.

In essence, a fourth option of "ifexists", which acts like "no" if there isn't a default.vim in the current directory, and "yes" if there is one. This way, I don't litter my drive with sessions files, but get the autosave functionality where I have explicitly called SaveSession before.

~ Jonathan Martin

@xolox
Copy link
Owner

xolox commented May 12, 2013

Hi Jonathan and thanks for the feedback.

I never intended the session plug-in to be used to store session scripts all over the filesystem :-). The guiding principle was that you would have one directory where all uniquely named session scripts would be stored. Nevertheless I understand that people do this, and that's fine of course, but I'm not going to further compromise the basic design of the plug-in to accomodate this.

Having said all that, I think the plug-in should already be flexible enough to accomodate this use case. Please try adding the fragment of Vim script code given below to your ~/.vimrc script:

autocmd BufReadPost * call s:CheckDefaultSession()

function s:CheckDefaultSession()
  let directory = expand('%:p:h')
  if filereadable(directory . '/default.vim')
    let g:session_autosave = 'yes'
  else
    let g:session_autosave = 'no'
  endif
endfunction

I'm closing this issue now because the code given above should enable your use case without changes to the plug-in. If it doesn't work, feel free to reopen this issue.

@xolox xolox closed this as completed May 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants