Here, I'm using a mapping from this post. Edited it to my liking like so:

nnoremap <F3> :execute 'help' expand('<cWORD>')<CR>

that works. Problem is, i wanted to add | only so that the help window become the only visible opened window. I tried this in Ex mode:

:execute "h "expand("<cWORD>")"| only"

This works as intended.

Now when i try to do it in a mapping:

nnoremap <F3> :execute "h "expand("<cWORD>")"| only"<CR>

Doesn't seem to work.

I think it might be due to the position of the quotes, but after some experiments, i couldn't fix it myself.

How come the mapping doesn't work, when the Ex command does?

1 Answer 1


:help sees | as its argument, so I suggest to write a simple function.

function! s:search_help(str)
  exec 'help '.a:str
nnoremap <F3> :call <SID>search_help(expand('<cword>'))<CR>

As pointed in comment, when using :map command | should be <bar> (:h key-notation), so there is an one-line solution:

nnoremap <F3> :exec 'h '.expand('<cword>').' <bar> only'<CR>
  • didn't know :O. Thanks! Commented Nov 5, 2020 at 16:45
  • 5
    You can write only instead of execute 'only'; this is true for all ex-commands (you only need execute when doing string interpolation into the command, and to protect certain things like | from being arguments to commands)
    – D. Ben Knoble
    Commented Nov 5, 2020 at 16:58
  • 5
    Note also that | in mappings should be <bar>, a common point of confusion
    – D. Ben Knoble
    Commented Nov 5, 2020 at 16:59

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.