0

I have the following in my init.vim (neovim):

nnoremap i k
nnoremap j h
nnoremap k j
xnoremap i k
xnoremap j h
xnoremap k j
nnoremap h i
nnoremap H I

I find this arrow key-like configuration much more comfortable, and aside from a few edge cases where plugins define special windows and don't expose movement remapping, it didn't seem to break anything...

...until I tried to use viw, i.e. select inner word from normal mode. What happens now is that after pressing vi, vim either waits timeoutlen for a key sequence and then moves the cursor up a line, or cancels the sequence if w is pressed and executes the normal w action, i.e. move to the beginning of the next word. Pressing i again while in visual mode starts another sequence countdown, so upward movement is also a bit jerky.

I'm pretty sure I understand why the sequence countdown happens, namely that i is ambiguous between "move up a line" and "start of a text object," but I don't understand why w cancels the text object sequence instead of completing it. Note that this is true for all text objects, e.g. s or (. Is this expected behavior?

Ideally, I would like behavior like the following:

  1. After entering visual mode, wait timeoutlen for a sequence to begin
  2. If a sequence is begun, wait indefinitely for it to be completed or canceled with an invalid key press
  3. If no sequence is begun or (2) completes, thereafter ignore sequences until visual mode is exited

Intuitively, this might not be scriptable, but any help would be appreciated. As a fallback, I would at least like for iw to work as expected in visual mode.


EDIT: @d-ben-knoble's answer doesn't quite get to the why of this, so I'm leaving the question unanswered in case anyone wants to take a whack at what exactly is going on.

That said, you'll all be proud I'm sure to know that there's officially an hjkl branch in my dot files repo now. It's actually not as bad as I remember. I think it was overwhelming when I was first learning vim and everything was new, so I used arrows for a while, then realized having to move my hand to transition in and out of insert mode sucked and ended up in the situation described above. I guess hjkl is the last step of the indoctrination process :)

4

First, terminology:

  • a chord is a key-combination like Ctrl-w—it is so-called because it is like the chords a pianist plays, with many keys pressed

iw is really more of a key sequence.

/end pendantry :)


Your visual-mode mappings are screwing with the usual iw sequence.

Once started with v, Visual mode does what you tell it to. In this case, you've sent it i—which could be the start of a text-object like i(, or it could be your mapping. You can also give regular motions (like w).

  • If it's your mapping, it does the k motion (up).
  • If it's a sequence, well, as best I can tell, it moves up (i -> k), then moves, e.g., to the next word.

I'm not sure how to achieve your desires, but a couple of things come to mind:

  1. It will be easier for you in the long run if you just get used to hjklless(1) (and therefore man(1)) and plenty of other programs use them. Even gmail. Trust me on this one. It's more complicated to screw with this then it's worth.
  2. If you insist, you could do something like override all the text objects (xnoremap iw iw or something), or
  3. You could have a look at langmap (for Normal mode translation) and keymap (for Insert mode translation). These are commonly used by folks with non-qwerty keyboards but who have grown used to the placement of qwerty keys in vim.
  • 2
    I think the most solid piece of advice in this answer is not to try to remap hjkl in this way. @thisisrandy vim is meant to be customized that's true, but that means building on the features it offers you to make them more efficient for your workflow. Here you are fighting against Vim and you have very few chances to win. If you really want to keep using the arrow keys pattern to navigate, then you'd be better off using the actual arrow keys rather than trying to bend vim this way. – statox Nov 5 at 9:04
  • 1
    @d-ben-knoble your response is much appreciated. You're right of course about "chord." I think I vaguely knew that and just slipped. I think you may have misunderstood slightly about ). I meant to say that this behavior (moving up and then performing the motion instead of executing the text object) is true for all text objects that I'm aware of, ) included. In any event, langmap and keymap sound promising, but I guess at the end of the day, if I spend more time on this than it would take to retrain my brain, maybe it just isn't worth it. – thisisrandy Nov 5 at 17:44
  • @statox honestly I tried, but the arrow key muscle memory is very strong. Still, I get what you're saying about fighting vim rather than working with it. I was just trying to find a way to stay on the home row and work with my muscle memory at the same time. – thisisrandy Nov 5 at 17:44
  • @thisisrandy I think that the benefit of staying on the home row is largely overrated (I'm not saying it doesn't exist tho) and breaking stuff as important as common text objects just for the sake of staying on the home row is not worth it in my opinion. If you're not ready to change your muscle memory, it's fine: use the arrow keys and the text objects and you'll be alright. And if one day it becomes a blocker for you, then you'll learn how to use hjkl properly and integrate it to your muscle memory ;) – statox Nov 6 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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