Using system clipboard in Vim on macOS
When you do copy, cut and paste text in Vim it goes into Vim’s own buffer (register).
Actually it has many registers, but we are’re interested only in primary (
More details on registers in Vim:
But it’s possible to make it work with system clipboard too.
Vim requires the
+clipboard feature flag to be set during compile.
Let’s check if Vim has this feature:
$ vim --version | grep clipboard +clipboard +keymap +printer +vertsplit +emacs_tags -mouse_gpm -sun_workshop -xterm_clipboard
By default macOS Catalina ships without clipboard. But the good news
we can easy install Vim with the
+clipboard feature from Homebrew for example:
$ brew install vim
We can set default register to
unnamed clipboard with command:
More details on clipboard in Vim:
I use shared
.vimrc configuration file across different machines,
so first check if it’s supported by Vim:
" .vimrc " " Set default clipboard register to system's unnamed " if has('clipboard') set clipboard=unnamed endif
Now commands like
d will put text into system clipboard
as well as
p command will take text from clipboard.
||Copy entire file|
||Copy till end of the line|
||Cut till end of the line|
||Paste before cursor|
||Paste after cursor|