Simple operations using the default register
Vim’s default register makes it easy to perform some of the most basic types of cut, copy, and paste operations. That’s partly thanks to the
p command, which behaves differently depending on whether the default register contains a characterwise or linewise region of text.
From Vim’s documentation (
Vim fills this register with text deleted with the “d”, “c”, “s”, “x” commands or copied with the yank “y” command, regardless of whether or not a specific register was used.
Vim calls this the unnamed register, which is a sweet oxymoron. I prefer to call it the default register.
Here are descriptions of a few simple commands that interact with the default register:
|x||cut one character and write it to default register|
|dd||cut one line and write it to default register|
|yy||copy one line into default register|
|p||put text from default register after cursor|
There’s more to the
p command than meets the eye: its behavior differs subtly depending on whether the register contains a characterwise or linewise region of text (see
:h linewise-register). When the default register contains a characterwise region of text, the
p command puts the text after the current character. Whereas when the default register contains a linewise region, the
p command puts the text after the current line.
yyp each consist of two separate commands, we can think of each pair as forming an aggregate command:
You can explicitly tell Vim that you want to paste the contents of the default register by prefixing the
p command with
"" (that is, doublequote twice). Of course,
p are equivalent, since the default register is used by default.