When I am working in vim, I often have a split, or splits, open containing a help files.
If I close other windows using :q
such that vim would be left in a state with only help windows open, vim closes the entire editor, which causes me to lose my position in the help pages. e.g. Say I have this layout
tab1 (this is the only tab open)
+------------------+-------------+-----------------+
| | | |
| |:h usr_26.txt| |
| A normal file, | | :h change.txt|
| containing code |section 26.2 | |
| e.g. |line 47 | line 272 |
| | | |
| app_db.sql | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
+------------------+-------------+-----------------+
If I were to enter the window containing app_db.sql
an issue the :q
command, surprisingly the entire editor would be lost.
It often takes me a long time - up to 15-20mins - of searching the help to finally discover that help content, so even though it's not exactly lost work, it's definitely a lot of time lost when this happens.
How can I prevent vim closing the editor itself when I close a window with only help windows open?
Possible solutions I've considered
- Simply don't close the last window when there are help windows open.
- the problem with this is I am not paying attention to what's in other windows when I close the current window.
- Use
mksession
- this requires that you know ahead of time that you need to
:mksession
and the editor closing always occurs unexpectedly.
- this requires that you know ahead of time that you need to
- Use a plugin like vim obsession which constantly update a
Session.vim
file.- I've currently paused using vim-obsession because of (ironically), the
Session.vim
files vim obsession makes often don't restore tabs containing help pages, but theSession.vim
files generated by:mksession
do restore the tabs with help windows. (Also another issue with tab labels getting mis-matched with the tabs themselves)
- I've currently paused using vim-obsession because of (ironically), the
QuitPre
event which would give the focus back to the previous window before closing the current one:autocmd QuitPre * wincmd p
~/.vimrc
and keep an eye on any weird side-effectswincmd p
is not working because p is null maybe. I will have to test a bit later when i get timeobsession
will save help windows if you addhelp
tosessionoptions
some time before saving the session:set sessionoptions+=help
.