Copy and paste the text to get to know a vim

Reprinted from my independent blog https://liushiming.cn/2020/01/18/copy-and-paste-in-vim/

Outline

Copy and paste text editor is the most commonly used functions, copy and paste in vim but still a little trouble, a little learning costs. This article summarizes the typical usage scenarios and use vim copy and paste, I hope to help the reader.

Vim internal copy, paste, cut

Select the text

  • v + cursor (by character selection) to highlight the text, and then performs various operations (for example, d represents deleted).
  • V (row selection)
  • v + + c to change the selected content selected text

Copy: y (ank)

  • Y after the command to select text with the v, to copy with y
  • yy Copy the current line, then p-paste
  • 5yy copied from the beginning of the current line 5
  • y_ equivalent to yy
  • Y is equivalent to yy
  • yw Copy the current word
  • Y $ copied from the current position to the end of line
  • y0 copied from the current position to the beginning of the line
  • y ^ copied from the current position to the first non-blank character
  • yG copied from the current line to the end of the file
  • y20G copied from the current line to the line 20
  • y? bar copy to the previous position bar appears

Paste: p (aste)

  • p (lower case) attached to the cursor position after the
  • P (upper case) attached to the cursor position before

Shear

  • v + arrow key (the hjkl) selected text pasting + d + p Cut

Clipboard

The default clipboard

providing the clipboard 12 vim, their names are vim clipboard 11 has, respectively 0, 1, 2, ..., 9, a, . If you turn the system clipboard, it will be another two more: +and *. Use :regcommand, you can view the contents of each clipboard.

:reg

Y is only used in a simple replication into vim (double quote) pasteboard, the same is with the p paste the contents of the clipboard.

Copy and paste the clipboard to the specified

Vim copy the contents to a clipboard, you need to exit edit mode, after entering the normal mode, select the content you want to copy, then press the "Ny complete copy, where N is the number pasteboard (note the quotation marks and then double click on press the clipboard by number of the last y), such as copying to the clipboard content should a, the contents of the selected press "ay it.

To some vim Paste the contents of the clipboard in, need to exit editing mode, in normal mode, press the "Np, where N is the number clipboard. For example, you can press" 5p to paste the clipboard came in No. 5 in the content, but also you can press "+ p global system clipboard to paste the contents of the room.

The system clipboard

Vim supports the system clipboard, you need to open the clipboard function. Use the following command to check the current version of Vim, supports clipboard.

$ vim --version | grep "clipboard"
-clipboard       +insert_expand   +path_extra      +user_commands
+emacs_tags      -mouseshape      +startuptime     -xterm_clipboard
root@sz ➜  ~ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 07 2019 15:35:43)

-clipboardRepresentatives do not support +clipboardrepresentatives supported.
If not, then you need to install gvim or turn on the system clipboard option at compile time.

vim copied to the system clipboard

  • "*y
  • "+y
  • "+2yy - Copy the two lines
  • {Visual}"+y - copy the selected text into the system clipboard
  • "+y{motion} - copy the text specified by {motion} into the system clipboard
  • :[range]yank + - copy the text specified by [range] into the system clipboard

vim into the system clipboard

  • "+dd - Cut a row

Paste from the system clipboard to vim

  • "*p
  • "+p
  • Shift+Insert
  • :put + - Ex command puts contents of system clipboard on a new line
  • <C-r>+ - From insert mode (or commandline mode)

"+pBetter than Ctrl-v command, it can be faster and more reliably handle pasting large blocks of text, can be avoided when pasting large amounts of text, the occurrence of each line of automatic indentation accumulation, because Ctrl-va stream processing through the system cache, row by row processing pasted text.

Vim default settings to use the system clipboard

OK vim support +clipboardafter, if you want y/p, and get through the system clipboard directly, you can ~/.vimrcadd the following configuration):

set clipboard^=unnamed,unnamedplus

Wherein unnamed representative of *registers, unnamedplus representative of +registers. In mac system, both of the same; linux systems in general +and *is different, +corresponding to ctrl + c, ctrl + vdesktop system clipboard, *the corresponding x desktop clipboard (select with the mouse to copy, paste with the mouse button).

Server vim copied to the local clipboard

When connecting to a linux server via ssh, vim is running on a remote server, you can not use ycopied to the local clipboard. Then there are several ways:

cmd + c

Select the text with the mouse cmd + cto copy (the windows ctrl + ccopy), cmd + vand paste to the local. This method is the most natural, but want to use this method has several prerequisites:

  • vim configuration is turned on mouse support, .vimrcfile plus
set mouse=a

Local vim editing remote files via scp

Use local vim to edit remote files directly via scp. So that you can use local registers "+y"copied. This method does not require the remote configuration vim.

