Block Editing in Vim

I have been lax in adding to this site for some time, but I am hoping to rectify that in the coming weeks. Luckily I have a backlog of things that I have done that will make up the next few entries. For instance, I have come to love Visual Block editing in vim.

When I’m debugging code it is just magic to be able to comment out a block at a time to test various aspects of a program. For a long time now I’ve been referring to a copy-and-pasted section of the vim manual in a loose file, because I don’t use the features so often that it sticks in my mind yet. To avoid collecting these loose files, I’ll put the relevant section here, so I can find it.

Visual-block Insert *v_b_I* With a blockwise selection, I{string} will insert {string} at the start of block in every line of the block, provided that the line extends into the block. Thus lines that are short will remain unmodified. TABs are split to retain visual columns.

Visual-block Append*v_b_A* With a blockwise
selection, A{string} will append {string} to the end of block on every line of the
block. There is some differing behavior where the block RHS is not straight, due to different line lengths:

1. Block was created with $ In this case the string is appended to the end of each line. 2. Block was created with {move-around} In this case the string is appended to the end of the block on each line, and whitespace is inserted to pad to the end-of-block column.

Note: “I” and “A” behave differently for lines that don’t extend into the selected block. This was done intentionally, so that you can do it the way you want.