[英]Vim remap in paste mode
是否有可能在粘贴模式下重新映射。
例如,我在插入模式下使用inoremap jk <esc>
将jk
重新映射到<ESC>
inoremap jk <esc>
,因此我可以轻松退出正常模式。 但是当我使用:pastetoggle
处于粘贴模式时,我的重新映射不再起作用。 我寻找:help map-modes
的帮助,但找不到与粘贴模式相关的任何内容。
来自: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
[...]
重映射在粘贴模式下不起作用这一事实的一种解决方法是使用vim-unimpaired的y o和y O命令进行粘贴。 至少以这种方式离开带有粘贴设置的插入模式也会设置nopaste
并且当您不nopaste
,您将不会发现自己处于粘贴模式。
这可能对你有帮助。 它没有帮助我,因为我使用 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
这是我发现的另一种方法。 当您按 Esc 键离开插入模式时,它会自动关闭粘贴模式。 颜色也可以帮助您了解您所处的模式。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.