0

We can get help on Vim functions by typing the following from within Vim.

:help somecommand

For example, the following sends us to the help text for the unmap functionality.:

:help unmap

Is there any way to get Vim help directly in the terminal? If I could put that functionality into a function, called say, vimhelp, I could then run from the terminal:

vimhelp unmap

And I could then open that text in Vim, like a normal file. Then I can use all the functionality I have come up with for all file working.

The question is now answered but for documentation purposes I would like to provide here the current state of the solution.

emanvim(){
    if [ -z "${1}" ]; then
        printf "Please provide Vim help topic.\n";
        return;
        fi  

    vim -i NONE -c "set bt=help|help $1" -- /tmp/dummy;
    };

2 Answers 2

2

This is more likely a Shell-scripting question. You could define the following function in your .bashrc:

vimhelp() {
    if [ -n "$1" ]; then
      vim -i NONE -c "set bt=help|help $1" -c 'nnoremap q :q!<cr>'
    else
      echo "please give help-topic to jump to"
    fi
  }

after resourcing your .bashrc file, you can use the command vimhelp unmap to directly jump to that in your vim editor.

10
  • I there any way to get rid of that error message in the beginning? It's like its expecting a filename.
    – john-jones
    Commented Dec 1, 2022 at 14:42
  • 1
    Instead of help xxx | only you can do set bt=help | help xxx. Then the buffer #1 will be re-used ;-)
    – Matt
    Commented Dec 1, 2022 at 14:45
  • I don't get it. There is no help xxx | only. I tried the following, but same error.
    – john-jones
    Commented Dec 1, 2022 at 15:03
  • vim -c "set bt=help | help $1" -c 'nnoremap q :q!<cr>'
    – john-jones
    Commented Dec 1, 2022 at 15:03
  • @joh-jones what error? Commented Dec 1, 2022 at 15:25
2

My very similar function is

vh() {
  vim +"help $*" +only
}

Based on some comments, I'll also mention that I have nnoremap <buffer> q :quit in ~/.vim/after/ftplugin/help.vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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