Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeating characters in VIM insert mode

Tags:

vim

People also ask

How do I get my cursor to move in insert mode?

Command mode is used for cursor movement, editing, retrieving and saving files, etc. If you want to type in text, you need to be in Insert mode. To move from Command mode to Insert mode, press "i" (no quotes). To move from Insert mode to Command mode, press "ESC" (the Escape key).

What is the difference between insert and append in Vim?

The append command will put the cursor after the current position, while the insert command will put the cursor before it. Using the append command is like moving the cursor one character to the right, and using the insert command.


If you are OK with leaving INSERT mode only once (at the end), this sequence works:

Ctrl+o 80i- Esc

  • Ctrl+o is used to issue normal commands without leaving INSERT mode,
  • 80 the repetition,
  • i to insert,
  • - the character you want to insert,
  • Esc to leave INSERT mode.

Another one without EVER leaving INSERT mode:

Ctrl+o :norm 8ia Return


Escnic Esc Esc.

E.g. Esc4iJEsc Esc will output JJJJ.


Through single repeat:

Insert mode
-
Esc
80.

Will output: 80 -

---------------------------------------------------------------------------------

More details about single repeat: :help .


<ESC> 
<the number of times you want to repeat>
i 
<the char you want to repeat> 
<ESC>

for example: <ESC>12ia<ESC> will insert 12 a's.

Slightly different version of Eelvex's solution:

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

imap <C-u> <C-o>:call Repeat()<cr>