Jump to content

Nvim Regex by @Rongzhou

From Wikibase
Created page with "== Markdown /md == Text > list <syntaxhighlight lang="text" copy> :%s#^#- # </syntaxhighlight>"
 
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Generic ==
Newline to space
<syntaxhighlight lang="text" copy>
:%s#\n# #g
</syntaxhighlight>
Truncate line at arbitrary char count
<syntaxhighlight lang="text" copy>
:s#.\{}\zs.*##
</syntaxhighlight>
where the number of char is to be written between <code>{}</code>
== Markdown /md  ==
== Markdown /md  ==


Text > list
Text <> list


<syntaxhighlight lang="text" copy>
<syntaxhighlight lang="text" copy>
:%s#^#- #
:%s#^#- #
</syntaxhighlight>
<syntaxhighlight lang="text" copy>
:%s#^- ##
</syntaxhighlight>
== Katex ==
\[ \( <> $$ $ delimiter change:
<syntaxhighlight lang="text" copy>
:%s/\(\\(\(.\{-}\)\\)\)\|\(\\\[\(\_.\{-}\)\\\]\)/\=submatch(1) != '' ? '$'.submatch(2).'$' : '$$'.submatch(4).'$$'/g
</syntaxhighlight>
<syntaxhighlight lang="text" copy>
:%s/\$\$\(\_.\{-}\)\$\$\|\$\(.\{-}\)\$/\=submatch(0) =~ '^\$\$' ? '\['.submatch(1).'\]' : '\('.submatch(2).'\)'/g
</syntaxhighlight>
<code>vmatrix</code> > <code>\det pmatrix</code>
<syntaxhighlight lang="text" copy>
:%s#\\\(begin\|end\){vmatrix}#\=submatch(1)=='begin'?'\det\begin{pmatrix}':'\end{pmatrix}'#g
</syntaxhighlight>
Stripping extra labels, tags
<syntaxhighlight lang=bash copy>
:%s#\v\\(label|tag)\*?\s*\{[^}]*\}|\\(nonumber|notag)\s*##g
</syntaxhighlight>
== Wikitext ==
<code><nowiki><syntaxhighlight ... inline></syntaxhighlight></nowiki></code> > <code><nowiki><code></code></nowiki></code>:
<syntaxhighlight lang="text" copy>
:%s#<syntaxhighlight[^>]*inline>\(.\{-}\)<\/syntaxhighlight>#<code>\1</code>#g
</syntaxhighlight>
ordered list (<code>#</code>) > to unordered list (<code>*</code>):
<syntaxhighlight lang="text" copy>
:%s#\##*#g
</syntaxhighlight>
literal digit list > to unordered list (<code>*</code>):
<syntaxhighlight lang="text" copy>
:%s#^\d.#*#
</syntaxhighlight>
<code>[[File:{filename}]]</code> > <code>[[File:{filename}|400px|center]]</code>
<syntaxhighlight lang="text" copy>
:%s/\[\[File:\([^]]*\)\]\]/[[File:\1\|400px\|center]]/g
</syntaxhighlight>
Plain Python code snippet > Pyodide
<syntaxhighlight lang="text" copy>
:%s#<syntaxhighlight lang="python" copy>#<syntaxhighlight lang="python" class="pyodide" copy>#g
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 10:01, 20 November 2026

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