Search code examples
vimvim-plugin

How to imap <Space> in vim


I am writing a vim script which may need to map the key to trigger a function, but it looks like whatever I write in the imap command, the mapping is not worked.

For testing purpose , I set map the to like:

imap <Space> <Esc>

So I should escape from the insert mode when I press a space.But it seems not working... Is it possible to imap in vim? If not, I will find another way to work around.


Solution

  • It's so strange to answer my own question , but I found a solution after all. mapping-enter-key-in-vim In this question, the answer is

    inoremap <buffer> <Space> <esc>
    

    Another problem is that AutoPairs is overriding setting.... So my setting is not working.