vimtricks.wiki Concise Vim tricks, one at a time.

How do I replace every character in a visual block selection with the same character?

Answer

<C-v>{motion}r{char}

Explanation

In visual block mode, pressing r followed by any character replaces every character in the selected block with that character simultaneously. Unlike r in normal mode which replaces one character, and unlike visual-block I/A which insert text, r fills the entire selection uniformly.

How it works

  • <C-v> enters visual block (column) mode
  • A motion (l, j, $, etc.) defines the rectangular selection
  • r{char} replaces all characters in the block with {char}
  • The operation affects every row and column in the selected rectangle

Example

Creating a separator line between sections:

section one

section two

Position the cursor on the blank line, press <C-v>40lr- (select 40 columns right, replace with -):

section one
----------------------------------------
section two

Or select a multi-line block and fill it with spaces to erase it:

foo  bar
baz  qux

With cursor on first space of foo bar, <C-v>jllr (select 2 chars on 2 rows, replace with space) clears just those columns.

Tips

  • Use r<Space> to blank out a rectangular region without deleting the characters (preserves line length)
  • Combine with G or } to select to end of section, then fill with a character
  • Works with any character including special ones — r| creates pipe-character column dividers for ASCII tables

Next

How do I navigate quickfix entries, buffers, and conflicts with consistent bracket mappings?