I am new to VIM and have been looking for a feature/plugin like guake for terminals wherein I could open the help functionality in a dropdown box without typing :q to close the vim help menu.

If there is a better way than to close and open new windows for help text I would love to hear those options as well.

  • You should be more precise about what you want: From what I read on their site guake is just a terminal that you can open with a defined keypress I don't really see how it relates to help windows. And if you don't want to use :q to close the help window you can try pressing ctrl+w followed by c
    – statox
    Jul 31, 2017 at 14:10
  • @statox. guake is a terminal with a window that pops-open from the top of the screen when a given key is hit. Hitting the same key again closes the window. Hitting again reopens the previous windows in its previous state. It's not just alternating K and :q as there is a context to restore. Aug 28, 2017 at 8:56

2 Answers 2

  1. We need to know whether a help window is opened to close it.

    We could get the list of help buffers and filter the hidden-readonly-nonmodifiable ones with a 'help' filetype that are displayed in a window to know if a help buffer is already displayed. This is quite complex, but this could be done with an boolean expression, and thus used in a oneliner mapping.

    While the help window can be closed with :helpclose, it doesn't tell us whether it's open. Yet, we can use it to count the number of windows before and after :helpc. This is best done with functions.

  2. We need to be able to restore the help window to where it where. Either we listen for event, or we just play with CTRL-O. It may yield a blinking the first time. I guess this part will need improvements. It's meant to be used in a :help sometopic -> :helpc -> :help + CTRL-O scenario.

Putting all the pieces together.

" I reuse F1, but to toggle this time
nnoremap <silent> <f1> :call s:toggle_help()<cr>

" untested
function! s:toggle_help() abort
    let nb_win = winnr('$')
    if winnr('$') == nb_win " there was no help window opened
        " open the help window
        :top :help
        :exe "normal \<c-o>"
    " else... it's already closed

I am not familiar with guake and am not sure what you mean by "dropdown box". However, I will try to give you some tips on how to make using the built in help system a little more convenient.

A common use case I have is that I am looking at some vim script and wondering, what does this command/option do? Let's take this line from my vimrc:

set laststatus=2

I have configured Vim to open the help for the word under the cursor when pressing K in a .vim file. So what I would do is place the cursor on laststatus and press K. This opens a new window where I read what the options mean, and then press CTRL-w c to close the window, and I'm back where I was.

K is the "lookup help" command (:help K). It usually runs man, but can be configured to use :help or any other command or program instead. Put the following in .vim/after/ftplugin/vim.vim to enable Vim help with K.

setlocal keywordprg=:help

(:help 'keywordprg, :help after-directory, :help ftplugin)

Opening and closing help with K and CTRL-c is super-quick!

Here are some other useful related features:

  • Go to anything under the cursor while in help with CTRL-]. Go back with CTRL-t. (:help tag-commands)
  • Autocomplete Vim commands and functions in insert mode with CTRL-p. (:help ins-completion)

Does this answer your question? What specific feature are you missing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.