5

When I do <c-o><c-o><c-o>, and keep the control key pressed, it will jump 3 times backwards in the jumplist but if I do noremap <leader>o <c-o> then <leader>o<leader>o<leader>o, and keep the leader key pressed as I did with control, it will move backward the first time then it enter in editing mode and add an o. Leader key is ignored if we keep it pressed.

Is there a solution?

Dougui
  • 7,142
  • 7
  • 52
  • 87
  • i suspect it has something to do with the fact that leader key is not considered a modifier key by the keyboard hardware/driver. If so, it might be impossible to work around. Would you try mapping leader key to ctrl and see if it works? – pqnet Dec 05 '17 at 14:02
  • @pqnet I can see [here](https://stackoverflow.com/questions/26837425/vim-how-to-use-the-control-key-as-my-local-leader) we cannot use modifiers as leader – Dougui Dec 05 '17 at 14:08
  • 3
    The problem is that is a single key to vim. thats what a modifier does. open your vim got to insert, press `` and then `` then you see what your vim sees. it is one character (probably `^O`) which is sent to vim once you press the `o`. Modifierkeys just enter a waiting state, as long as `ctrl` is pressed, `^O` will be sent insted `o` if you press `o` – Doktor OSwaldo Dec 05 '17 at 14:13
  • @DoktorOSwaldo It makes a lot of sense. So there is not solutions for that, right? – Dougui Dec 05 '17 at 14:14
  • @Dougui no, none that I am aware of at least. And even worse, the next combination which would be great for your usecase `ctrl+shift+o` does not work either. vim recieves the same keycode as for `ctrl+o` (maybe possible with that https://stackoverflow.com/questions/1506764/how-to-map-ctrla-and-ctrlshifta-differently). As ingo says below, easiest thing is to map it to another modifier combo – Doktor OSwaldo Dec 05 '17 at 15:06

1 Answers1

12

Modifier keys like Ctrl, Alt and Shift can be kept in pressed state while you type additional keys; all keys will receive the modifier(s). That's a feature of keyboard input, nothing special about Vim.

For the Leader key, you cannot assign a modifier. It has to be a "real" key (possibly with modifiers). As the Leader key just starts a mapping sequence, you cannot keep it pressed. The closest you can achieve is a repeated mapping of it:

:nnoremap <Leader><Leader> :echo "pressed twice"<CR>

If you want to define a mapping that can be repeated with a single key press, you have to use a single key with (e.g. <C-g>, or <A-g>) or without (not much left there in Vim, maybe ,).

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324