Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Delete (desired text), delete (undesired text), and paste (desired text) in Vim

Tags:

vim

paste

I don't know if its a retarded problem but it's a funny dilemma. When I want to delete text that I want to place somewhere else, but that place has other bunch of text that I don't want, I would delete that text, but in the process I copy a new clipboard so the previously deleted text disappear.

Any suggestions to solve this?

like image 331
alexchenco Avatar asked Feb 16 '10 16:02

alexchenco


People also ask

How do you select and delete text in Vim?

Deleting a single line in Vim editor: First, bring your cursor to the line you want to delete. Press the “Esc” key to change the mode. Now type, “:d”, and press “Enter” to delete the line or quickly press “dd”.

How do I delete specific words in Vi?

To delete a word, position the cursor at the beginning of the word and type dw . The word and the space it occupied are removed. To delete part of a word, position the cursor on the word to the right of the part to be saved. Type dw to delete the rest of the word.

How do I delete content in Vim?

Delete a Range of LinesUse Esc to switch to normal mode in Vim. Once you press Enter, the specified lines are removed, as in the image below.

Can you highlight and delete in Vim?

Once the text is highlighted, press the d key to delete the text. If you deleted too much or not enough, press u to undo and start again. Move your cursor to the new location and press p to paste the text.


1 Answers

A few possible solutions:

Delete the undesired text first :)

or

When deleting the desired text store it in a register other than the default register e.g. to delete the desired text to the end of the current line and store it in register b:

"bd$

Then delete your undesired text.

Then paste the contents of register b:

"bp

or

Delete the undesired text to the black hole register as suggested in the answer linked to by Yarek T using:

"_d
like image 150
mikej Avatar answered Oct 02 '22 02:10

mikej