Grimoire-
Command
.es

GNU+Linux command memo

Replace all occurrences of a text via vim (various forms)

Remplacer toutes les occurences d’un texte dans vim

:%s/foo/bar/g [1]

:%s\+/foo+/bar+g [2]

:%s/\Cfoo/bar/g [3]

:s/f\(o\)\{-}/ba\1/ [4]

:s/\(.*\)\_./\1/ [5]


1. % to treat all lines, foo is replaced by bar, g to treat all the occurrences in treated lines
2. If target text contains a slash (/) use any other delimiter letter, here it’s a + sign
3. \C for case sensitivity
4. \{-} non-greedy search ; \1 will be replaced by the first captured text in parenthesis, so the 1st 'o' found : folbaol
5. \_. matches every characters including new line ones ; so this concatenates 2 lines