Editing Wiki pages with vim

From UniLang Wiki

Jump to: navigation, search

If you like using the text editor vim, and you use a browser that lets you edit text fields with an external editor (e.g. lynx, links, w3m, mozilla with the mozex plugin), a few vi macros in your .vimrc file can make life much easier.

These examples use "*" as the action key for Wiki commands. for example

map *$ <esc>mp$a<br><esc>`p

adds a <br> to the end of the current line every time you press "*$" in command mode, while keeping cursor position.
You may also easily make lines into headers by using these maps:

map *h2 <esc>mp0i== <esc>$a ==<esc>`p 
map *h3 <esc>mp0i=== <esc>$a ===<esc>`p 
map *h4 <esc>mp0i==== <esc>$a ====<esc>`p 

To put the current word under the cursor into bold/italics use

map *i <esc>mpebi''<esc>ea''<esc>`p
map *b <esc>mpebi'''<esc>ea'''<esc>`p

To surround the marked text in visual mode with [[ ]], '' '', ''' ''', <nowiki> or colour codes, you may use these visual map commands:

:vmap [[ "zdi[[<C-R>z]]<ESC>
:vmap '' "zda''<C-R>z''<ESC>
:vmap ''' "zda'''<C-R>z'''<ESC>
:vmap nw "zda<nowiki><C-R>z</nowiki><ESC>
:vmap fr "zdi<font color=red><C-R>z</font><ESC> 
:vmap fb "zdi<font color=blue><C-R>z</font><ESC> 
:vmap fg "zdi<font color=green><C-R>z</font><ESC> 
:vmap fy "zdi<font color=yellow><C-R>z</font><ESC> 

And don't forget to set the encoding to utf-8:

:set enc=utf-8

To indent a whole block of pasted text by one whitespace, for example to prevent reformatting of the text, mark the block in visual mode and run

:'<,'>s/^ //g

To load a text into vim that you previously prepared, run

:r file.txt

Browser settings:
If you use mozex, enter the following command for textareas in the mozex configuration menu: xterm -e vim %t

A syntax highlighting file for vim can be found here: http://en.wikipedia.org/wiki/Wikipedia:Syntax_highlighting

Personal tools

« Return to the main site