Jump to content

Nvim Regex by @Rongzhou

From Wikibase
Revision as of 10:01, 20 November 2026 by Rongzhou (talk | contribs) (→Wikitext)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Generic

Newline to space

:%s#\n# #g

Truncate line at arbitrary char count

:s#.\{}\zs.*##

where the number of char is to be written between {}

Markdown /md

Text <> list

:%s#^#- #
:%s#^- ##

Katex

\[ \( <> $$ $ delimiter change:

:%s/\(\\(\(.\{-}\)\\)\)\|\(\\\[\(\_.\{-}\)\\\]\)/\=submatch(1) != '' ? '$'.submatch(2).'$' : '$$'.submatch(4).'$$'/g
:%s/\$\$\(\_.\{-}\)\$\$\|\$\(.\{-}\)\$/\=submatch(0) =~ '^\$\$' ? '\['.submatch(1).'\]' : '\('.submatch(2).'\)'/g

vmatrix > \det pmatrix

:%s#\\\(begin\|end\){vmatrix}#\=submatch(1)=='begin'?'\det\begin{pmatrix}':'\end{pmatrix}'#g

Stripping extra labels, tags

:%s#\v\\(label|tag)\*?\s*\{[^}]*\}|\\(nonumber|notag)\s*##g

Wikitext

<syntaxhighlight ... inline></syntaxhighlight> > <code></code>:

:%s#<syntaxhighlight[^>]*inline>\(.\{-}\)<\/syntaxhighlight>#<code>\1</code>#g

ordered list (#) > to unordered list (*):

:%s#\##*#g

literal digit list > to unordered list (*):

:%s#^\d.#*#

[[File:{filename}]] > [[File:{filename}|400px|center]]

:%s/\[\[File:\([^]]*\)\]\]/[[File:\1\|400px\|center]]/g

Plain Python code snippet > Pyodide

:%s#<syntaxhighlight lang="python" copy>#<syntaxhighlight lang="python" class="pyodide" copy>#g