Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 510a052c6db41b0002000028

LaTeX to XML Math Delimiters

Vim is amazing when used to edit MediaWiki text, but typing "<math> . . . </math>" can be tiresome and frustrating if formulas are used often. LaTeX delimiters are so concise and even come in two flavors: "\( . . . \)" for inline math and "\[ . . . \]" for centered formulas. The goal is to perform the following conversions: "\( . . . \)" becomes "<math>. . .</math>" "\[ . . . \]" becomes "<center><math>. . .</math></center>"

Start file
Given two vectors \(\vec{x}\) and \(\vec{y}\) in \( \mathbb{R}^n \),
their
'''dot product''' or '''inner product''' is defined as the following:

\[ \sum_{i=0}^{n} x_i \, y_i \]

----

Integration by parts is another way of writing the product rule of differentiation.
For two functions \(f(x)\) and \(g(x)\), the following are equivalent:

\[ \begin{align}
\frac{\mathrm{d}}{\mathrm{d}x} \left( f(x) \, g(x) \right) &= f'(x) \, g(x) + f(x) \, g'(x) \\
\int f(x) \, g'(x) \, \mathrm{d}x &= f(x) \, g(x) - \int f'(x) \, g(x) \, \mathrm{d}x
\end{align} \]

----

Matrix multiplication is not commutative

\(
\begin{align}
\begin{bmatrix}
    a_
{11} & a_{12} \\
    a_
{21} & a_{22}
\end{bmatrix} \,
\begin{bmatrix}
    b_
{11} & b_{12} \\
    b_
{21} & b_{22}
\end{bmatrix} &\ne
\begin{bmatrix}
    b_
{11} & b_{12} \\
    b_
{21} & b_{22}
\end{bmatrix} \,
\begin{bmatrix}
    a_
{11} & a_{12} \\
    a_
{21} & a_{22}
\end{bmatrix} \\

\begin{bmatrix}
    a_
{11} \, b_{11} + a_{12} \, b_{21} & a_{11} \, b_{12} + a_{12} \, b_{22} \\
    a_
{21} \, b_{11} + a_{22} \, b_{21} & a_{21} \, b_{12} + a_{22} \, b_{22}
\end{bmatrix} &\ne
\begin{bmatrix}
    a_
{11} \, b_{11} + a_{21} \, b_{12} & a_{12} \, b_{11} + a_{22} \, b_{12} \\
    a_
{11} \, b_{21} + a_{21} \, b_{22} & a_{12} \, b_{21} + a_{22} \, b_{22}
\end{bmatrix}
\begin{align}
\)

''Quod erat demonstrandum''.
End file
Given two vectors <math>\vec{x}</math> and <math>\vec{y}</math> in <math>\mathbb{R}^n</math>,
their '''dot product''' or '''inner product''' is defined as the following:

<center><math>\sum_{i=0}^{n} x_i \, y_i</
math></center>

----

Integration by parts is another way of writing the product rule of differentiation.
For two functions <math>f(x)</math> and <math>g(x)</math>, the following are equivalent:

<center><math>\begin{align}
\frac{\mathrm{d}}{\mathrm{d}x} \left( f(x) \, g(x) \right) &= f'(x) \, g(x) + f(x) \, g'(x) \\
\int f(x) \, g'(x) \, \mathrm{d}x &= f(x) \, g(x) - \int f'(x) \, g(x) \, \mathrm{d}x
\end{align}</math></center>

----

Matrix multiplication is not commutative

<math>
\begin{align}
\begin{bmatrix}
    a_
{11} & a_{12} \\
    a_
{21} & a_{22}
\end{bmatrix} \,
\begin{bmatrix}
    b_
{11} & b_{12} \\
    b_
{21} & b_{22}
\end{bmatrix} &\ne
\begin{bmatrix}
    b_
{11} & b_{12} \\
    b_
{21} & b_{22}
\end{bmatrix} \,
\begin{bmatrix}
    a_
{11} & a_{12} \\
    a_
{21} & a_{22}
\end{bmatrix} \\

