Skip to content

Instantly share code, notes, and snippets.

@XiaochenCui
Last active February 20, 2019 02:34
Show Gist options
  • Save XiaochenCui/88180bc7864679752537a37c44037641 to your computer and use it in GitHub Desktop.
Save XiaochenCui/88180bc7864679752537a37c44037641 to your computer and use it in GitHub Desktop.

vim 中需要转义才能生效的 meta characters

  • ()
  • +

look around

meaning perl vim remark
Matches the preceding atom with zero width (?=pattern) @=
Matches with zero width if the preceding atom does NOT match at the current position. (?!pattern) @!
Matches with zero width if the preceding atom matches just before what follows. (?<=pattern) @<= Vim allows non-fixed-width patterns
Matches with zero width if the preceding atom does NOT match just before what follows. Thus this matches if there is no position in the current or previous line where the atom matches such that it ends just before what follows. (?<!pattern) @<! Vim allows non-fixed-width patterns.
Matches the preceding atom like matching a whole pattern (?>pattern) @>

Vim has \zs and \ze to start and end matching, so you usually don't have to deal with normal regex lookaround.

e.g: :%s/^rs\d\{1,12}\zs-/\t/g

Meta character

character name find substitude
new line \n \r

reference

Vim documentation: pattern

Non greedy

Instead of .* use .\{-}.

%s/style=".\{-}"//g

Also, see :help non-greedy

See: https://stackoverflow.com/questions/1305853/how-can-i-make-my-match-non-greedy-in-vim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment