Leader key is ignored if I keep it pressed and I do multiple combinations
Asked Answered
P

2

6

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?

Palmirapalmistry answered 5/12, 2017 at 13:54 Comment(5)
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?Servetnick
@Servetnick I can see here we cannot use modifiers as leaderPalmirapalmistry
The problem is that <c-o> is a single key to vim. thats what a modifier does. open your vim got to insert, press <c-v> and then <c-o> 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 oGauthier
@DoktorOSwaldo It makes a lot of sense. So there is not solutions for that, right?Palmirapalmistry
@Palmirapalmistry 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 #1507264). As ingo says below, easiest thing is to map it to another modifier comboGauthier
R
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 ,).

Raeannraeburn answered 5/12, 2017 at 14:43 Comment(0)
S
0

You can use a recursive mapping and append the <leader> key to the mapping.

Here is an excerpt from my .vimrc for instance:

nnoremap <leader> <nop>
nmap <leader>j :tabprev<cr><leader>
nmap <leader>k :tabnext<cr><leader>

If you don't map the sole leader key (as in the first line), a bell will ring whenever you enter the keys with recursive mappings.

Spiro answered 12/4 at 2:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.