2

I would like to be able to map actions to key bindings when in insert mode. However using the code here just inserts the text :action EditorCompleteStatement into the buffer.

inoremap <a-j> :action EditorCompleteStatement<CR>

Why is this not working and how can I change it to work?

user3139545
  • 6,882
  • 13
  • 44
  • 87

1 Answers1

7

This is working exactly how it should. inoremap says "whenever you type left hand side, pretend the user typed right hand side". So after that mapping, <a-j> is literally equivalent to typing ":action EditorCompleteStatement" in insert mode.

So really all you need to do is escape insert mode first:

inoremap <a-j> <esc>:action EditorCompleteStatement<cr>gi

Or, you could use <C-o>, which is a bit easier in this context:

inoremap <a-j> <C-o>:action EditorCompleteStatement<cr>
DJMcMayhem
  • 7,285
  • 4
  • 41
  • 61
  • For anyone interested, vim help for `i_CTRL-O` says: `execute one command, return to Insert mode` – Leon S. Jul 16 '19 at 15:49