Skip to content

Instantly share code, notes, and snippets.

@AirManH
Last active December 11, 2021 08:16
Show Gist options
  • Save AirManH/41a77f61eca53fef3d77dacf1683fd18 to your computer and use it in GitHub Desktop.
Save AirManH/41a77f61eca53fef3d77dacf1683fd18 to your computer and use it in GitHub Desktop.

Revisions

  1. AirManH revised this gist Dec 11, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions vim_regex_cheatsheet.org
    Original file line number Diff line number Diff line change
    @@ -36,3 +36,4 @@ See also [[https://vim.fandom.com/wiki/Search_and_replace][this fandom vim wiki
    =\1= is the first backreference,
    =\2= is the second backreference,
    =\0= is the text matched by the entire pattern.
    - =\<= and =\>= to match the beginning and the end of a word.
  2. AirManH revised this gist Dec 2, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim_regex_cheatsheet.org
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    * Cheatsheet about vim and regex
    * vim and regex cheatsheet

    ** Search and Replace

  3. AirManH revised this gist Dec 2, 2020. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions vim_regex_cheatsheet.org
    Original file line number Diff line number Diff line change
    @@ -23,11 +23,16 @@ See also [[https://vim.fandom.com/wiki/Search_and_replace][this fandom vim wiki
    *** Other

    - *Reuse* the matched pattern:

    1. =:s/f/&/=
    =&= is the text that matches the search pattern

    =&= 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=.

    =\(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.
  4. AirManH revised this gist Dec 2, 2020. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions vim_regex_cheatsheet.org
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,12 @@ See also [[https://vim.fandom.com/wiki/Search_and_replace][this fandom vim wiki

    *** Other

    - *Reuse* the matched pattern: =:s/f/&/=
    =&= is the text that matches the search pattern
    Example: =:s/[a-z]/&1/g=, add a =1= after each character
    - *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.
  5. AirManH revised this gist Nov 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim_regex_cheatsheet.org
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    * Cheatsheat about vim and regex
    * Cheatsheet about vim and regex

    ** Search and Replace

  6. AirManH created this gist Nov 20, 2020.
    27 changes: 27 additions & 0 deletions vim_regex_cheatsheet.org
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    * Cheatsheat about vim and regex

    ** 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: =:s/f/&/=
    =&= is the text that matches the search pattern
    Example: =:s/[a-z]/&1/g=, add a =1= after each character