* vim and regex cheatsheet ** Search and Replace See also [[https://vim.fandom.com/wiki/Search_and_replace][this fandom vim wiki page]]. *** Basic: - =:s/find/replace/=, only search in current line, and replace the first matched pattern *** Search in a certain range - Default: only in current line - In all lines: =:%s/f/r/= - In selected *line*: =:'<,'>s/f/r/= - In selected *characters*: =:`<,`>s/f/r/= *** Repeat - Default: only first matched in given range - match every one: =:s/f/r/g= *** Other - *Reuse* the matched pattern: 1. =:s/f/&/= =&= is the text that matches the search pattern. Example: =:s/[a-z]/&1/g=, add a =1= after each characte 2. =:s/\(a\)/\1/= =\(a\)= makes a backreference to =a=. =\1= is the first backreference, =\2= is the second backreference, =\0= is the text matched by the entire pattern.