Cut/copy and paste using visual selection in vim

Modern day vim includes many features, one of the most distinguished can be termed as visual selection. We can use this feature to copy/cut and paste text.

In order to copy/cut and paste using visual selection, you need to:

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).
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”) to copy.
5. Move the cursor to the desired paste location.
6. Press p to paste after the cursor, or P to paste before.

Additional Feature: In case you want to delete or replace an entire selection, you can select the text data as per steps 1 to 3. Then instead of pressing d or y as provided in step 4, press c which will delete the current selection and leave you in insert mode, where you can insert the text you want.

No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.