[Vi/Vim] Copy, cut and paste
Here is how to cut-and-paste or copy-and-paste text using a visual selection in Vim. See Cut/copy and paste using visual selection for the main article.
Cut and paste:
- Position the cursor where you want to begin cutting.
- Press
v
to select characters, or uppercaseV
to select whole lines, orCtrl-v
to select rectangular blocks (useCtrl-q
ifCtrl-v
is mapped to paste). - Move the cursor to the end of what you want to cut.
- Press
d
to cut (ory
to copy). - Move to where you would like to paste.
- Press
P
to paste before the cursor, orp
to paste after.
y
instead of d
: d
stands for delete in Vim, which in other editors is usually called cuty
stands for yank in Vim, which in other editors is usually called copy
Copying and cutting in normal mode.
In normal mode, one can copy (yank) withy{motion}
, where {motion}
is a Vim motion. For example, yw
copies to the beginning of the next word. Other helpful yanking commands include: yy
orY
– yank the current line, including the newline character at the end of the liney$
– yank to the end of the current line (but don't yank the newline character); note that many people like to remapY
toy$
in line withC
andD
yiw
– yank the current word (excluding surrounding whitespace)yaw
– yank the current word (including leading or trailing whitespace)ytx
– yank from the current cursor position up to and before the character (tilx
)yfx
– yank from the current cursor position up to and including the character (findx
)
d{motion}
. To copy into a register, one can use
"{register}
immediately before one of the above commands to copy into the register {register}
. See pasting registers for more information on register syntax. Pasting in normal mode.
In normal mode, one can usep
to paste after the cursor, or P
to paste before the cursor. The variants
gp
and gP
move the cursor after the pasted text, instead of leaving the cursor stationary. To select a register from which to paste, one can use
"{register}p
to paste from the register {register}
. See pasting registers. 출처 - http://vim.wikia.com/wiki/Copy,_cut_and_paste
댓글
댓글 쓰기