1

We know that the command w, e, b handle the movement about word. But I think the w is stable, since whenever you type w, the cursor always jump to the next word. But e and b not that stable, if the cursor in the middle of the word, you need to press twice key to jump to the different word, if you at the end the word, or beginning of the word, just press once.

Here is my question, is there any way to make the e and b stable, even if you are in the beginning of the word, or end of the word, you need to press twice key to jump to the different word.

I make a keymap like this:

nnoremap e he
nnoremap b lb

I don't know if it is a proper way, any better choice?

2
  • 1
    The keymaps seem alright. But why do you need that? If you're already at the end (for key e) or the beginning (for key b) of the word, why would you want a keypress to keep you there? Just don't press any key then.
    – 3N4N
    Oct 29, 2022 at 5:29
  • @3N4N may be you are right. I may think too complicated about it
    – lizhe
    Oct 29, 2022 at 8:37

1 Answer 1

3

The semantics of wWbBeEgegE are not as clearly cut as one would hope. The way they work mostly matches the way they are described in the documentation when the cursor is on the first character of a word/WORD but it deviates quickly if that condition is not met or when used in combination with operators (think cw).

I have had mixed feelings about that situation for years, adding mappings one day only to remove them the next day… and adding them back a couple of months later. I eventually settled on leaving the default behavior as-is and stop worrying about inconsistencies.

If you still want to enforce consistency over portability, I recommend using visual mode to preposition the cursor. It seems less brittle than just using h or l:

nnoremap b viwo<C-c>b
nnoremap B viWo<C-c>B

Note that normal mode mappings won't be enough as those motions can also be used in visual mode (vb) and operator-pending mode (yB). It would be a shame to chase consistency in one mode only.

xnoremap b <C-c>m'viwob<C-c>v``
xnoremap B <C-c>m'viWoB<C-c>v``
onoremap b :<C-u>normal vb<CR>
onoremap B :<C-u>normal vB<CR>

eEgegE are a little bit more complicated. On one hand, eE are relatively clearly meant to move the cursor within a word, on the other hand gegE can only move the cursor to another word despite the wording of their doc being pretty much copy-pasted from eE. In my opinion, gegE don't deserve custom mappings because their behavior is the least ambiguous of the lot, but their documentation should be improved. That leaves eE, which you can decide to leave as-is or map like bB above.

Assuming you also decide to map eE, you may notice that you can't move the cursor to the beginning or end of the current word/WORD anymore, something that was precisely allowed by the "instability" of bBeE. That's fine if you never need that feature, I guess, but that whole approach—modifying default behaviors and removing functionalities—is not one I would recommend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.