I want to map <CR> to call multiple functions e.g. Func1() Func2() Func3()

I tried:

imap <expr> <CR> Func1() Func2() Func3()

But I got "E15:Invalid expression"

How can I do it correctly?

1 Answer 1


Try this:

imap <CR> <C-O>:call Func1() \| call Func2() \| call Func3()<CR>

The <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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.