-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Restore sessions automatically #2
base: master
Are you sure you want to change the base?
Conversation
I am going to give this some bake time in my personal config before evaluating merging it in. It does have the potential to confuse/annoy people into uninstalling the plugin. |
Yeah, I was in two minds about it. I couldn't think of an elegant way to make it a non-default setting in what's otherwise an elegant and setting-less plugin, either — but I'll cede to your infinite knowledge on that front! |
When I call Vim with
|
When starting Vim, check if a Session.vim file exists in the current directory. If it does, and if we haven't been passed any arguments, then load the session.
Great spot. I can reproduce, and can verify that doing the check within the autocmd works fine. I've updated this branch and rebased into the same commit as before. |
Actually, I'm now getting this error if I start vim in a directory where a session is present, when starting without
|
Ah; it's a problem with the placement of |
When a session file existed, but no manual session was specified, Vim was throwing a syntax error from our autocmd definition. This fixes the problem by moving the `nested` declaration outside the checks for the existence of a session.
Pushed; not sure of the etiquette on squashing this into the previous commit, but let me know and I'll rebase and force push. |
I favor squashes, but a merge isn't on the table in the short term so feel free to leave it for now. |
If this functionality is added, then I would hope that the sessions directory is configurable in some way or another. I am sure that I am not the only user who doesn't like having Session.vim sitting in my project directories. I created monokrome/vim-lazy-obsession for this, but I think that it would be nice if it was just part of vim-obsession as long as it was configurable enough. |
If you're interested in a similar take, maybe look at vphantom/vim-obsession. I've added two commits in this fork: one to load sessions if Vim is invoked with no arguments (this topic), and another one to use ".session.vim" instead of "Session.vim" (personal perference — I hate clutter). |
Long time no code! Let me bring up another workflow I have had trouble solving. The workflow itself first, motivation second:
Now, why. I'm perfectly comfortable with vim in terminal. But I've noticed that in modern multi-tab split-window terminals, often containing nested Exactly that, having a dedicated window which I can always switch to instantly, is a major part of why I've been using stuff like Atom for years. So, back to Vim, and I'm transplanting my workflow onto nvim-qt. Passing arguments like So, how to solve this? Pretty easy in fact, there's a autocmd DirChanged * ++nested
\ if empty(v:this_session) && filereadable('.session.vim') |
\ source .session.vim |
\ endif P.S.: the filename |
What happens if I have a bunch of files open and then I |
@tpope well, those are valid concerns; but you can solve them with dead simple prompts ("Session found in CWD, load? (y/n)" etc), just like xolox/vim-session does. Obviously, there'd better be no prompts on the "hot" UI interaction paths, but in risky corner cases like you describe the python's EAFP doesn't really shine :) FWIW, I'll share some of my findings.
let g:workspace_session_name = '.session.vim'
let g:workspace_session_disable_on_args = 1
if has('nvim')
au DirChanged * ++nested
\ if empty(v:this_session) && filereadable(g:workspace_session_name) |
\ exe ':source' . g:workspace_session_name |
\ endif
endif |
You want to make |
When starting Vim, check if a Session.vim file exists in the current directory. If it does, and if we haven't been passed any arguments, then load the session.
I'm not sure if you wanted this to be an setting thing or even if you wanted to leave it up to people's
.vimrc
s, but I figured it couldn't hurt to submit a pull request — I would certainly think that the automatic behaviour fits the philosophy of the plugin.