簡體   English   中英

Vim 在粘貼模式下重新映射

[英]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-unimpairedy oy 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM