Vim Tips Wiki
Advertisement

This tip describes how to configure syntax highlighting and folding for MoinMoin files. It is quite useful when using editmoin.

Syntax highlighting

Install the moin.vim script.

Folding

This will allow you to have folding of wiki sections ==section==, ===subsection===, etc. It is done through expression folding, so you have to define the folding expression, and set the proper fold method (expr).

Put the following in your vimrc

function! WikiIndent(lnum)
python << EOF
import vim
import os
ln = vim.eval('a:lnum')
l = vim.current.buffer[int(ln)-1]
if l.startswith('='):
    total = 0
    for c in l:
        if c == '=':
            total = total + 1
        else:
            break
    vim.command('let total=\'>%s\'' % str(total))
else:
    total = '='
    vim.command('let total="="')
EOF
    return total
endfunction

Now you can define your fold expression (.vim/ftplugin/moin.vim would be a good location)

set foldmethod=expr
set foldexpr=WikiIndent(v:lnum)

File type definition

It is necessary to tell Vim to associate MoinMoin files with the moin filetype. Assuming that all MoinMoin files have the .moin extension, adding the following to the .vim/ftdetect/moin.vim file enables the filetype detection (create the file if it doesn't exist)

au BufRead,BufNewFile *.moin            set filetype=moin

Extras

Since MoinMoin uses utf8 to handle its text, you should set the proper encoding when editing such files. Add the following to your .vim/ftplugin/moin.vim

set encoding=utf8

Comments

Advertisement