Mert Nuhoglu
Mert Nuhoglu

Reputation: 10133

Swap Normal Mode Mappings of two letters in Vim

I use Turkish-F keyboard layout where the key w is very far from home row. In order to prevent carpal tunnel in my right baby finger, I want to swap the normal mode mappings of e and w.

I can do it using the following mappings:

nnoremap w e
nnoremap e w

But this doesn't swap e and w when they are used in combination with other mappings such as diw or die.

How can I swap all mappings involving e with w and vice versa.

Upvotes: 0

Views: 93

Answers (1)

sudo bangbang
sudo bangbang

Reputation: 28179

After mapping

nnoremap w e
nnoremap e w

If you look at the output of :map, you can see

e         * w
w         * e

Motions like iw, aw will not respect this mapping as they are a different motion (text object) altogether.

One workaround is to add extra mappings like

onoremap ie iw
onoremap ae aw

Also note that operators like c, d, y takes you to operator-pending mode, hence onoremap

Upvotes: 2

Related Questions