Copy and paste in LIinux terminal and Vim

Source: Internet
Author: User

Copy and paste in LIinux terminal and Vim

In the GUI, we can copy and paste it freely. But in the character interface, we have to select with the mouse, then click the right key, select copy, and then go elsewhere to Ctrl-v. In addition, for those VIM that have not been configured, the VIM clipboard and the X Window clipboard are not shared yet. This is not smooth in the Process of code words. Next, we will try to solve this problem.

First, we need to share a clipboard with VIM and X Window, so that we can copy and paste it like on the GUI. We can add this line in our VIM configuration file. vimrc:

Set clipboard = unamedplus

This configuration enables VIM to set the $ '+' $ register (Clipboard) to the default clipboard for normal yank and p operations, in VIM, the $ '+' $ register represents the clipboard of X Window. In this way, we can share a clipboard with VIM and X Window. We don't have to worry about copying in VIM any more. We can't paste it out of VIM.

However, note that if you download the basic VIM file, the above settings cannot achieve the expected results. By default, the basic version of VIM does not support the clipboard of X Window. Therefore, you must install the complete version of VIM or the giant version. You can run the following command to determine whether your VIM supports the X Window clipboard:

Vim -- version | grep clipboard

If the clipboard and xterm_clipboard carry a plus sign, this feature is supported, and the minus sign is not supported.

Under Ubuntu, you should install vim-gnome, and under Fedora, you need to install the vim-X11.

After this is done, you will find that VIM clears the clipboard every time it exits, and this is not what we want. We can add the following configuration line in the VIM configuration file to keep the content in the clipboard when VIM exits:

Autocmd VimLeave * call system ("xsel-ib", getreg ('+ '))

This configuration requires you to install xsel each time VIM exits, run the xsel command to save the content in the '+' register to the system clipboard.

Now, let's assume that we have some yank content from VIM, exit VIM, and paste it to the terminal command line. At this time, we may have to pick up the mouse and right-click and paste it. In fact, in most terminal, There is a shortcut key: Ctrl-Shift-v, paste the content into the command line. In this way, we solve the problem of pasting under the terminal.

Someone may ask, what should I do if I copy data under the terminal? At present, no satisfactory solution has been found.

-------------------------------------- Split line --------------------------------------

Build VIM into a simple and practical IDE

Vim Learning Guide

Quick learn Vi Editor

Powerful Vim Editor

Build a Vim Development Environment on CentOS 6.2

Install the highlighted Vim editing tool in CentOS 5.4

Vim tips: C language settings

Set the Vim row number in Ubuntu

Vim editor basic tutorial

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

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.