2

When I use imap or inoremap to create any shortcut in Neovim 0.2.0, the shortcuts seem to act as if they are not there! Here is an example that I just tried.

nnoremap <F2> :w!<CR>
vnoremap <F2> <Esc>:w!<CR>gv
inoremap <F2> <Esc>:w!<CR>gi

The insert mode mapping just types in the key combination when I enter it in insert mode. However, the normal and visual mode mappings work just fine. I have tried other combinations such as zz C-s and others.

Any ideas?

P.S. I have stty -ixon in my shell rc file.

Zack Frost
  • 41
  • 4
  • 1
    Can't reproduce on Vim 8.0.586 on Windows. Try starting with vim -u NONE (or whatever Neovim's version of that is) and see if the problem persists. – Tumbler41 Oct 05 '17 at 14:18
  • What exactly gets typed? What does imap <Esc> print? – Mass Oct 05 '17 at 14:19
  • @Mass Well, binding escape exits insert mode like normal. In other cases, <C-s> prints out ^S as it would with no binding. – Zack Frost Oct 05 '17 at 15:13
  • I'm not sure what <c-s> has to do with this? Basically, the answer is it should work and you must have something in your configs that is, for example, changing what does (see @Tumbler41's comment). – Mass Oct 05 '17 at 15:24
  • 1
    @ZackFrost You may have a look here to try and debug your vimrc first. – Tumbler41 Oct 05 '17 at 15:26
  • @Mass, I was trying to demonstrate what gets typed. – Zack Frost Oct 05 '17 at 15:44

2 Answers2

2

So as it turns out, the problem was that I had

set paste

In my init.vim file. Removing that line solved it, and now insert mode key bindings work fine!

Zack Frost
  • 41
  • 4
1

Instead of the <esc>...gi pattern, it is generally better to use <c-o> to temporarily leave insert mode to use a command:

inoremap <F2> <c-\><c-o>:w!<cr>

<c-\><c-o> is like <c-o> except does not move the cursor backwards when at the end of the line.

Mass
  • 14,080
  • 1
  • 22
  • 47