dhruvasagar / vim-prosession

Handle vim sessions like a pro
254 stars 22 forks source link

Option to load last opened session #36

Closed alex-shamshurin closed 7 years ago

alex-shamshurin commented 7 years ago

I use this plugin to make new session and ctrlp-obsession plugin to switch between them, but I feel a lack of initial loading of last edited session. Is there a option to do it? It's a bit annoying for me to be opened at my home dir each time I start vim. (it's GUI version and I don't want to configure many desktops icons - one for each project). Most IDE's do it.

dhruvasagar commented 7 years ago

Hi, there's an option g:prosession_default_session which you can enable by setting it to 1. When you open vim in a directory for which a session doesn't already exist (you can remove session for your home directory), it then creates a special session by the name 'default' for the purpose of treating it as the default fallback session. Subsequent launches will load this default session unless another session was saved for that directory.

PS : This feature hasn't been tested exhaustively so may have some gotchas. Kindly play around with it and let me know if it works as you'd expect. (I don't personally use it).

PSS : Aside from this, I switched to using vim within a terminal a while ago, it works better (IMO) when launching vim from the directory where you want to work and have the session loaded on startup rather than having to always 'cd', 'Prosession \' every time.

alex-shamshurin commented 7 years ago

But I have session for my home directory - for editing my vim files. And time to time I need to switch current session back to home directory session for vim configs adjusting. I think the default session is not related for this case. I think plugin must switch to last edited session if vim itself was started from home directory regardless of existence session inside home if some option was specified.

I switched from terminal VIM to GVIM because of better colours support, better highlighting (like modern IDEs do) and it's independent of console fonts and may be used across all systems.

dhruvasagar commented 7 years ago

I don't want to give any directory special treatment, even if it is the home directory. Irrespective of which directory VIM starts from, the behavior should be consistent in that prosession tries to load a session that already exists or otherwise creates a new one. If there already exists a session, loading a previously used session instead of the one for the current directory would be inconsistent / awkward.

PS : Modern terminals have better colors support, syntax highlighting and most other features that GUI seems to offer. VIM experience within terminal has evolved quite a bit, especially if you are willing to switch to more modern forks such as NeoVIM.

dhruvasagar commented 7 years ago

Note, the behavior of prosession need to also be consistent with whether you're starting VIM or trying to switch to another.

alex-shamshurin commented 7 years ago

I agree, but I wrote

if some option was specified

So if this special option is set, the 'home' directory must be treated special way and last edited session must be loaded. if last session was home directory itself then home session must be loaded. So this change it does not break anything and make this plugin very convenient.

PS. I tried ConEmu for windows and iTerm for my mac and I had to change colours of terminal in order to apply vim colour scheme. And terminal cannot highlight wrong tags with ~~~. Also it cannot use GPU rendering.

alex-shamshurin commented 7 years ago

So any update with this?

alex-shamshurin commented 7 years ago

+1

dhruvasagar commented 7 years ago

Will publish here when completed, on priority this week.

alex-shamshurin commented 7 years ago

Ok, I hope you make release soon and it will work under windows too.

alex-shamshurin commented 7 years ago

Any progress?

dhruvasagar commented 7 years ago

Hi, I have pushed changes in favor of this feature. Now I have added a g:prosession_last_session_dir setting that defines which directory to be treated as special and then load the last open session instead of the one for that directory. Should work as discussed, kindly play around with it and let me know if you face any issues.

alex-shamshurin commented 7 years ago

Great!!! I' check it out.

alex-shamshurin commented 7 years ago

session instead of the one for that directory

I'm sure this must be only for home directory! if I open vim from ANY other folder it should open the project from that directory, even if this options is set. Special treatment only for HOME directory.

dhruvasagar commented 7 years ago

Kindly read the description above. As per the directory which you set the configuration option g:prosession_last_session_dir (You'd want to set it to your home), when you launch vim from that directory prosession will attempt to load the last open session and not the session for that directory.

alex-shamshurin commented 7 years ago

Ok, please give an example how to do it. On unix it's '~'. On windows I do not know. How to specify for all systems a home dir here? Please add this to docs also.

dhruvasagar commented 7 years ago

It would be best if you specify the value of the setting based on the platform. It should be the complete path.

dhruvasagar commented 7 years ago

I have now updated it to compare using :h expand() function, so the value can be ~ or $HOME etc. There may be an appropriate notation for windows too. Or you can use the full path without short hand notations.

alex-shamshurin commented 7 years ago

I have four computers, 5 accounts, three different OSes. But I'd like to have only one VIM config. That's why I emphasised that home dir (root of home dir) must be a special case.

For now I just use let g:prosession_default_session=getcwd() but I think it must be inside a plugin.

dhruvasagar commented 7 years ago

No, all you need to do is something like this :

let g:prosession_last_session_dir = '~'

I cross checked with vim in windows and it gets expanded correctly to the user home directory there as well, and so will on linux / osx.

dhruvasagar commented 7 years ago

For your reference however, there may be times where you need different settings for windows / linux, for that you can just do something like this :

if has('win32') || has('win64')
  let g:is_win = 1
else
  let g:is_win = 0
endif
alex-shamshurin commented 7 years ago

Yes, it helped. Thank you very much for your time.

dhruvasagar commented 7 years ago

You're welcome