【发布时间】:2017-01-12 00:36:28
【问题描述】:
是否有可能在粘贴模式下重新映射。
例如,我在插入模式下用inoremap jk <esc> 将jk 重新映射到<ESC>,这样我就可以轻松退出正常模式。但是当我使用:pastetoggle 处于粘贴模式时,我的重新映射不再起作用。我通过:help map-modes 寻求帮助,但找不到与粘贴模式相关的任何内容。
【问题讨论】:
是否有可能在粘贴模式下重新映射。
例如,我在插入模式下用inoremap jk <esc> 将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 的 yo 和 y O命令粘贴。至少这种方式离开插入模式并设置粘贴也会设置nopaste,当你不想这么多时,你不会发现自己处于粘贴模式。
【讨论】:
这可能会对您有所帮助。它对我没有帮助,可惜我使用的是 GNU 屏幕,并且它不支持带括号的 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
【讨论】:
这是我发现的另一种方法。当您点击退出以离开插入模式时,它会自动关闭粘贴模式。颜色还可以帮助您了解您处于哪种模式。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
【讨论】: