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.

6
  • 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
    Commented Oct 5, 2017 at 14:18
  • What exactly gets typed? What does imap <Esc> print?
    – Mass
    Commented Oct 5, 2017 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
    Commented Oct 5, 2017 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 <esc> does (see @Tumbler41's comment).
    – Mass
    Commented Oct 5, 2017 at 15:24
  • 1
    @ZackFrost You may have a look here to try and debug your vimrc first.
    – Tumbler41
    Commented Oct 5, 2017 at 15:26

2 Answers 2

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!

1
  • :checkhealth warns about this in 0.2.1 Commented Oct 23, 2017 at 11:17
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.

3
  • It still does not work
    – Zack Frost
    Commented Oct 5, 2017 at 15:35
  • Interestingly, I found the solution on my own just now!
    – Zack Frost
    Commented Oct 5, 2017 at 15:38
  • 1
    This feels more like a comment than an answer. It sidesteps the issue rather than explaining what it is.
    – Rich
    Commented Oct 5, 2017 at 15:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.