3

I use a comma as my leader key. I would like to be able to press the comma twice rapidly (i.e., <leader>,) to achieve the native functionality of the comma (i.e., jump back after f/F and ;).

To that end, my .vimrc begins

let mapleader=","
map <leader>, ,

But when I press ,, it does nothing. What should I change to make it work?

1 Answer 1

4

It works for me, but there is a 1 second delay before the cursor moves to the left. This is because when ,, is pressed, vim translates it to ,, which further translates to the <leader> key. So, vim is waiting for additional input as there may be additional keystrokes after <leader>. This explains the 1 second delay.

The remedy is to use noremap instead of map. This tells vim to use a non-recursive mapping. So, if we use

let mapleader=","
noremap <leader>, ,

,, is translated to ,, and is not further translated to the <leader>. The cursor moves immediately to the left, as intended.

11
  • 2
    To add a few details to this answer: husB analyzed correctly the issue with the comma being interpreted as a leader and creating a delay, once possible solution would also be to tweak :h 'ttimeoutlen' (but that would impact all mappings). Using a non recursive mapping is the right solution, actually by default you should always be using non recusive mapping unless you have a very specific need and you know what you are doing. And furthermore it would be better to use mode specific mappings like nnoremap and xnoremap.
    – statox
    Mar 1, 2022 at 14:39
  • Thank you. I just tested it with those two lines, and I found that you're right, it works. The trouble is that it doesn't work with my big, bloated .vimrc. So I will do some digging to see if I can find what is interfering. Mar 2, 2022 at 4:49
  • @husB, a follow-up question for you or anyone else who knows: Do you have any suggestions for how to find what the problem is in my .vimrc that is preventing your answer from working with my setup? Are there any particular types of settings that might be expected to mess with <leader>,, or is there a way to list such mappings and find what <leader>, is mapped to? Sep 27, 2022 at 18:31
  • 1
    @AlexRoberts that should work, but there may be other mappings that take priority over your mapping... a more specific command would be :verbose filter /,/ map, which filters out mappings that contain ,.
    – husB
    Sep 28, 2022 at 3:34
  • 1
    Regarding your first question, you could do a bisection search (as taken from here)-- commenting out half your vimrc and see if the problem persists. Then you would know which if the issue is in the former or latter half. Further comment out half of that (a quarter), ...until the problem is isolated :)
    – husB
    Sep 28, 2022 at 3:37

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.