Skip to main content
deleted 19 characters in body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
  • You are probably best off just hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r    TabTabTabTabTab    \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that typing for you. But with its ≥7 keystrokes and a bit of thinking effort, 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

  • The most literal and technical answer to your question is – at the cost of even much more verbose syntax – 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


(PS: TabTabTabTabTabTabTabTabTabTabTabTabTabTabTab)
  • You are probably best off just hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r    TabTabTabTabTab    \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that typing for you. But with its ≥7 keystrokes and a bit of thinking effort, 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

  • The most literal and technical answer to your question is – at the cost of even much more verbose syntax – 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


(PS: TabTabTabTabTabTabTabTabTabTabTabTabTabTabTab)
  • You are probably best off just hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r    TabTabTabTabTab    \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that typing for you. But with its ≥7 keystrokes and a bit of thinking effort, 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

  • The most literal and technical answer to your question is – at the cost of even much more verbose syntax – using \= 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


(PS: TabTabTabTabTabTabTabTabTabTabTabTabTabTabTab)
added 17 characters in body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
  • You are probably best off just hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r    TabTabTabTabTab    \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that typing for you. But with its ≥7 keystrokes and a bit of thinking effort, 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

  • The most literal and technical answer to your question is – at the cost of even much more verbose syntax – 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


(PS: TabTabTabTabTabTabTabTabTabTabTabTabTabTabTab)
  • You are probably best off just hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r    TabTabTabTabTab    \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that typing for you. But with its ≥7 keystrokes and a bit of thinking effort, 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

  • The technical answer to your question is – at the cost of even much more verbose syntax – 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


(PS: TabTabTabTabTabTabTabTabTabTabTabTabTabTabTab)
  • You are probably best off just hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r    TabTabTabTabTab    \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that typing for you. But with its ≥7 keystrokes and a bit of thinking effort, 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

  • The most literal and technical answer to your question is – at the cost of even much more verbose syntax – 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


(PS: TabTabTabTabTabTabTabTabTabTabTabTabTabTabTab)
added 167 characters in body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
  • You are probably best off just hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r            TabTabTabTabTab            \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that typing for you. But with its ≥7 keystrokes and a bit of thinking effort, 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

  • The technical answer to your question is – at the cost of even much more verbose syntax – 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


(PS: TabTabTabTabTabTabTabTabTabTabTabTabTabTabTab)
  • You are probably best off hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r       TabTabTabTabTab       \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that 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

  • The technical answer to your question is – at the cost of even much more verbose syntax – 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


(PS: TabTabTabTabTab)
  • You are probably best off just hitting dat Tab key 5 times in your example:
    :%s/\s\(item.\)/\r     TabTabTabTabTab     \1/g
    (The tabs display as ^I in the Command-line.)

  • More elegantly, you can have vim repeat that typing for you. But with its ≥7 keystrokes and a bit of thinking effort, 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

  • The technical answer to your question is – at the cost of even much more verbose syntax – 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


(PS: TabTabTabTabTabTabTabTabTabTabTabTabTabTabTab)
added 285 characters in body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
Loading
added 346 characters in body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
Loading
added 346 characters in body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
Loading
edited body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
Loading
added 438 characters in body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
Loading
added 438 characters in body
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
Loading
Source Link
Aaron Thoma
  • 514
  • 3
  • 12
Loading