Copying from outside of Vim

There are two built-in registers that interact with the outside world:

  • The * register is the primary system clipboard (the default clipboard in Mac and Windows, and mouse selection inside a Terminal in Linux)
  • The + register (only in Linux) is used for Windows-style Ctrl + c and Ctrl + v operations (referred to as Clipboard selection)

You can interact with these registers as you would with any other. For instance, you can use "*p to paste from the primary clipboard or use "+yy to yank a line into Linux's Clipboard selection.

If you want Vim to work with these registers by default, you can set the clipboard variable in your .vimrc file. Set it to unnamed to copy and paste from the * register:

set clipboard=unnamed  " Copy into system (*) register.

Set it to unnamedplus for yank and paste commands to work with the + register by default:

set clipboard=unnamedplus  " Copy into system (+) register.

You can also tell Vim to use both at once:

set clipboard=unnamed,unnamedplus  " Copy into system (*, +) register.

Now, y and p will yank and paste from the specified register by default.

You can also sometimes choose to paste text from the system clipboard while inside the insert mode. In older Vim versions or in certain Terminal emulators, this will yield some issues, since Vim will try to automatically indent code or extend commented out sections. To avoid this, run :set paste before pasting code to disable auto indent and auto comment insertion. Run :set nopaste to turn it back on once you're done.

Most of these issues are resolved in bracketed paste mode, which is enabled by default, starting with version 8.0. See :help xterm-bracketed-paste for more details.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.228.40