[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:
  1. Position the cursor where you want to begin cutting.
  2. Press v to select characters, or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks (use Ctrl-q if Ctrl-v is mapped to paste).
  3. Move the cursor to the end of what you want to cut.
  4. Press d to cut (or y to copy).
  5. Move to where you would like to paste.
  6. Press P to paste before the cursor, or p to paste after.
Copy and paste is performed with the same steps except for step 4 where you would press y instead of d:
  • d stands for delete in Vim, which in other editors is usually called cut
  • y 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) 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:
  • yy or 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 Y to y$ in line with C and 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)
Cutting can be done using 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

댓글

이 블로그의 인기 게시물

[Linux, AIX] 사용자 계정 생성 및 설정

[AIX] rpm 설치와 rpm 으로 패키지 설치 및 삭제

Ubuntu 에서 Fortran 시작하기