0

What I want to do

I want to select a block of text in Vim, delete it, and replace the selected block with spaces.

Example

Suppose I have the following text:

Lorem ipsum dolor sit amet, consectetur 
adipiscing elit. Fusce facilisis arcu 
porta leo efficitur malesuada. In eget 
turpis erat. Sed ipsum metus, malesuada 
bibendum ipsum vel, molestie convallis nisi. 

Suppose I wish to remove the block of text indicated by the hyphens:

Lorem ipsum dolor sit amet, consectetur 
adipiscing el------sce facilisis arcu 
porta leo eff------ malesuada. In eget 
turpis erat. ------sum metus, malesuada 
bibendum ipsum vel, molestie convallis nisi. 

How could I turn the original paragraph into the following?

Lorem ipsum dolor sit amet, consectetur 
adipiscing el      sce facilisis arcu 
porta leo eff       malesuada. In eget 
turpis erat.       sum metus, malesuada 
bibendum ipsum vel, molestie convallis nisi. 

My Understanding

I understand how to select a block of text in Vim: I press Ctrlv to enable Visual block mode, then use arrow keys to outline/select the block.

I can also delete a selected block by pressing d.

However, I don't know how to replace the text with spaces quickly (without manually inserting each in insert mode, or manually adding them in a way similar to this), or whether there's a better way to do this.

4

You can replace every character of your selection with one of your choosing by using r, the replace command.

In your case, in visual mode, type

r<space>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.