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.
- # 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.
- # Yum install-y parcellite
After installation, run the following command. Here the parameter '&' is used to run the parcellite later processes.
- # Parcellite & amp;
Check options are enabled in gvim.
- # Gvim -- version
Make sure that the "+ xterm_clipboard" option is displayed in the following output.
- VIM-ViIMproved7.2 (2008Aug9, compiled Apr5201210: 12: 08)
- Encoded ded patches: 1-411
- Modifiedby & lt; bugzilla@RedHat.com & gt;
- Compiledby bugzilla@redhat.com;
- Huge version with GTK2 GUI. Features encoded ded (+) ornot (-):
- + Arabic + autocmd + balloon_eval + browse ++ builtin_terms + byte_offset + cindent
- + Clientserver + clipboard + cmdline_compl + cmdline_hist + cmdline_info + comments
- + Cryptv + cs1_+ cursorshape + dialog_con_gui + diff + digraphs + dnd-ebcdic
- + Emacs_tags + eval + ex_extra + extra_search + farsi + file_in_path + find_in_path
- + Float + folding-footer + fork () + gettext-hangul_input + iconv + insert_expand
- + Jumplist + keymap + langmap + libcall + linebreak + lispindent + listcmds + localmap
- + Menu + mksession + modify_fname + mouse + mouseshape + mouse_dec + mouse_gpm
- -Mouse_jsbterm + mouse_netterm-mouse_sysmouse + mouse_xterm + multi_byte
- + Multi_lang-mzscheme + netbeans_intg-osfiletype + path_extra + perl + postscript
- + Printer + profile + python + quickfix + reltime + rightleft-ruby + scrollbind
- + Signs + smartindent-sniff + startuptime + statusline-sun_workshop + syntax
- + Tag_binary + tag_old_static-tag_any_white-tcl + terminfo + termresponse
- + Textobjects + title + toolbar + user_commands + vertsplit + virtualedit + visual
- + Javasalextra + viminfo + vreplace + wildignore + wildmenu + windows + writebackup
- + X11-xfontset + xim + xsmp_interact + xterm_clipboard-xterm_save
Open your. bashrc file.
- # Vim ~ /. Bashrc
Add the alias and save the file (Press 'I to insert the row, Press ESC, and run: wq to save and exit ).
- #. Bashrc
- # User specific aliases and functions
- Alias rm = 'rm-I'
- Alias cp = 'cp-I'
- Alias mv = 'mv-I'
- Alias vim = 'gvim-V'
- # Source global definitions
- If [-f/etc/bashrc]; then
- ./Etc/bashrc
- 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 ).
- # Vim ~ /. Vimrc
Append the following line and save the file.
- 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 ).
- # Cd [return to your home directory]
- # 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 ).
- : R $ VIMRUNTIME/vimrc_example.vim
- : 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