title: VIM: Calling a function from insert mode with imap?
body: <p>I have a function that I've written in my vimrc to turn syntax off and set paste. The function looks like this: </p>
  
  <pre><code>function! ToggleSyntax()
  if g:syntaxon == 1
  syntax off
  set paste
  let g:syntaxon = 0
  else
  syntax on
  set nopaste
  let g:syntaxon = 1
  endif
  endfunction
  </code></pre>
  
  <p>I use the F12 key to call the function, and have mapped the function to F12 like this: </p>
  
  <pre><code>map &lt;F12&gt; :call ToggleSyntax()&lt;cr&gt;
  imap &lt;F12&gt; &lt;c-o&gt;:call ToggleSyntax()&lt;cr&gt;
  </code></pre>
  
  <p>the problem that I'm having is that I can't call the ToggleSyntax function from insert mode. This is very confusing to me,  because I have used the imap handler, but still, this function only works from command mode. I can't figure out how to get it to work, any help with this would be greatly appreciated! thank you!</p>