I have added the following the mappings to my vimrc. I want K to take me to the top line of the window and H to take me to the first non-empty character of the line.

nmap K H
nmap H ^
nmap J L
nmap L g_

This does not do what I want it to. Since K performs H and H is mapped to (under the above mapping) take me to the first non-empty character of the line, K takes me to the first non-empty character of the line.

How to achieve what I want to do? I could not think of anything.

1 Answer 1


Your question is the opposite problem of this one. You need to use the non recursive version of the map commands :h :nore:

nnoremap K H
nnoremap H ^
nnoremap J L
nnoremap L g_

And as a general rule always use the non recursive version unless you know what you're doing.

  • I see. A related question, if I wanted to combine this mappings with operators what should I do? Like if I wanted to do dH say.
    – mahbubweb
    Dec 13, 2018 at 10:15
  • 1
    @MahbubAlam You want to read the doc for operator pending mode :h omap-info
    – statox
    Dec 13, 2018 at 10:22
  • I tried the suggestions in :h omap-info, they didn't work. For instance I added omap H ^ and typed dH, it didn't perform d^; and similarly for other mappings. Whats going on here?
    – mahbubweb
    Feb 18, 2019 at 21:39
  • @MahbubAlam Your comment is another question, we try not to answer questions in comments because it is more difficult for future readers to find it. If you're still struggling with your operator pending mode mappings, please ask a new question :)
    – statox
    Feb 19, 2019 at 8:22
  • Yeah, sorry about that.
    – mahbubweb
    Feb 19, 2019 at 10:42

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.