Open the system clipboard function of Vim in Ubuntu 18
1. Check whether Vim supports the system clipboard
There are two ways to check whether Vim supports the system clipboard function.
Method 1: View the information on the terminal
- Enter at the terminal
vim --version | grep clipboard
Enter:
jpch89@jpch89-Ubuntu:~$ vim --version | grep clipboard
+clipboard +jumplist +persistent_undo +virtualedit
-ebcdic +mouseshape +statusline +xterm_clipboard
Copy the code
- if
clipboard
The front is-
Please continue to see the next section if both are supported+
You can skip to the last section.
Method two: InVim
In the view
- Enter at the terminal
vim
Enter into theVim
- The input
:echo has('clipboard')
enter - Let’s say it shows
0
The system clipboard is not supported. Please continue to the next section if1
Support system clipboard, you can directly skip to the last section.
2. Enable the system clipboard function
- There are many ways to open the system clipboard function, the more orthodox should be recompile and install
Vim
Source code, because I am afraid of trouble (horizontal slag), so choose the simple method, namely installationvim-gnome
. - A line of instructions can be done, in the terminal input
sudo apt install vim-gnome -y
Press enter. - At this point, the above two methods are used again to verify, and found
Vim
The system clipboard function is supported.
3. Use the system clipboard function
3.1 Copying a Vim File from a Terminal
- First copy a sentence in the terminal, such as
print('Hello, world! ')
. vim hello.py
Press enter.:reg +
View the system clipboard, as shown in the figure below:
"+p
Paste, successful:
3.2 Copying Vim Files to Terminals
- In the first
Vim
Copy a sentence in it, likels
ctrl + alt + t
Open a new terminal,ctrl + shift + v
Paste, success!
Note: if the Vim terminal is closed here, it is not possible to paste!
3.3 Setting the System Clipboard as the Default Register
- in
Vim
The default register is an anonymous register (""
), we can pass the modificationvimrc
File to use the system clipboard as the default register, so you don’t have to add it every time"+
The prefix. - Add this line to the configuration file
set clipboard^=unnamed,unnamedplus
, done!
As to why write this line configuration, mainly for cross-platform general, specific how to study, I have no interested friends can refer to the following links: stackoverflow.com/questions/3…
Completed in 2019.6.27