Home > Software design >  Replace pattern in vim from first non space character
Replace pattern in vim from first non space character

Time:01-06

   Line1 starting after some initial space
    Line2 starting after few initial space
      Line3 starting after someother initial space

In Vim, i want to change some pattern not on all line, but per each line starting from non white-space character horizontally. Suppose on each line, right from L (first non space character in that line) i want to insert multiple space between each words.

CodePudding user response:

Use this command for adding another space:

:%s/\v\w \s/& /g

Explanation:

:s   command
%    entire file
/    delimiter
\v   regex magic mode
\w   at least one word character
\s   a whitespace character
&    replace match with itself plus a space
g    match multiple times per line
  • Related