54

I just used the help files in vim and now I am stuck in help.

:q Exits the entire program and I am getting tired of having to close and reopen vim every time I use help. I would prefer a command that can close help and return me to the program I am writing.

I have trouble searching google.com because the search string exit help in vim obviously returns articles about exiting vim itself, something I have became very good at.

Does anyone know how to do this?

EDIT: I must have been somehow getting stuck in the split screen thing. That's why I was unable to get out of the help via :q

2

8 Answers 8

49

:q is already the solution.

It closes not the whole vim session, but only the active window (split section within vim). If this is window is the help, only the help will be closed. If your document is active, the document will be closed.

If this is the last non-help window, the help will close as well -- which means vim is closed.

Use Ctrl+W followed by a cursor key to make sure your cursor is in the help window. Then try :q again.

21

Recent Vims have the :helpclose command (this needs a Vim 7.4.449)

1
  • This is elegant, clear cut and avoid mistakes.
    – Json
    Jul 4, 2023 at 7:55
15

:q is a little bit annoying since this is a readonly buffer. And I believe people rarely need to record a macro in help buffer.

So I'd like to map q to :q:

autocmd FileType help noremap <buffer> q :q<cr>
1
  • 1
    This is what I came in for, thank you!
    – Gal
    Nov 29, 2020 at 15:31
3

I use Ctrl+W+C or Ctrl+W+Q, although I agree that like many other more modern read only windows, it would be more natural if we could quit it with just pressing q.

2

You must have somehow arrived at a sole help window. Usually, :help splits a window, and a :q in that window will just close the help, and return to the other window.

Or, you've typed the :q while in the other window, not the help. Vim doesn't "count" help windows as full windows, and will quit completely when only help windows would be left.

There are quite some window management commands; for example, :close is a variant of :quit that won't exit Vim. Though initially confusing, learn how to use them, as they are very powerful. :help windows has all the information.

2

:bd will unload the current buffer (exit help) and return you to the last used buffer.

The command will not exit vim.

For example, the commands:

:help :bd
:only
:bd

will not exit vim despite the session having only 1 window.

1
  • Yes, it works! It works also with help window opened in a new tab: :tab help foo. But it does not look logical because help is absent in the list returned by :buffers command...
    – nickkzl
    Sep 22, 2020 at 20:28
1

I combined previous answers to get:

autocmd FileType help noremap <buffer> q :bd<CR>

or in lua:

vim.api.nvim_create_autocmd(
    "FileType", {
        pattern = {"help"},
        command = "noremap <buffer> q :bd<CR>",
    }
)

Works great for me!

0

I know this is late, but there is a shortcut for :q which is ZQ. ZQ is quit without saving. In the same way if you want to quit with save, then use ZZ(this is similar to :wq).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .