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

How do I replace every character in a visual selection with a single character?

Answer

r{char} in visual mode

Explanation

In visual mode, pressing r followed by a character replaces every character in the selection with that single character. This is a fast way to redact text, create separator lines, or blank out a region.

How it works

  1. Select text in any visual mode (v, V, or <C-v>)
  2. Press r followed by the replacement character
  3. Every character in the selection becomes that character

Example: Create a separator line

Select a line of text with V, then press r-:

Before: This is a heading
After:  ------------------

Example: Redact sensitive data

Select text with v, then press r*:

Before: Password: secret123
After:  Password: *********

Block mode replacement

In <C-v> block mode, r replaces only the block column:

Before:    After <C-v>jjjr|:
foo bar    foo|bar
baz qux    baz|qux
hello hi   hel|o hi

Comparison with other replacements

r{char}    " Replace every char with the same char
c          " Delete selection and enter insert mode
s          " Same as c in visual mode
S          " Delete lines and enter insert mode

Tips

  • r<CR> replaces every character with a newline — use cautiously!
  • r (r followed by space) blanks out the selection while preserving line structure
  • In block mode, this is perfect for drawing table borders or box-drawing characters
  • Works with all three visual modes — characterwise, linewise, and blockwise

Next

How do I run the same command across all windows, buffers, or tabs?