Tip #386: Cut/copy and paste using visual selection
tip karma |
Rating 525/190, Viewed by 8673
|
created: |
|
December 9, 2002 18:49 |
|
complexity: |
|
basic |
author: |
|
rainbrot |
|
as of Vim: |
|
5.7 |
Visual selection, although common in applications today, is a key feature that differentiates vim from traditional vi.
To cut (or copy) and paste using visual selection:
1. Position the cursor at the beginning of the text you want to cut/copy.
2. Press v to begin character-based visual selection (or upper case V to select whole lines, or Ctrl-V for a vertical block).
3. Move the cursor to the end of the text to be cut/copied. (While selecting text, you can perform searches and other advanced movement, a feature that sets vim apart from most other editors.)
4. Press d (as in "delete") to cut, or y (as in "yank", which I imagine meaning "yank so hard and fast that it leaves a copy behind") to copy.
5. Move the cursor to the desired paste location.
6. Press p to paste after the cursor, or P to paste before.
In gvim, visual marking (steps 1-3) can be replaced by selecting text using a mouse or similar pointing device, although I strongly prefer to navigate using the keyboard.
Bonus tip: To replace the selected text with new text (to be entered by you), press 'c' instead of 'd' or 'p' on step 4. This deletes the selection and leaves you in insert mode. Then, instead of (or prior to) steps 5-6, type your replacement text.
<<some java & vim tips |
A way to quickly prefix a char(or chars) to a parameter list, via :s >>
Additional Notes
|