在粘贴模式下重新映射Vim

3
有没有一种可能在粘贴模式下进行重新映射。
例如,我使用“inoremap jk ”在插入模式下重新映射了“jk”为“”,以便我可以轻松地退出正常模式。但是当我使用“:pastetoggle”进入粘贴模式时,我的重新映射就不再起作用了。我查看了“:help map-modes”的帮助文档,但没有找到与粘贴模式相关的内容。
4个回答

6

来自: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
[...] 

1

解决重新映射在粘贴模式下无法工作的方法是使用vim-unimpairedyoyO命令进行粘贴。至少这样,离开插入模式时设置粘贴将同时设置nopaste,这样你就不会发现自己在不想要的情况下进入粘贴模式。


0

这可能会对你有所帮助。但是对我来说没有用,因为我使用GNU screen,它不支持括号化的xterm粘贴转义码。

(来自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

0

这里是我发现的另一种方法。当您按下Esc键退出插入模式时,它会自动关闭粘贴模式。此外,颜色可以帮助您知道当前所处的模式。希望对您有所帮助。

" 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接