简体   繁体   中英

Vim remap in paste mode

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.

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
[...] 

One workaround to the fact that remappings don't work in paste mode is to use vim-unimpaired 's y o and y O commands 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM