Skip to main content
5 of 10
added 346 characters in body
Aaron Thoma
  • 514
  • 3
  • 12
  • You are probably best off hitting dat Tab key 5 times in your example.

  • More elegantly, you can have vim repeat the typing for you. But with its ≥7 keystrokes, this technique is only economical for a bigger number of repetitions or characters to be repeated:
    :%s/\s\(item.\)/\r     Ctrl-f 5a \t Ctrl-c     \1/g

  • At the cost of more verbose syntax, the technical answer to your question is using the \= syntax element for substituting by an expression [:help sub-replace-expression], in which you could then employ the repeat() function:
    :%s/\s\(item.\)/\= "\n" . repeat("\t",5) . submatch(1)/g   (Readability spaces not required.)

Unfortunately, vim does not provide syntactic sugar for repetition (\{5} or otherwise) in the replacement part of the :substitute command; almost none of the special regex syntax for pattern matching [:h pattern-overview] is available for the replacement: :h sub-replace-special

Aaron Thoma
  • 514
  • 3
  • 12