tpope / vim-obsession

obsession.vim: continuously updated session files
http://www.vim.org/scripts/script.php?script_id=4472
1.76k stars 70 forks source link

Stopping the Obsession #68

Closed Jasha10 closed 3 years ago

Jasha10 commented 3 years ago

Hi,

What's the recommended way to guarantee that Session.vim is gone and the plugin has stopped?

I've tried :Obsession!. The docs say:

:Obsession!             Stop obsession and delete the underlying session file.

and this would seem to be what I'm asking for. And if a Session.vim file exists, it is what I'm asking for. But if a Session.vim file does not exist, then invoking Obsession! creates a new Session.vim file and starts tracking state, giving the opposite result.

My use case is: I want to map the letter Q to delete Session.vim (if it exists) and then exit vim. I am planning another map (<Leader>E) to ensure Obsession is running before exiting.

Thanks in advance.

tpope commented 3 years ago

This is the conditional that decides whether to delete: https://github.com/tpope/vim-obsession/blob/96a3f837c112cb64e0a9857b69f6d6a71041155e/plugin/obsession.vim#L15-L17

So to always delete, your map will need to invert that third clause:

nmap <script> Q :<C-U>if filereadable(get(g:, 'this_obsession', v:this_session))|Obsession!|endif|qa<CR>