I’m following Mapping keys in Vim – Tutorial (Part 1) – 6.2 Insert mode maps, and there it says:
The <C-R>= command doesn't create a new undo point.
You can also call Vim functions using the <C-R>= command:
:inoremap <F2> <C-R>=MyVimFunc()<CR>
I’m trying to use this to call SingleCompile#Compile() like:
map! <F5> <C-R>=SingleCompile#Compile()<CR>
It’s working, but the problem is that when I get back to insert mode, a 0 character is inserted as a side-effect.
Why is this and how can I avoid it?
EDIT:
I’m using <C-R> because it doesn’t create a undo point and has the purpose of calling a function instead of entering a command like <C-O> does. I don’t want to create a undo point.
EDIT:
I’ve updated the VIM wiki based on the ternary operator trick provided by Ingo Karkat.
The implicit return value of a function is
0. You need to either modifySingleCompile#Compile()or write a wrapper that returns the empty string:An alternative clever trick is to evaluate the function inside the
?:ternary operator: