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
  • 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? – Mahbub Alam Feb 18 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 at 8:22
  • Yeah, sorry about that. – Mahbub Alam Feb 19 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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