How to exactly repeat the n matching pattern in the result line?
Example if I have the following text:
++ '[' -f /etc/bashrc ']' ++ . /etc/bashrc +++ '[' '[\ u@ \h \W]\$ ' ']' +++ '[' -z 'printf "\033]0;% s@ %s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' ']' +++ shopt -s checkwinsize +++ '[' '[\ u@ \h \W]\$ ' = '\s-\v\$ ' ']' +++ shopt -q login_shell +++ '[' 506 -gt 199 ']' ++++ id -gn
Now I want to replace each "+" with 3 spaces, but this can only happen at the beginning of the template. I would use :<range>s/^<pattern> :%s/+/ /g , but if the rest of the text was "+", I would just mess it up.
Question: How to compare each + at the beginning and repeat the same number of + found in the result line? Expected Result:
^ ++$ -> ^ $ ^ +++$ -> ^ $ ^ +$ -> ^ $
thanks
source share