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?
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
.
space
count, tryc-]
.