Vim key remaping doesn't work in chaining commands

255 Views Asked by At

I have following vimrc file

map u <Up>
map n <Left>
map e <Down>
map i <Right>
noremap h i
noremap t w
noremap s b

Delete or changing word with dt or ct works, but when I want to delete inner word with dht or cht it doesn't work but dhw or chw works. Am I missing something in this remaping of the keys?

I have tried with map instead noreamp but it didn't worked.

1

There are 1 best solutions below

0
Chris Heithoff On

Vim's operator-pending mode is likely not expecting two consecutive mappings of individual characters. However you can do a multi-character mapping.

noremap ht iw
noremap at aw

This will let you do dht, dat, cht, and cat, as well as vht and vat.

For multi-character maps, please be aware of the 'timeoutlen' option setting. This is normally defaulted to 1000ms. If you have a mapping for both h and for ht, then this will slow down your h mapping because Vim must wait up to 1000ms for you to possibly type t. You can reduce 'timeoutlen' to a shorter time but it must still be long enough to let you type both h and t.

The noremap command applies to Normal, Visual and Operator-Pending modes.
You probably want to specify only Operator-Pending and Visual modes and exclude Normal mode so that you don't slow down your other Normal mode mappings.

onoremap ht iw
onoremap at aw
vnoremap ht iw
vnoremap at aw