dhruvasagar / vim-prosession

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

[Question] Saving and restoring vim sessions #104

Closed jdholtz closed 1 year ago

jdholtz commented 1 year ago

Hello. First of all, this is a very helpful plugin. I have three questions about using vim-prosession that I could not find in the documentation.

  1. Is it possible to automatically start tracking a session that has never had :Prossession invoked before? For example, when I create a new project, for Prosession to start tracking my sessions, I need to first invoke :Prosession. Then it will take care of automatically saving and restoring my sessions for eternity. My g:prosession_on_startup value is 1.
  2. How can I have vim-prosession track my current session if I open a file in my project directory. For example, if I explicitly state a file when opening vim in a project directory, I want to update the project's session to start tracking the one I currently have open.
  3. Going off of the last one, is it possible to start tracking a project's session if I open a file from a higher directory than the project? Ex: My CWD is ~ and I do vim ~/project/file.txt, I would want vim to start tracking my project directory session as the one I am currently in (Right now, it tracks my home directory session). I understand if this is not wanted or possible and there is an easy workaround for this (moving to the project directory), so I'm not too worried about this.

Sorry for all the questions. Thanks!

dhruvasagar commented 1 year ago

Hey,

  1. Prosession utilizes the dependency vim-obsession to do the underlying session tracking. By default, project is essentially a synonym for a folder, when vim is launched from a project without any arguments it tries to load a session for it if one exists already, if not starts a session while saving the session file in a centralized location configured by g:prosession_dir.
  2. If you manually open a specific file, vim-prossion intentionally assumes you do not want to load / start a session. If you want to still start / load session for the same you need to invoke :Prosession manually for the same. It will follow the same logic as on starting vim without any arguments, i.e. load an existing session if found, or start a new one.
  3. There are a few ways you can get the desired behavior
    • You can leverage prosession_ignore_dirs to prevent prosession to create a session for a specific directory, such as ~
    • You can rely on special last session created by vim-prosession by setting prosession_last_session_dir
    • You can manually trigger :Prosession with path to the project to load / start a session for that path.
jdholtz commented 1 year ago

Thanks! I will probably utilize autocmd to run :Prosession on startup to hopefully have less manual intervention. I appreciate you spending your time making this.