0

This is best explained with an example: Suppose I want to remap G to go to the end of the line, as I find that convenient. I also want to be able to jump to the end of the file, maybe by pressing gG. I might then try the following:

nmap gG G
nmap G g_

However, that'll not work. Since G was remapped to g_ later on, the action performed by gG will not be to go to the end of the file, but the end of the line.

So my question is: Is there a way to "fix" the mapping, so its actions are not affected by later remappings of the keys it uses?


Note: I know the problem above can be solved by other methods, such as using nmap <silent> gG :$<cr>. My question is not about solving that specific problem, but more about whether the idea proposed above is possible in vim.

4
  • 1
    :nnoremap gG G
    – B Layer
    Jun 4 at 16:48
  • @BLayer Hah, I thought :nnoremap only prevented recursion, thanks. Is this question too obvious and should be deleted? If so, feel free to suggest that, if not, feel free to leave your comment as an answer. Jun 4 at 16:57
  • 1
    It's almost certainly a duplicate. There are so many answers containing "nnoremap", though, that it could be hard to find a proper dupe match. I like the title of your question, though, since it's nice and general (and likely to be hit by searches) so I'm hoping we can find one ... deleting is not ideal.
    – B Layer
    Jun 4 at 16:59
  • 1
    Best one I've found so far: Remap keys conflicting with plugin It's not ideal that it mentions "plugin" in the title though, obviously. And the answer is pretty brief. {sigh} Hoping someone else just knows a good one.
    – B Layer
    Jun 4 at 17:09

Your Answer

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

Browse other questions tagged or ask your own question.