vim scp://[email protected]//absolute/path/to/file

Com and absolute attention between two backslash is //not a knock on the wrong.

Reference links

Vim internal copy, paste, cut

Select the text

  • v + cursor (by character selection) to highlight the text, and then performs various operations (for example, d represents deleted).
  • V (row selection)
  • v + + c to change the selected content selected text

Copy: y (ank)

  • Y after the command to select text with the v, to copy with y
  • yy Copy the current line, then p-paste
  • 5yy copied from the beginning of the current line 5
  • y_ equivalent to yy
  • Y is equivalent to yy
  • yw Copy the current word
  • Y $ copied from the current position to the end of line
  • y0 copied from the current position to the beginning of the line
  • y ^ copied from the current position to the first non-blank character
  • yG copied from the current line to the end of the file
  • y20G copied from the current line to the line 20
  • y? bar copy to the previous position bar appears

Paste: p (aste)

  • p (lower case) attached to the cursor position after the
  • P (upper case) attached to the cursor position before

Shear

  • v + arrow key (the hjkl) selected text pasting + d + p Cut

Clipboard

The default clipboard

providing the clipboard 12 vim, their names are vim clipboard 11 has, respectively 0, 1, 2, ..., 9, a, . If you turn the system clipboard, it will be another two more: +and *. Use :regcommand, you can view the contents of each clipboard.

:reg

Y is only used in a simple replication into vim (double quote) pasteboard, the same is with the p paste the contents of the clipboard.

Copy and paste the clipboard to the specified

Vim copy the contents to a clipboard, you need to exit edit mode, after entering the normal mode, select the content you want to copy, then press the "Ny complete copy, where N is the number pasteboard (note the quotation marks and then double click on press the clipboard by number of the last y), such as copying to the clipboard content should a, the contents of the selected press "ay it.

To some vim Paste the contents of the clipboard in, need to exit editing mode, in normal mode, press the "Np, where N is the number clipboard. For example, you can press" 5p to paste the clipboard came in No. 5 in the content, but also you can press "+ p global system clipboard to paste the contents of the room.

The system clipboard

Vim supports the system clipboard, you need to open the clipboard function. Use the following command to check the current version of Vim, supports clipboard.

$ vim --version | grep "clipboard"
-clipboard       +insert_expand   +path_extra      +user_commands
+emacs_tags      -mouseshape      +startuptime     -xterm_clipboard
root@sz ➜  ~ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 07 2019 15:35:43)

-clipboardRepresentatives do not support +clipboardrepresentatives supported.
If not, then you need to install gvim or turn on the system clipboard option at compile time.

vim copied to the system clipboard

  • "*y
  • "+y
  • "+2yy - Copy the two lines
  • {Visual}"+y - copy the selected text into the system clipboard
  • "+y{motion} - copy the text specified by {motion} into the system clipboard
  • :[range]yank + - copy the text specified by [range] into the system clipboard

vim into the system clipboard

  • "+dd - Cut a row

Paste from the system clipboard to vim

  • "*p
  • "+p
  • Shift+Insert
  • :put + - Ex command puts contents of system clipboard on a new line
  • <C-r>+ - From insert mode (or commandline mode)

"+pBetter than Ctrl-v command, it can be faster and more reliably handle pasting large blocks of text, can be avoided when pasting large amounts of text, the occurrence of each line of automatic indentation accumulation, because Ctrl-va stream processing through the system cache, row by row processing pasted text.

Vim default settings to use the system clipboard

OK vim support +clipboardafter, if you want y/p, and get through the system clipboard directly, you can ~/.vimrcadd the following configuration):

set clipboard^=unnamed,unnamedplus

Wherein unnamed representative of *registers, unnamedplus representative of +registers. In mac system, both of the same; linux systems in general +and *is different, +corresponding to ctrl + c, ctrl + vdesktop system clipboard, *the corresponding x desktop clipboard (select with the mouse to copy, paste with the mouse button).

Server vim copied to the local clipboard

When connecting to a linux server via ssh, vim is running on a remote server, you can not use ycopied to the local clipboard. Then there are several ways:

cmd + c

Select the text with the mouse cmd + cto copy (the windows ctrl + ccopy), cmd + vand paste to the local. This method is the most natural, but want to use this method has several prerequisites:

  • vim configuration is turned on mouse support, .vimrcfile plus
set mouse=a

Local vim editing remote files via scp

Use local vim to edit remote files directly via scp. So that you can use local registers "+y"copied. This method does not require the remote configuration vim.

vim scp://[email protected]//absolute/path/to/file

Com and absolute attention between two backslash is //not a knock on the wrong.

Reference links

Guess you like

Origin www.cnblogs.com/huahuayu/p/12235242.html