I am trying to do the following mapping to open the correct help topic underneath my cursor:

nnoremap K viWlF=hK

This works for the first term:

  • belloff=all

But not for the second:

  • splitbelow

For the second, it just highlights the word correctly, but doesn't open the help section. If I manually press K on my keyboard, it will then open the help section but doesn't do so automatically. Why is this occurring, and how could I fix this? Note that if I manually type in viWlF=hK it works for both.

This allows me to open something more easily like:

  • 'viminfo'
  • c_CTRL-R

For whatever reason, putting it into a function worked:

function MyFunc() abort
    normal! viWlF=h
    normal! K
nnoremap K :call MyFunc()
  • 2
    Why do you want to remap 'K' at all? It's enough to move cursor on 'belloff' (not "all") and it just works.
    – Matt
    Jun 16, 2020 at 5:39
  • @Matt sure, but if you do the same on 'viminfo' it opens :h viminfo instead of h: 'viminfo', same with ctrl-r
    – David542
    Jun 16, 2020 at 18:04
  • By fixing one error you will most likely do another one. E.g. press "remapped" K on exists("g:syntax_on") and you won't get to :h g:syntax_on anymore. Just do it normal way and manually use Visual mode when it's really needed. Trying to be too smart rarely pays off.
    – Matt
    Jun 16, 2020 at 18:21
  • @Matt -- agreed, I ended up doing this which uses the default unless I manually put the help word between *'s (I'm surprised vim doesn't do that by default when pressing K, or is there an option for that too?) imgur.com/a/6KR1biO.
    – David542
    Jun 16, 2020 at 18:34

1 Answer 1


A mapping is interrupted if a command fails. For example, l would fail if your splitbelow is at the end of a line, and if it wasn't then the F= would fail if there was no = on that line.

This behavior is documented under :help map-error:

Note that when an error is encountered (that causes an error message or beep) the rest of the mapping is not executed. This is Vi-compatible.

  • I see. So in the above case, I should remove the abort from my function? I disabled all beeping, etc. so am not too sure when something actually 'fails' or just nothing happens.
    – David542
    Jun 16, 2020 at 1:51
  • @David542 This is about a mapping, not a function... The abort on the function is unrelated.
    – filbranden
    Jun 16, 2020 at 1:57
  • I see. Then for the above mapping (or function), what/how would you suggest doing it?
    – David542
    Jun 16, 2020 at 2:40
  • 2
    @David542 I actually suggest not using a map at all, just use viWK when you need it for something that includes non-keyword characters.
    – filbranden
    Jun 16, 2020 at 3:08
  • 1
    @David542 Failure of an Ex command (which would fail a function tagged with "abort") is different from failure of a Normal mode command (which is the one that interrupts a mapping.) Running a :normal! with a sequence including a Normal mode command that fails will not produce an Ex command failure of the :normal! command. Hopefully that's a little bit clearer...
    – filbranden
    Jun 19, 2020 at 1:10

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.