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

How do I insert the same text multiple times without a macro or copy-paste?

Answer

80i-<Esc>

Explanation

Vim's insert commands accept a count prefix that repeats everything you type. When you press <Esc> to leave insert mode, Vim duplicates the inserted text the specified number of times. This is a fast way to create separator lines, repeated strings, or padding without reaching for macros or external tools.

How it works

  • 80 — the count prefix, specifying how many times to repeat
  • i — enter insert mode (also works with a, o, O, etc.)
  • - — type whatever characters you want repeated
  • <Esc> — exit insert mode; Vim repeats the inserted text 80 times total

Example

To create a horizontal rule of 40 equals signs:

Before:
  Section Title
  (cursor on line below)

Type: 40i=<Esc>

After:
  Section Title
  ========================================

This also works with multi-character insertions:

Type: 5iha <Esc>

Result: ha ha ha ha ha 

Tips

  • Works with a (append), o (open line below), and O (open line above) too — 3o<CR><Esc> inserts 3 blank lines
  • The count applies to the entire inserted text, so 3ifoo<Esc> produces foofoofoo
  • Combine with <C-v>I in visual block mode: the count applies to every line in the block

Next

How do I ignore whitespace changes when using Vim's diff mode?