How to copy a selection to the OS X clipboard

后端 未结 27 2156
野趣味
野趣味 2020-11-29 14:17

I have an area selected in Vim. How can I copy it into the OS X clipboard?

(The OS X clipboard can be written to via a pipe to /usr/bin/pbcopy)

相关标签:
27条回答
  • 2020-11-29 14:55

    On macos 10.8, vim is compiled with -clipboard so to use "*y you'll need to recompile. Luckily brew install vim would compile a new version easily for you and it will be +clipboard.

    0 讨论(0)
  • 2020-11-29 14:57

    What worked for me in my .vimrc

    set clipboard=unnamed
    if has("unnamedplus") " X11 support
        set clipboard+=unnamedplus
    endif
    
    0 讨论(0)
  • 2020-11-29 14:58

    In my case I just had to do :

    :set mouse=v
    

    please visit the original solution on superuser.com

    0 讨论(0)
  • 2020-11-29 14:59

    You can visually select text and type :w !pbcopy<CR>

    Or you can include the below key mappings in your ~/.vimrc file. They cut/copy text in visual mode to the operating system's clipboard.

    vmap <C-x> :!pbcopy<CR>  
    vmap <C-c> :w !pbcopy<CR><CR> 
    

    source: http://drydevelopment.com/blog/vim-pbcopy-on-os-x

    0 讨论(0)
  • 2020-11-29 14:59

    If you are on MacOS X:

    $ brew install vim
    $ vim --version
    VIM - Vi IMproved 7.4 [...]
    

    Then, add to your .vimrc:

    set clipboard=unnamed
    

    Now you just need to be in vim and do :%y, to have all the content copied to your clipboard.

    0 讨论(0)
  • 2020-11-29 14:59

    I am currently on OS X 10.9 and my efforts to compile vim with +xterm_clipboard brought me nothing. So my current solution is to use MacVim in terminal mode with option set clipboard=unnamed in my ~/.vimrc file. Works perfect for me.

    0 讨论(0)
提交回复
热议问题