Vim Replace 2 spaces indent with 4 spaces

To replace all 2 space indentations, use the following command:

:%s/\n \{2\}\([^ ]\)/\r    \1/gc


: - command
%s - entire selection
/ - separator
\n \{2\}\([^ ]\) - search for a newline and 2 spaces followed by a character that is not a space
/ - separator
\r    \1 - replace with a newline and the matching group that is a not a space
/ - separator
g - global replace
c - confirm replacements (type y (yes) to confirm replacements)
If you liked this posting, please feel free to leave me a comment below.
View this page on GitHub.
Posted .


Leave a Reply