Access Clipboard content across multiple vim instances on the terminal

Source: Internet
Author: User
Tags expression engine

Vim (Vi IMproved) is a popular text editor among programmers. It has its own expertise in executing different shortcut commands.

For example, to copy the highlighted text, run the 'y' command and cut it with 'X. However, the content of the vim (not gVim) clipboard cannot be accessed by other vim instances by default.

The system clipboard is enabled using '+' in the Vim version information. You can run 'vim ­-version'. If you don't see "+ xterm_clipboard" but show "­ xterm _ clipboard", the internal clipboard will be used, it cannot be accessed by other vim instances.

Install gvim and parcellite

To access the content of the vim clipboard, you need to install the gvim package. GVim is the GUI mode of the vim editor. Its clipboard option is enabled by default.

  1. # Yum install-y gvim

Then, use the RPMForge repository to install the parcellite package. Parcellite is a lightweight, compact, and free Linux clipboard management tool.

  1. # Yum install-y parcellite

After installation, run the following command. Here the parameter '&' is used to run the parcellite later processes.

  1. # Parcellite & amp;

Check options are enabled in gvim.

  1. # Gvim -- version

Make sure that the "+ xterm_clipboard" option is displayed in the following output.

  1. VIM-ViIMproved7.2 (2008Aug9, compiled Apr5201210: 12: 08)
  2. Encoded ded patches: 1-411
  3. Modifiedby & lt; bugzilla@RedHat.com & gt;
  4. Compiledby bugzilla@redhat.com;
  5. Huge version with GTK2 GUI. Features encoded ded (+) ornot (-):
  6. + Arabic + autocmd + balloon_eval + browse ++ builtin_terms + byte_offset + cindent
  7. + Clientserver + clipboard + cmdline_compl + cmdline_hist + cmdline_info + comments
  8. + Cryptv + cs1_+ cursorshape + dialog_con_gui + diff + digraphs + dnd-ebcdic
  9. + Emacs_tags + eval + ex_extra + extra_search + farsi + file_in_path + find_in_path
  10. + Float + folding-footer + fork () + gettext-hangul_input + iconv + insert_expand
  11. + Jumplist + keymap + langmap + libcall + linebreak + lispindent + listcmds + localmap
  12. + Menu + mksession + modify_fname + mouse + mouseshape + mouse_dec + mouse_gpm
  13. -Mouse_jsbterm + mouse_netterm-mouse_sysmouse + mouse_xterm + multi_byte
  14. + Multi_lang-mzscheme + netbeans_intg-osfiletype + path_extra + perl + postscript
  15. + Printer + profile + python + quickfix + reltime + rightleft-ruby + scrollbind
  16. + Signs + smartindent-sniff + startuptime + statusline-sun_workshop + syntax
  17. + Tag_binary + tag_old_static-tag_any_white-tcl + terminfo + termresponse
  18. + Textobjects + title + toolbar + user_commands + vertsplit + virtualedit + visual
  19. + Javasalextra + viminfo + vreplace + wildignore + wildmenu + windows + writebackup
  20. + X11-xfontset + xim + xsmp_interact + xterm_clipboard-xterm_save

Open your. bashrc file.

  1. # Vim ~ /. Bashrc

Add the alias and save the file (Press 'I to insert the row, Press ESC, and run: wq to save and exit ).

  1. #. Bashrc
  2. # User specific aliases and functions
  3. Alias rm = 'rm-I'
  4. Alias cp = 'cp-I'
  5. Alias mv = 'mv-I'
  6. Alias vim = 'gvim-V'
  7. # Source global definitions
  8. If [-f/etc/bashrc]; then
  9. ./Etc/bashrc
  10. Fi

This alias is built in to wrap some commands around other commands. In this way, each time the vim command is run, the corresponding alias will start gVim with clipboard by default.

Now, edit your '. vimrc' file in a similar way (in case you do not have a. vimrc file, generate such a file and return it again ).

  1. # Vim ~ /. Vimrc

Append the following line and save the file.

  1. Autocmd VimLeave * call system ("echo-n $ '". escape (getreg (), "'"). "'| xsel-ib ")

Now open any file in vim, highlight some text (use the 'V' command), and press 'y '. Try to paste the post anywhere outside vim (if it is off or not vim), and you will find that the copied content in vim is pasted out.

Attachment: generate the. vimrc File

Run the following command to generate the. vimrc file (skip this part if you have done it ).

  1. # Cd [return to your home directory]
  2. # Vim. vimrc

In vim, run the following command after pressing the ESC key (in vim, each command is run after pressing the ESC key, that is, it takes you to the command mode ).

  1. : R $ VIMRUNTIME/vimrc_example.vim
  2. : W

Recommended reading:

Vim Learning Guide

Quick learn Vi Editor

Powerful Vim Editor

Build a Vim Development Environment on CentOS 6.2

Vim 7.4a released, a new and faster Regular Expression Engine

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

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.