0

I have the following mappings in my ~/.vimrc:

" Add new lines and spaces without changing the mode
nmap <leader>j mvo<Esc>`v
nmap <leader>k mvO<Esc>`v
nmap <leader>h i<space><esc>l
nmap <leader>l a<space><esc>h

All shortcuts work, but I can't get consistent behavior with leader+h/l commands.
For example, here is the word and cursor is at h:

Floccinaucinihilipilification

When we press leader+l, one space gets instantly added to the right and cursor stays at h:

Floccinaucinih ilipilification

Pressing u moves cursor one position to the right, which is unexpected.
Next, when we press leader+h, space gets added to the left with approximately 3 seconds delay:

Floccinaucini hilipilification

However, this time pressing u leaves cursor at h as expected.

NVIM v0.2.2
Any clues?

3

Actually the behavior you are observing is the expected one:

  • When you delete some text and undo the deletion, u brings you back to the beginning of the deleted text.
  • When you write some text and undo the addition, u bring you back to the end of the added text.

Both of your mapping <leader>h and <leader>l add a new character. When you undo what they did you will get to the end of the deleted text no matter what motions you used before the undo. I think what confused you is that you changed the position of your cursor with the final h and l motions in your mappings.

You can replace your mappings by the following to convince yourself that the behavior is the expected one:

nmap <leader>h i<space><esc>0
nmap <leader>l a<space><esc>0

So as far as I know your mappings are working properly and you can't do much to change the behavior of u.

  • Thanks for the explanation! Do you know what can be a reason for 3sec delay? – asv Dec 24 '17 at 4:07
  • 1
    @asv You will probably find an answer at :h 'ttimeout' and :h 'ttimeoutlen' – statox Dec 28 '17 at 14:37

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.