Search code examples
vim

Turn vim paste mode off when it is turned on


Title pretty much says it. Only thing to add is I am setting 3 modes at once. Putting the following:

map <F11> :set paste! number! rnu! paste?<CR>

in .vimrc only works in normal mode. Adding imap <F11> <Esc><F11>i<CR> doesn't help much because it only turns it on, but not off and moreover you lose the ability to return to replace mode automatically (if that was on). Using pastetoggle=<F11> doesn't suit it, because I need to set other stuff as well. Additional question: does map act equivalently to nmap since it doesn't trigger under insert/replace mode?


Solution

  • Using the following .vimrc combination did it:

    set number rnu pastetoggle=<F11> nmap <F11> :set paste! number! rnu! paste?<CR> imap <F11> <C-o>:set paste! number! rnu! paste?<CR>

    Strange as it is, it doesn't double-toggle in normal mode.

    One small caveat is that when toggling paste with F11 under insert mode you are cycling between 3 modes.