I want to map <CR> to call multiple functions e.g. Func1() Func2() Func3()
imap <expr> <CR> Func1() Func2() Func3()
But I got "E15:Invalid expression"
How can I do it correctly?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
imap <CR> <C-O>:call Func1() \| call Func2() \| call Func3()<CR>
<expr> argument for mappings is if you want the mapping to execute the return value of the expression, which doesn't make sense in the case where you want to call multiple functions. So instead you want to temporarily leave insert mode (
<C-O>), enter :-command mode, and then execute three functions in a row. The
| command separators have to be escaped so Vim doesn't try to execute them when defining the mapping.