2

This behaviour seems a bit strange (^ is the cursor):

inoreabbrev @@t <esc>0

what@@t
what
 ^

But:

inoreabbrev @@t <esc>0h

what@@t
what
^

Why using 0 is not enough to put the cursor at the beginning of the line after abbreviation?

1
  • 1
    You typing space count, try c-]. – dedowsdi Apr 21 '20 at 0:57
1

Why using 0 is not enough to put the cursor at the beginning of the line after abbreviation?

When you press space, Vim expands @@t into <esc>0, then the space command is executed. In insert mode, the space command inserts a space, but in normal mode it moves the cursor 1 character forward (see :h <space>).

To prevent the space from interfering, you can consume it with getchar():

inorea <silent> @@t <esc>0@=<sid>eat_space()<cr>
fu s:eat_space() abort
    let c = nr2char(getchar(0))
    return c =~# '\s' ? '' : c
endfu

See :helpgrep Eatchar.

1
  • 1
    or use CTRL-] in insert mode (see, :h i_CTRL-]) – Christian Brabandt Apr 21 '20 at 9:50

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.