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 12 remaining solutions by signing in and submitting your own entry
#13 Gareth Lloyd / IgnitionWeb - Score: 95 - 03/08/15 @ 16:30
:%s:\\\[:<center>\\(:g<CR>:%s:\\\]:\\)</center>:g<CR>:%s:\\(\s*\(\_.\{-}\)\s*\\):<math>\1</math>:g<CR>ZZ

0 comments

#14 Satoshi Kawasaki / hobbes3k - Score: 98 - 04/18/13 @ 22:19
:%s:\\(\s*:<math>:g<CR>:%s:\s*\\):</math>:g<CR>:%s:\\\[ :<center><math>:g<CR>:%s: \\]:</math></center>:g<CR>ZZ

0 comments

#15 Olivier Huber / xhub - Score: 118 - 04/05/13 @ 22:55
:%s/\\( */<math>/g<CR>l"my$:%s/ *\\)/<\/<C-R>m/g<CR>:s<BS>%s/\\\[ /center<Left><Left><Left><Left><Left><Left>c<BS><<Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right>C<BS><<BS>><<C-R>m<CR>:%s/ \\\]/<\/<C-R>m<\/center><CR>ZZ

0 comments

#16 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

16 active golfers, 35 entries

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

02/06/2013 at 11:40PM

82
#2 - Trevor Powell / DoomedBunnies

02/05/2013 at 05:57AM

82
#3 - sweet.mike.vg / SweetMikeVg

05/02/2013 at 05:35AM

86
#4 - lubyk / lubyk_

05/21/2013 at 07:08AM

87
#5 - Christopher Harrison / Xophmeister

01/31/2013 at 06:37PM

89
#6 - Carlos A HenrĂ­quez Q / lagunex

01/19/2015 at 02:48PM

90
#7 - mnx / mnxx

01/31/2013 at 01:10PM

90
#8 - matthieu le grix / mlegrix

05/01/2015 at 08:10AM

91
#9 - hiding / I_haveno_name

10/22/2013 at 01:12PM

92
#10 - Vim Golfer / vimgolfern00b

01/31/2013 at 01:01PM

92
#11 - Steve Tjoa / stevetjoa

02/01/2013 at 10:35PM

94
#12 - Zach Kelling / zeekay

02/25/2013 at 09:02AM

95
#13 - Gareth Lloyd / IgnitionWeb

03/08/2015 at 04:30PM

98
#14 - Satoshi Kawasaki / hobbes3k

04/18/2013 at 10:19PM

118
#15 - Olivier Huber / xhub

04/05/2013 at 10:55PM

144
#16 - David Wales / selawdivad

02/04/2013 at 05:41AM