Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - Visual Block : Delete rather than insert

Tags:

vim

vi

macvim

I often use visual block then inserting on multiple lines when for example commenting out a lot of code. This is great for inserting text in the same position on multiple lines but I can't figure out how to delete this text later using visual block mode, Backspace, Del and d all don't work. I am using MacVim.

like image 811
henry.oswald Avatar asked Jul 04 '11 10:07

henry.oswald


People also ask

How do I delete a visual block in Vim?

Step 1: Move your cursor to the top line of the block of text/code to remove. Step 2: Press V (Shift + v) to enter the Visual mode in Vim/Vi. Step 3: Now move your cursor down to the bottom of the block of text/code to remove. Step 4: Press d to delete the block selected.

How do I use visual block mode in Vim?

To enable the Visual block mode in Vim, you have to try out the “Ctrl+V” command within the normal mode. You can see that the new. txt file has been opened in the Visual Block mode. The file contains only two lines that will be edited further.

How do I delete a section in vi?

Press 'v' to enter a select mode, and use arrow keys to move that around. To delete, press x. To select lines at a time, press shift+v. To select blocks, try ctrl+v.


1 Answers

You're looking for x:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh

Then visual-block-select, x:

root:/root:/bin/bash
daeaemon:/usr/sbin:/bin/sh
bin/bin:/bin/sh
sys/dev:/bin/sh

I use this frequently, for exactly the same reason -- commenting and uncommenting large blocks of code.

like image 121
sarnold Avatar answered Sep 28 '22 12:09

sarnold