[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 vto select characters, or uppercaseVto select whole lines, orCtrl-vto select rectangular blocks (useCtrl-qifCtrl-vis mapped to paste).
- Move the cursor to the end of what you want to cut.
- Press dto cut (oryto copy).
- Move to where you would like to paste.
- Press Pto paste before the cursor, orpto paste after.
y instead of d: - dstands for delete in Vim, which in other editors is usually called cut
- ystands 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) with y{motion}, where {motion} is a Vim motion. For example, yw copies to the beginning of the next word. Other helpful yanking commands include: - yyor- Y– yank the current line, including the newline character at the end of the line
- y$– yank to the end of the current line (but don't yank the newline character); note that many people like to remap- Yto- y$in line with- Cand- D
- 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 (til- x)
- yfx– yank from the current cursor position up to and including the character (find- x)
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 use p 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
댓글
댓글 쓰기