Mastering Column Editing with Vim Visual Block Mode
Visual Block mode lets you select rectangular text regions in Vim, enabling bulk insert, delete, and move operations across many lines at once.
26 Sept 2025, 01:19 UTC

The Problem: Repetitive Multi-Line Edits
You have a list of 50 variables that all need a prefix, a configuration file where you need to comment out a specific block of lines, or a CSV-like text file where you need to delete the first three characters of every row. Doing this line-by-line is tedious and prone to manual error.
The solution is Visual Block Mode. Unlike standard Visual mode, which selects text as a continuous stream, Visual Block mode treats the text as a two-dimensional grid. This allows you to manipulate vertical columns of text independently of line length.
Activating and Navigating the Block
To enter Visual Block mode, press Ctrl-v in Normal mode. You will see -- VISUAL BLOCK -- appear in the status line.
Once active, use the standard movement keys (h, j, k, l) to expand your selection. Because you are selecting a rectangle, Vim tracks the start and end columns across all spanned lines. If you move the cursor to the right, every line in the selection expands by one character.
Performing Bulk Insertions and Deletions
The real power of block mode comes after the selection is made. Most users expect to type immediately, but Vim requires a specific command to apply the change.
Inserting Text at the Start
- Enter Visual Block mode (
Ctrl-v) and select the column where the text should start. - Press
Shift-I(uppercase I). The cursor will jump to the first line. - Type your text. Note: the text will only appear on the first line while you type.
- Press
Esc. After a brief pause, Vim applies the text to every line.
Appending Text at the End
If you need to add text to the end of the selection, use Shift-A (uppercase A). Similar to the insert command, the change is only committed once you hit Esc.
Deleting Rectangular Regions
To remove a specific column of data without affecting the rest of the line, select the block and press d. This deletes the rectangular area and shifts the remaining text left.
Worked Example: Commenting Out Code
Imagine you have the following Python code and want to comment out lines 2 through 4:
def main():
print("1")
print("2")
print("3")
return
Execution Steps:
- Move cursor to the start of line 2.
- Press
Ctrl-v. - Press
jtwice to highlight the first character of lines 2, 3, and 4. - Press
Shift-I. - Type
# - Press
Esc.
Expected Result:
def main():
# print("1")
# print("2")
# print("3")
return
Trade-offs and Limitations
Visual Block mode is highly efficient but has a few behavioral quirks to keep in mind:
- Undo Granularity: When you perform a block insertion or deletion, Vim treats the entire operation as a single change. If you make a typo during a 100-line block insert, pressing
uwill undo the entire operation. - Terminal Rendering: Some terminal emulators or specific SSH configurations may fail to render the block-selection highlighting correctly. If the highlight looks like a standard line selection, verify your
TERMvariable or consult:help visualblock. - Line Lengths: If your block selection extends beyond the end of a line, Vim handles the empty space, but appending text (
Shift-A) will place the text at the actual end of each line, which may not align visually.
Actionable Closing
Next time you face a repetitive column edit, open the file in Vim, press Ctrl-v, select the rectangle, and apply the change with Shift-I, Shift-A, or d. Verify the result visually, then run :w to save. For deeper reference, run :help VisualBlock inside Vim.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.