Reputation: 1439
Is there a possibility to remap in paste mode.
For example, I remapped jk
to <ESC>
in insert mode with inoremap jk <esc>
, so I can easily exit normal mode. But when I'm in paste mode with :pastetoggle
my remapping does not work anymore. I looked for the help with :help map-modes
but could not find anything related to the paste mode.
Upvotes: 3
Views: 1250
Reputation: 3096
Here is another approach I found. When you hit escape to leave insert mode it turns off paste mode automatically. Also the colors help you know which mode you are in. hth.
" Mode Indication -Prominent!
function! InsertStatuslineColor(mode)
if a:mode == 'i'
hi statusline ctermfg=red
elseif a:mode == 'r'
hi statusline ctermfg=blue
else
hi statusline ctermfg= magenta
endif
endfunction
function! InsertLeaveActions()
hi statusline ctermfg=green
set nopaste
endfunction
au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertLeave * call InsertLeaveActions()
" to handle exiting insert mode via a control-C
inoremap <c-c> <c-o>:call InsertLeaveActions()<cr><c-c>
" default the statusline to green when entering Vim
hi statusline ctermfg=green
" have a permanent statusline to color
set laststatus=2
Upvotes: 0
Reputation: 3096
This might help you. It didn't help me as alas I use GNU screen and it has not support for bracketed xterm paste escape codes
(from https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode)
:inoremap jj <esc>
:inoremap jk <esc>
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"
" This resets paste mode after insert
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
echo "DONE"
return ""
endfunction
Upvotes: 0
Reputation: 28722
One workaround to the fact that remappings don't work in paste mode is to use vim-unimpaired's yo and yOcommands to paste. At least this way leaving insert mode with paste set will also set nopaste
and you won't find yourself in paste mode when you don't want to be as much.
Upvotes: 1
Reputation: 196789
From :help 'paste'
:
[...]
When the 'paste' option is switched on (also when it was already on):
- mapping in Insert mode and Command-line mode is disabled
[...]
Upvotes: 6