配置VIM以从Ubuntu中的系统缓冲区复制和粘贴键盘快捷方式?


Answers:


16

MS Windows中的默认行为:-

这是mswin.vim文件的专家:-

" CTRL-X and SHIFT-Del are Cut
vnoremap <C-X> "+x
vnoremap <S-Del> "+x

" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y

" CTRL-V and SHIFT-Insert are Paste
map <C-V>       "+gP
map <S-Insert>      "+gP

cmap <C-V>      <C-R>+
cmap <S-Insert>     <C-R>+

" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature.  They are pasted as if they
" were characterwise instead.
" Uses the paste.vim autoload script.

exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']

imap <S-Insert>     <C-V>
vmap <S-Insert>     <C-V>

" Use CTRL-Q to do what CTRL-V used to do
noremap <C-Q>       <C-V>

和块模式剪切/粘贴所需的paste.vim脚本:-

    " Vim support file to help with paste mappings and menus
" Maintainer:   Bram Moolenaar <Bram@vim.org>
" Last Change:  2006 Jun 23

" Define the string to use for items that are present both in Edit, Popup and
" Toolbar menu.  Also used in mswin.vim and macmap.vim.

" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature.  They are pasted as if they
" were characterwise instead.  Add to that some tricks to leave the cursor in
" the right position, also for "gi".
if has("virtualedit")
  let paste#paste_cmd = {'n': ":call paste#Paste()<CR>"}
  let paste#paste_cmd['v'] = '"-c<Esc>' . paste#paste_cmd['n']
  let paste#paste_cmd['i'] = 'x<BS><Esc>' . paste#paste_cmd['n'] . 'gi'

  func! paste#Paste()
    let ove = &ve
    set ve=all
    normal! `^
    if @+ != ''
      normal! "+gP
    endif
    let c = col(".")
    normal! i
    if col(".") < c " compensate for i<ESC> moving the cursor left
      normal! l
    endif
    let &ve = ove
  endfunc
else
  let paste#paste_cmd = {'n': "\"=@+.'xy'<CR>gPFx\"_2x"}
  let paste#paste_cmd['v'] = '"-c<Esc>gix<Esc>' . paste#paste_cmd['n'] . '"_x'
  let paste#paste_cmd['i'] = 'x<Esc>' . paste#paste_cmd['n'] . '"_s'
endi

3
对于意外在此处进行SEO的Windows用户(OP为Ubuntu),请source $VIMRUNTIME/mswin.vim在_vimrc文件的顶部添加。还有什么时髦的事情可以阻止您也成功地将文件包含在Linux中?
鲁芬

1
@ruffin在检查源代码时,您会看到UNIX是否为语句,因此创建者还考虑了mswin.vimLinux下的用法。
RoliSoft 2014年

设置C-V粘贴将打破特殊字符输入模式: vim.wikia.com/wiki/...
g33kz0r

0

假设大多数情况都是默认设置,这只是最小的**:

:behave mswin
:set clipboard=unnamedplus
:smap <Del> <C-g>"_d
:smap <C-c> <C-g>y
:smap <C-x> <C-g>x
:imap <C-v> <Esc>pi
:smap <C-v> <C-g>p
:smap <Tab> <C-g>1> 
:smap <S-Tab> <C-g>1<
  • 第1行:让Shift +箭头选择文本(还有更多*)

  • 第2行:将“ +”(和“ *”)作为默认寄存器(GUI /术语剪贴板)

  • 第3、4、5、6行:进行Ctrl-x / c / v剪切/复制和粘贴

  • 第7,8行:使TAB / SHIFT + TAB缩进/突出选择

注意:*** [:set]设置可能会改变这种行为,并且可能需要进行许多调整才能满足您的需求,就像我说的那样,这很小。* [:behave]更改了许多[:set] tings阅读文档。


0

映射Ctrl-V以运行系统命令,该命令将获取系统剪贴板并将其放入寄存器中,然后将其粘贴到光标下方的屏幕上:

vmap <C-c> y:call system("xclip -i -selection clipboard", getreg("\""))<CR>:call system("xclip -i", getreg("\""))<CR>
nmap <C-v> :call setreg("\"",system("xclip -o -selection clipboard"))<CR>p

资料来源:http : //vim.wikia.com/wiki/In_line_copy_and_paste_to_system_clipboard


1
这不必要地复杂。您可以将地图映射为“ + y和” + p
FliiFe
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.