bootleg
bootleg

Reputation: 187

Vim: swapping 2 characters in operation-pending mode

Using an exotic keyboard layout, I have to remap g (among others) which is, on my layout, in the h position on a classic qwerty layout. To do so I decided to swap g with h with the following commands:

noremap g h
noremap h g

This doesn't work. For instance typing hh is viewed as gh and not gg. Also when hitting g it shows g (with showcmd enabled) and not h and it doesn't seem to take the remapping into account, it act like the g command. But when hitting g again or waiting 1 second it actually moves left.

I tried the following to make it work in operation-pending mode

onoremap g h
onoremap h g

but it doesn't change anything.

So why does it behaves that way? And how to fix it?

Upvotes: 4

Views: 183

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172698

The trouble with multi-key commands like gg (or the various <C-w> commands from which I remember a similar issue) is that they are not the g command followed by a g operator. (Especially with the g prefix, there's a whole range of unrelated commands not found in the original vi in that space.)

I'm afraid you'll have to define separate remappings for all of them:

:nnoremap hh gg
...

Upvotes: 3

Related Questions