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
:mksessionand 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.vimfile.- I've currently paused using vim-obsession because of (ironically), the
Session.vimfiles vim obsession makes often don't restore tabs containing help pages, but theSession.vimfiles generated by:mksessiondo 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
QuitPreevent which would give the focus back to the previous window before closing the current one:autocmd QuitPre * wincmd p– user9433424 Jul 06 '16 at 23:46~/.vimrcand keep an eye on any weird side-effects – the_velour_fog Jul 06 '16 at 23:49wincmd pis not working because p is null maybe. I will have to test a bit later when i get time – the_velour_fog Jul 07 '16 at 00:02obsessionwill save help windows if you addhelptosessionoptionssome time before saving the session:set sessionoptions+=help. – Sato Katsura Jul 07 '16 at 06:22taboodoesn't touchsessionoptions. – Sato Katsura Jul 07 '16 at 06:35set sessionooptions+=globals,tabpagesthey suggest this snippet on the taboo github readme this is a bad snippet because it doesnt check whatsessionoptionsvalue it before it changes it. also tim pope has been making changes to sessionoptions in obsession – the_velour_fog Jul 07 '16 at 06:41taboousessessionoptions. It doesn't change it. Have you actually tried my suggestion above before arguing about it? – Sato Katsura Jul 07 '16 at 06:44helpis already in mysessionoptionswith or without:Obsession. also there are more problems than just missing tabpages with help windows. there are tab labels that are attached to the wrong tabs. I need to spend some time testing – the_velour_fog Jul 07 '16 at 06:48