oskarkv
oskarkv

Reputation: 2369

omap a letter differently depending on what is already typed

I have a custom keyboard layout. And so I have the vim commands h, j, k and l bound to other letters, e.g. I have bound j to e, like so: nmap e j.

The problem with this is that in operator pending mode, I sometimes want e to mean j, and sometimes I want it to mean e. For example when I am pressing de I want it to mean dj, but when pressing te I want it to mean te.

Is there a way to solve this problem?

I could do omap de dj but that does not work if I want to delete more lines by typing d3e. If there was (I don't think so, or is there?) some way to match numbers, for example with #, then I could to something like omap d#e d#j. Or maybe there is some way to change the mappings depending on what I have already typed in operator pending mode.

Upvotes: 2

Views: 327

Answers (1)

ZyX
ZyX

Reputation: 53614

  1. You should hardly consider doing this with *noremap, not *map.
  2. nnoremap e j can’t possibly spoil te. Neither can onoremap e j: t is not an operator and it does not invoke operator-pending mode.
  3. omap de dj has nothing to do with de pressed in normal mode, you should press dde to invoke this mapping. And nnoremap e j has nothing to do with changing meaning of de: you need onoremap e j here (operator-pending mode is invoked by the operator d, but operator must be typed in normal mode. Neither it is a part of invoked mode).
  4. Remapping of basic movement keys is the perfect example of those rare cases when you need noremap, without leading n, o, v or something. Try doing

    noremap e j
    

    for all keys you want to remap, this should be sufficient.

  5. Remapping does not happen at the start of the mode, so no need to do onoremap 3e 3j. onoremap e j will also enable doing d3e->d3j. And noremap e j is equivalent to

    nnoremap e j
    onoremap e j
    vnoremap e j
    

Upvotes: 4

Related Questions