Embarrassed by capital I'm in vim

I follow these steps when I want to comment on a block of code:

1) Enter Blockwise Visual mode by hitting CTRL-V. 2) Mark the block you wish to comment. 3) Hit I (capital I) and enter your comment string at the beginning of the line. (// for C++) 4) Hit ESC and all lines selected will have 

However, I'm not quite sure what I do. And why does ESC trigger an insert on every line of the block.

+8
vim vi
source share
3 answers

In block selection mode, I VIM switches to insert mode with the cursor up to the first character in the first line of the block.

All the characters that you type in this first line will be inserted before all lines in the selection, right before the selected block.

You can do the same with A , except that you add it after the block.

+12
source share

from :help I

 Insert text before the first non-blank in the line [count] times. When the 'H' flag is present in 'cpoptions' and the line only contains blanks, insert start just before the last blank. 

inserts in front of each selected line

I can only assume that "ESC" is used because it is not a printed character like ENTER.

+4
source share

When using I , A or c in visual mode, you actually use the so-called blockwise-operator. Yes, they behave very differently in visual mode than when pasted.

For more information, help :blockwise-operators

0
source share

Source: https://habr.com/ru/post/650502/


All Articles