Copy and paste under Linux terminal and vim

Source: Internet
Author: User

http://www.tinylab.org/linux-terminal-and-paste-copy-under-vim/

Under the GUI interface, we are free to copy and paste. But in the character interface, we have to use the mouse to select, and then click on the right, select Copy, and then go elsewhere to ctrl-v. And for those with not configured Vim, Vim's pasteboard and X Window's pasteboard is not shared. This is in the process of the code word, feeling very not fluent. Below, we will try to solve this problem.

First we have to let vim and X Window share a pasteboard so that we can copy and paste it just like in the GUI interface. We can add this line in our Vim config file. VIMRC:

<textarea class="crayon-plain print-no" style="-moz-tab-size: 4; font-size: 12px ! important; line-height: 15px ! important; z-index: 0; opacity: 0; overflow: hidden;" readonly="" data-settings="mouseover">Set Clipboard=unamedplus</textarea>
1 Set Clipboard=unamedplus

This line of configuration means that Vim has the $$ ' + ' $$ this register (pasteboard) set to normal Yank and P operation of the default pasteboard, and $$ ' + ' $$ register in Vim is the Paste Board representing X window. So we let vim and X Window share a pasteboard, no longer have to worry about what is being copied in vim, and cannot be pasted outside of vim.

However, it is important to note that if you download the basic vim, you cannot achieve the desired effect according to the above settings. Because the VIM basic version does not support the X Window Pasteboard by default, you have to install the Vim full version, or the mega version. You can run the following command to determine if your vim supports the X Window's pasteboard:

<textarea class="crayon-plain print-no" style="-moz-tab-size: 4; font-size: 12px ! important; line-height: 15px ! important; z-index: 0; opacity: 0; overflow: hidden;" readonly="" data-settings="mouseover">Vim--version | grep clipboard</textarea>
1 Vim --version | grep clipboard

If clipboard and Xterm_clipboard have a plus sign, then this feature is supported, and the minus sign indicates no support.

Under Ubuntu, you should install Vim-gnome, and under Fedora you need to install vim-x11.

When this is done, you will find that vim empties the pasteboard at each exit, which is not what we want. We can add the following line configuration in the Vim configuration file to allow Vim to retain the contents of the Clipboard when it exits:

<textarea class="crayon-plain print-no" style="-moz-tab-size: 4; font-size: 12px ! important; line-height: 15px ! important; z-index: 0; opacity: 0; overflow: hidden;" readonly="" data-settings="mouseover">autocmd Vimleave * Call System ("Xsel-ib", Getreg (' + '))</textarea>
1 Autocmd vimleave * Call system("Xsel-ib", getreg(' + '))

This configuration is actually in vim every time you exit, run the Xsel command to save the ' + ' register contents to the system pasteboard, so this configuration requires you to install Xsel.

Now, suppose we yank some content from Vim, and then exit vim and paste it on the terminal command line, we may still have to pick up the mouse and right-click Paste. In fact, in most terminal there is a shortcut key: ctrl-shift-v, paste the content into the command line. This solves the problem of pasting under the terminal.

Someone might ask, what should I do if I copy under the terminal? This, has not found a very satisfactory solution for the time being.

Copy and paste under Linux terminal and vim

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.