In past issues, we have covered using the clipboard register. The clipboard register syncs to the system clipboard and is accessible with the *
character. To paste from your system clipboard in normal mode, you can can use “*p
.
But what about if you’re in command mode? Let’s say you’ve copied some text from another program, maybe regular expression pattern. When you enter command mode with : you can’t use the usual method to paste from the clipboard register. Instead, use Ctrl-r
and then press *.
<C-r>*
- Paste into command mode from system clipboard
You can also use this insert mode. Plus, any of the registers will work including the numbered registers. In practice, I most often use the clipboard register to get data into and out of Vim.
Here’s a quick screencast of this in action. First, I enter command mode to preform a substitution. Then I hold Control
and press r
then *
and the pattern appears, pasted from my system clipboard:
Was this useful? Help us improve!
With your feedback, we can improve VimTricks. Click a link to vote:
A bit of a nitpick: "Command mode" in the documentation is an alias for "Normal mode". Check `:help command-mode`. What the article refers to is "Command-line mode" (`:help Command-line-mode`)
This is a great tip IF vim has been compiled with the clipboard option.
You can check this by running 'vim --version' and looking for the clipboard entry
-clipboard = no clipboard support
+clipboard = clipboard support
Unfortunately, some linux distros (I'm talking about YOU AWS) don't have this turned on.