In a terminal instance of Vim, how can I make abbreviation expansion be aut开发者_JAVA百科omatically disabled when I am pasting code?
Note: The keyword here is automatically, not manually via :set paste
.
There is no standard way for Vim to distinguish whether an input character was actually typed by the user or was generated for them by the X Window System through the clipboard or selection buffers. That is why there is the paste mode to manually switch Vim into the state when all input is not interpreted as interactively typed.
Thus, you have two alternatives:
Paste from the
"*
or"+
registers (that represent the clipboard and X selection, respectively), if you are using GVim or your Vim is compiled with theX11
feature (or, at least, with thexterm_clipboard
one).In case of Vim running in the terminal, you can manually synchronize one of the registers (for example, the unnamed one,
""
) with the clipboard or X selection. For instance, since I use Vim only in the terminal, I define the following mappings for myself:nmap <silent> <leader>y :call system('xclip', @")<cr> nmap <silent> <leader>p :call XClipRead()<cr> function! XClipRead() let s = system('xclip -o') if v:shell_error return endif call setreg('"', s) endfunction
To paste the contents of the X selection buffer using these mappings, you need to type the leader key followed by
p
, and then an appropriate Vim paste command. If you agree to lose the opportunity of using different paste commands (such asP
,gp
,]p
, etc), you can define a mapping that does both things:nmap <silent> <leader>P :call XClipRead()<cr>p
精彩评论