At work, we use Mediawiki to document stuff. It is nice to have up to date wiki articles, but the process of writing them can be painful sometimes. When it comes to editing text, I want to have a nice editing environment and not the crappy online text editors provided by all kinds of CMS and Wikis. Simply put, I want to have the same editing environment as for every other document I touch. For me, this editing environment happens to be Vim with a few useful plugins. So, this short blog post shows some of the things I use for editing Mediawiki documents with Vim. Take a look at my vimrc if you are interested in my other Vim settings.

Syntax highlighting

One of the most important things when editing files is to have some visual support by using syntax highlighting. For Mediawiki, there are a few syntax highlighting plugins available. I use mediwiki.vim.

Quick navigation in Mediawiki documents with Tagbar

A nice way for navigating inside a file is provided by Tagbar. From the webpage:

Vim plugin that displays tags in a window, ordered by class etc.

Since there is no ctags support for Mediawiki available in Tagbar, you have to make it yourself. Here is how I did it.

Add this to your .ctags file:

--langdef=mediawiki
--langmap=mediawiki:.wiki
--regex-mediawiki=/^=[[:space:]]?([^=]+)[[:space:]]?=$/\1/h,header/
--regex-mediawiki=/^==[[:space:]]?([^=]+)[[:space:]]?==$/. \1/h,header/
--regex-mediawiki=/^===[[:space:]]?([^=]+)[[:space:]]?===$/.  \1/h,header/
--regex-mediawiki=/^====[[:space:]]?([^=]+)[[:space:]]?====$/.  \1/h,header/
--regex-mediawiki=/^=====[[:space:]]?([^=]+)[[:space:]]?=====$/.  \1/h,header/

Next up, add this to your .vimrc file:

" tagbar mediawiki support
autocmd FileType mediawiki :!ctags %
let g:tagbar_type_mediawiki = {
  \ 'ctagstype' : 'mediawiki',
  \ 'kinds'     : [
  \ 'h:header',
  \ ],
  \ 'sort'    : 0
  \ }

When you edit a wiki page with Vim and it recognises the file as a Mediawiki document, it will automatically run ctags on the file and the results will be ready to use with the Tagbar plugin.

Snippet support for UltiSnips

Want to have some snippet support for Mediawiki in UltiSnips? Take a look at my snippets for Mediawiki.