Take the 2-minute tour ×

Is there a way of repeating a character while in Vim's insert mode? For example, say I would like to insert 80 dashes, in something like emacs I would type:

Ctrl+U 8 0 -

The only way I know how to do it in VIM is to exit normal mode for the repeat argument, then go back into insert mode to type the dash, then exit to insert the actual dashes, AND then go back into insert mode to carry on typing. The sequence is a really long:

<ESC> 8 0 a - <ESC> a

It would be nice not to switch in and out of modes.


share|improve this question

6 Answers 6

up vote 6 down vote accepted

Slightly different version of Eelvex's solution:

function! Repeat()
    let times = input("Count: ")
    let char  = input("Char: ")
    exe ":normal a" . repeat(char, times)

imap <C-u> <C-o>:call Repeat()<cr>
share|improve this answer

If you are OK with leaving INSERT mode only once (at the end), this sequence works <C-o>8ia<Esc>.

  • <C-o> is used to issue normal commands without leaving INSERT mode.
  • 8 the repetition.
  • i to insert.
  • a the letter you want to type.
  • <Esc> to leave INSERT mode

Another one without EVER leaving INSERT mode: <C-o>:norm 8ia<CR>.

share|improve this answer
Your answer and the OP's answer are the only ones that work for me. –  twblamer Sep 23 '11 at 21:26
"<C-o> is used to issue normal commands without leaving INSERT mode" wins my can't-believe-I-never-knew-about-this award! –  Stabledog Mar 20 at 13:30


E.g. Esc4iJEsc will output JJJJ.

share|improve this answer
Unfortunately that doesn't work on my vim unless you escape back to normal mode. –  Cthutu Feb 20 '11 at 0:56
Yes you're right -I was starting from normal mode –  Martin Beckett Feb 20 '11 at 16:33
But this is the best answer in the "vim way". –  Drasill Feb 21 '11 at 13:09
it's missing one ESC at the end for it to work –  Bryan Feb 1 '12 at 21:43
I always find myself going back to insert mode when I press the i, so then I will only insert CHARACTER. How do I work this? –  Wolter Hellmund Mar 3 '13 at 16:50
<the number of times you want to repeat>
<the char you want to repeat> 

for example: <ESC>12ia<ESC> will insert 12 a's.
share|improve this answer

There are many other ways but AFAIK the one you describe is the shortest one. In vim you are mostly supposed to spend your time in command mode, so that would be just 3 keystrokes + the number of repeats (80i-).

However, if you find that you very often use this repeat thing, you can make yourself a function or macro to that end; maybe something like:

:function Repeat(char)
: let counter = input("How many times?: ")
: call feedkeys("i")
: call feedkeys(repeat(a:char,counter))
:imap <C-U> <ESC>h"ryl :call Repeat(@r)<CR>
share|improve this answer
It didn't work for me but thanks for the answer. My knowledge of the vim programming language is not good enough to figure out why. –  Cthutu Feb 20 '11 at 1:06

In addition to writing function that will repeat text multiple times, you could use <C-x><C-l>: if you already have line that contains 80 dashes, writing a few dashes at the start of new line and then pressing <C-x><C-l> will complete lines which start with these few dashes which will be likely that line with 80 dashes. I used to write horizontal lines (78 dashes) in help files in a such way.

share|improve this answer

Your Answer


