V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xinali
V2EX  ›  Vim

vim 从一个文件粘贴到另一个文件,有时好用,有时不好用,这是什么原因呢?

  •  
  •   xinali · 2016-07-18 20:53:00 +08:00 · 3253 次点击
    这是一个创建于 2838 天前的主题,其中的信息可能已经有所发展或是发生改变。

    要说完全没法用还好说,关键是,有时能用,有时不能用,没办法了粘贴的时候只能调出 gedit 去复制,之后再用 vim 编辑 vim 的版本

    
    VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:39:32)
    Included patches: 1-52
    Modified by [email protected]
    Compiled by buildd@
    Huge version without GUI.  Features included (+) or not (-):
    +acl             +farsi           +mouse_netterm   +syntax
    +arabic          +file_in_path    +mouse_sgr       +tag_binary
    +autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
    -balloon_eval    +float           +mouse_urxvt     -tag_any_white
    -browse          +folding         +mouse_xterm     -tcl
    ++builtin_terms  -footer          +multi_byte      +terminfo
    +byte_offset     +fork()          +multi_lang      +termresponse
    +cindent         +gettext         -mzscheme        +textobjects
    -clientserver    -hangul_input    +netbeans_intg   +title
    -clipboard       +iconv           +path_extra      -toolbar
    +cmdline_compl   +insert_expand   -perl            +user_commands
    +cmdline_hist    +jumplist        +persistent_undo +vertsplit
    +cmdline_info    +keymap          +postscript      +virtualedit
    +comments        +langmap         +printer         +visual
    +conceal         +libcall         +profile         +visualextra
    +cryptv          +linebreak       +python          +viminfo
    +cscope          +lispindent      -python3         +vreplace
    +cursorbind      +listcmds        +quickfix        +wildignore
    +cursorshape     +localmap        +reltime         +wildmenu
    +dialog_con      -lua             +rightleft       +windows
    +diff            +menu            -ruby            +writebackup
    +digraphs        +mksession       +scrollbind      -X11
    -dnd             +modify_fname    +signs           -xfontset
    -ebcdic          +mouse           +smartindent     -xim
    +emacs_tags      -mouseshape      -sniff           -xsmp
    +eval            +mouse_dec       +startuptime     -xterm_clipboard
    +ex_extra        +mouse_gpm       +statusline      -xterm_save
    +extra_search    -mouse_jsbterm   -sun_workshop    -xpm
       system vimrc file: "$VIM/vimrc"
         user vimrc file: "$HOME/.vimrc"
     2nd user vimrc file: "~/.vim/vimrc"
          user exrc file: "$HOME/.exrc"
      fall-back for $VIM: "/usr/share/vim"
    Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
    Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl    -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions
    
    
    21 条回复    2016-09-18 11:24:25 +08:00
    kotomi
        1
    kotomi  
       2016-07-18 21:13:52 +08:00
    你是怎么复制的?我"+y -> "+p 总是成功的,编辑状态下 command + c -> command + v 也是可以的。
    ceyes
        2
    ceyes  
       2016-07-18 21:18:20 +08:00
    的确容易被这些剪切板 /寄存器搞得头晕眼花,索性 :vs 打开另一个文件然后复制粘贴就简单多了
    3pointer
        3
    3pointer  
       2016-07-18 21:26:53 +08:00 via iPhone
    你需要 tmux
    dong4138
        4
    dong4138  
       2016-07-18 21:31:41 +08:00
    vim: "+y 复制到剪切板
    tmux: <c-b>[
    RIcter
        5
    RIcter  
       2016-07-18 21:36:27 +08:00 via iPhone
    vim 里 :set paste
    xinali
        6
    xinali  
    OP
       2016-07-18 21:52:54 +08:00
    统一回复一下,现在我能成功时,只能是首先打开一个文件,之后"+y 复制,之后立马关闭该文件,之后打开需要粘贴的文件,利用"+p 进行复制,这样可以成功

    在两个文件同时打开的情况下
    @RIcter 这个方法尝试了,但是没有成功
    @dong4138 这个是什么意思? tmux <c-b>[ 这个难道不是翻页的功能吗?还有别的用法
    @kotomi ubuntu 下在编辑状态下,貌似只能右键选择进行复制,也许有别的方法,我还不知道
    xinali
        7
    xinali  
    OP
       2016-07-18 22:21:53 +08:00
    还有一点需要说明的是,每次最多只能复制 50 line 。。。
    HHehr0ow
        8
    HHehr0ow  
       2016-07-18 22:22:13 +08:00
    :reg 看看剪贴板里都是些啥内容
    Bardon
        9
    Bardon  
       2016-07-18 22:34:41 +08:00
    vim --version | grep clipboard
    看下,如果编译开关没打开
    则装个 gvim 吧
    seoguess
        10
    seoguess  
       2016-07-18 22:40:12 +08:00
    这个问题我也纠结过。

    set pas 自动补全,我记不住,然后 i 插入
    然后 set nopas 取消

    就不会错位了。
    ETiV
        11
    ETiV  
       2016-07-18 23:08:28 +08:00 via iPhone
    vim 复制内容我都是打开文件 A ,再 :tabnew 文件 B

    复制好后 gt 、粘贴
    dong4138
        12
    dong4138  
       2016-07-19 10:16:49 +08:00
    @xinali 我是设置了复制的 vi 模式,按了<c-b>[ 后, vi 的移动,选择, copy 操作都可以用
    wlsnx
        13
    wlsnx  
       2016-07-19 10:31:17 +08:00
    +clipboard 直接 p
    morefreeze
        14
    morefreeze  
       2016-07-19 10:43:47 +08:00
    分享个复制的 map 吧,仔细看注释

    " Allow to copy/paste between VIM instances
    "copy the current visual selection to ~/.vbuf
    vmap <leader>y :w! ~/.vbuf<cr>

    "copy the current line to the buffer file if no visual selection
    nmap <leader>y :.w! ~/.vbuf<cr>
    bp0
        15
    bp0  
       2016-07-19 13:51:28 +08:00
    set clipboard=unnamed

    可以默认使用系统的剪贴板
    xinali
        16
    xinali  
    OP
       2016-07-19 17:12:56 +08:00
    @morefreeze leader 是什么?
    morefreeze
        17
    morefreeze  
       2016-07-19 18:22:00 +08:00
    :help leader 看一下,简单来说就是个按键,默认是\
    elvba
        18
    elvba  
       2016-07-22 00:31:28 +08:00
    @RIcter +1
    ashfinal
        19
    ashfinal  
       2016-07-23 15:05:27 +08:00
    感觉楼上回复的都比较模糊混乱,这里统一说一下:

    为啥要用 "+y "+p 这种方式呢,直接 yy p 不行么?我一般都是用插件 yankring 的。这是个可视化多剪贴板,很有用。

    +clipboard 选项是与外部程序共享剪贴板的。没这特性,从 firefox 或其它程序复制文本,在 vim 直接按 p 是粘贴不进来的。看楼主 :version 输出信息这项是 -clipboard ,可以考虑有空的时候重新编译下 vim 。 一般 gvim 这一选项默认都是开的。

    set (no)paste 选项是从外部粘贴过来防止格式缩进错乱的,与粘不粘得进来关系不大。

    麻烦对照下重新阐释下自己遇到的问题。

    顺便打个广告,我的 vimrc 配置: https://github.com/ashfinal/vimrc-config
    chemzqm
        20
    chemzqm  
       2016-07-29 22:35:29 +08:00
    自己编译吧 你这个 vim 版本太老了一点 clipboard 也没启用
    ThomasZ
        21
    ThomasZ  
       2016-09-18 11:24:25 +08:00
    可以设置共用系统剪贴板

    if has('clipboard')
    if has('unnamedplus') " When possible use + register for copy-paste
    set clipboard=unnamed,unnamedplus
    else " On mac and Windows, use * register for copy-paste
    set clipboard=unnamed
    endif
    endif
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   996 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:10 · PVG 04:10 · LAX 13:10 · JFK 16:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.