I have created a Vim abbreviation for the start of a file path, i.e.
cab \x\ M:\xmlexport\Output\
and I want to have this expand, remove the space and wait for further input. I have tried using =Eatchar('s')
but don't know what to put before it to make it trigger correctly. All the examples I have seen use <C-R>
which adds in a new line. I have tried <left>
just to move back one space but this creates M:\xmlexport\Output \
Perhaps I have misunderstood the question, but I've tested the function you pointed out and seems to work:
I've added the Eatchar
function to .vimrc
:
func Eatchar(pat)
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunc
And inside vim
I've created your abbreviation, like:
:cab \x\ M:\xmlexport\Output\ <left><C-R>=Eatchar('\s')<CR>
Then I write :\x\
in command-line and it expands to :M:\xmlexport\Output\
, and the cursor position is just after the last backslash to write your desired input.