How to copy a selection to the OS X clipboard

后端 未结 27 2158
野趣味
野趣味 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 15:11

    Copying to clipboard using register '+' or '*' is not working?

    Reason: Your particular version of vim was compiled without clipboard support.Type vim --verion on console and you will see -xterm_clipboard. Installing vim with gui packages solves this issue. On ubuntu you can do this by typing on shell:

    sudo apt-get install vim-gui-common

    Now again do vim --version on console. Most probably, you would be seeing +xterm_clipboard now!!

    So, now you can copy anything to clipboard using register + (like "+yy to copy current line to clipboard)

    0 讨论(0)
  • 2020-11-29 15:13

    For MacVim and Windows Gvim, simply add the following to your ~/.vimrc:

    set clipboard=unnamed
    

    Now all operations such as yy, D, and P work with the clipboard. No need to prefix them with "* or "+.

    0 讨论(0)
  • 2020-11-29 15:13

    Fakeclip implements the + and * buffers if they aren't natively supported.

    0 讨论(0)
  • 2020-11-29 15:15

    My main problem was the default OSX version of Vim. Installing it via homebrew added +clipboard to the build.

    You can check with:

    vim --version
    

    to see if it says -clipboard or +clipboard.

    0 讨论(0)
  • 2020-11-29 15:15

    if you have the +clipboard option on your Vim installation (you can check with :version) and you are in visual mode you can do "+y This will yank the selection to the buffer + that is the clipboard.

    I have added the following maps to my vimrc and it works fine.

    vmap <leader>y "+y : With this I can do leader key follow by y to copy to the clipboard in visual mode.

    nmap <leader>p "+p : With this I can do leader key follow by p to paste from the clipboard on normal mode.

    PD : On Ubuntu I had to install vim-gtk to get the +clipboard option.

    0 讨论(0)
  • 2020-11-29 15:15

    For Ubuntu users, the package you want to retrieve for using the clipboard is vim-full. The other packages (vim-tiny, vim) do not include the clipboard feature.

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