I recently wanted to have a mapping that I could trigger from
normal mode as well as from
insert mode. Writing the same mapping for multiple modes annoyed me as it cluttered my .vimrc and requires me to make the same changes multiple times.
It was pointed out to me, that no such mapping mode exists. See here: https://superuser.com/questions/1236999/vim-multiple-specific-mappings
It was also pointed out, that for very simple mappings I could use a function like this:
function! DoubleMap(x, y) exec "nmap ".x." ".y exec "imap ".x." ".y endfunction
I now tried the following:
I created a mapping that takes care of what ever I want to achieve, without using
map <COMPLEX-KEY> <ACTION>
Then I created mappings for the modes I wanted the mapping to work in:
inoremap <KEY> <Esc><COMPLEX-KEY><Esc>i nnoremap <KEY> <COMPLEX-KEY>
This should allow me to outsource complex mappings to another part of the .vimrc or another file altogether, as well as for easier changes and readability.
But this does not work. Is there a way to trigger a mapping from within a mapping?