\begin{bmatrix}
    a_
{11} \, b_{11} + a_{12} \, b_{21} & a_{11} \, b_{12} + a_{12} \, b_{22} \\
    a_
{21} \, b_{11} + a_{22} \, b_{21} & a_{21} \, b_{12} + a_{22} \, b_{22}
\end{bmatrix} &\ne
\begin{bmatrix}
    a_
{11} \, b_{11} + a_{21} \, b_{12} & a_{12} \, b_{11} + a_{22} \, b_{12} \\
    a_
{11} \, b_{21} + a_{21} \, b_{22} & a_{12} \, b_{21} + a_{22} \, b_{22}
\end{bmatrix}
\begin{align}
</math>

''Quod erat demonstrandum''.

View Diff

1c1
< Given two vectors \(\vec{x}\) and \(\vec{y}\) in \( \mathbb{R}^n \),
---
> Given two vectors <math>\vec{x}</math> and <math>\vec{y}</math> in <math>\mathbb{R}^n</math>,
4c4
< \[ \sum_{i=0}^{n} x_i \, y_i \]
---
> <center><math>\sum_{i=0}^{n} x_i \, y_i</
math></center>
9c9
< For two functions \(f(x)\) and \(g(x)\), the following are equivalent:
---
> For two functions <math>f(x)</math> and <math>g(x)</math>, the following are equivalent:
11c11
< \[ \begin{align}
---
> <center><math>\begin{align}
14c14
< \end{align} \]
---
> \end{align}</math></center>
20c20
< \(
---
> <math>
48c48
< \)
---
> </math>

Solutions

The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!

Check out these helpful resources to improve your Vim skills... Game on.

Unlock 19 remaining solutions by signing in and submitting your own entry
#20 David Wales / @selawdivad - Score: 144 - 02/04/13 @ 05:41
:%s/\\(/<math>/g<CR>:%s/\\)/<\/math>/g<CR>:%s/\\\[/<e<BS>center><math>/g<CR>:%s/\\\]/<\/math><\/center>/g<CR>:%s/<math> /<math>/g<CR>:%s/ <\/math>/<\/math>/g<CR>:wq<CR>

0 comments


Created by: @komputerwiz

20 active golfers, 48 entries

Leaderboard (lowest score wins):
63
#1 - Urtica dioica / @udioica

02/06/2013 at 11:40PM

63
#2 - Peppa Pig / @PeppaPigSg

06/29/2024 at 08:47AM

75
#3 - Miłosz Łakomy / @foobar01123

12/28/2019 at 02:12PM

82
#4 - Trevor Powell / @DoomedBunnies

02/05/2013 at 05:57AM

82
#5 - sweet.mike.vg / @SweetMikeVg

05/02/2013 at 05:35AM

86
#6 - lubyk / @lubyk_

05/21/2013 at 07:08AM

87
#7 - Christopher Harrison / @Xophmeister

01/31/2013 at 06:37PM

89
#8 - Carlos A Henríquez Q / @lagunex

01/19/2015 at 02:48PM

90
#9 - mnx / @mnxx

01/31/2013 at 01:10PM

90
#10 - matthieu le grix / @mlegrix

05/01/2015 at 08:10AM

91
#11 - hiding / @I_haveno_name

10/22/2013 at 01:12PM

92
#12 - Vim Golfer / @vimgolfern00b

01/31/2013 at 01:01PM

92
#13 - Steve Tjoa / @stevetjoa

02/01/2013 at 10:35PM

92
#14 - nickGPT / @nickandbro

08/28/2024 at 06:48PM

94
#15 - Zach Kelling / @zeekay

02/25/2013 at 09:02AM

95
#16 - Gareth Lloyd / @IgnitionWeb

03/08/2015 at 04:30PM

98
#17 - Satoshi Kawasaki / @hobbes3k

04/18/2013 at 10:19PM

99
#18 - Łukasz Kadłubowski / @LAKadlubowski

08/22/2020 at 02:05AM

118
#19 - Olivier Huber / @xhub

04/05/2013 at 10:55PM

144
#20 - David Wales / @selawdivad

02/04/2013 at 05:41AM