简体   繁体   English

Vim 在粘贴模式下重新映射

[英]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.例如,我在插入模式下使用inoremap jk <esc>jk重新映射到<ESC> inoremap jk <esc> ,因此我可以轻松退出正常模式。 But when I'm in paste mode with :pastetoggle my remapping does not work anymore.但是当我使用:pastetoggle处于粘贴模式时,我的重新映射不再起作用。 I looked for the help with :help map-modes but could not find anything related to the paste mode.我寻找:help map-modes的帮助,但找不到与粘贴模式相关的任何内容。

From :help 'paste' :来自: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.重映射在粘贴模式下不起作用这一事实的一种解决方法是使用vim-unimpairedy oy O命令进行粘贴。 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.至少以这种方式离开带有粘贴设置的插入模式也会设置nopaste并且当您不nopaste ,您将不会发现自己处于粘贴模式。

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它没有帮助我,因为我使用 GNU screen 并且它不支持括号内的 xterm 粘贴转义码

(from https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode ) (来自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.当您按 Esc 键离开插入模式时,它会自动关闭粘贴模式。 Also the colors help you know which mode you are in. hth.颜色也可以帮助您了解您所处的模式。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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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