2

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.

3

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. – Mahbub Alam Dec 13 '18 at 10:15
  • 1
    @MahbubAlam You want to read the doc for operator pending mode :h omap-info – statox Dec 13 '18 at 10:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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