URL:         http://www.math.fu-berlin.de/~guckes/vim/macros/
URL:         http://www.vim.org/macros/ (mirror)
Created:     Mon Feb 22 18:00:00 CET 1999
Last update: Tue Feb 23 12:00:00 CET 1999

VIM Macros/Mappings

Well, I have hundreds of macros on my hands - but they will not be of much use unless they get documented, I think. Therefore this page has not much yet. Sorry.

TODO: Add macros from the VIM FAQ and from posts on comp.editors.


Sven's vimrc

Sven's vimrc has many examples of mappings. Take a look!

Mirror/reverse Lines

by Dr. Charles E. Campbell Jr. (cec@gryphon.gsfc.nasa.gov)

Description: This script "mirrors" (reverses) the contents of the text between (the line marked with) 'a' and the current line. The script is sourced with a map to "\fm". Depending on the kind of map for "\fm" the order of the lines will remain or be reversed, too.

Instructions: Let your shell export VIMSCRIPT which points to the directory where you keep your scripts for Vim, eg "export VIMSCRIPT=/Vol/Pub/share/vim/syntax".

Define this map:

map \fm :'a,.g/^/:so $VIMSCRIPT/mirror.vim<CR> Here is the "mirror.vim" that should get sourced:
"mirror.vim script : "mirror images" the current line
"  Uses my mz "y
normal ^my$mz
"
if col("'y") < col("'z")
  " note: the first time, mz is at $, and when the character
  "       at 'a is deleted, mz travels backwards with $
  normal `yl"yd`y`z"yphmzl"yd`z`y"yP`ylmy
  endif
"
while col("'y") < col("'z")
  " note: normally, marks will remain in the same column,
  "       and will *not* travel with the marked character
  "       during deletions
  normal `yl"yd`y`zhmz"yphmzl"yd`z`y"yP`ylmy
  endwhile
Go to some line, ma. Move to end-of-block. These lines will now be mirror-imaged.

Example:

Applying this self-referentially: :yllaitnerefer-fles siht gniylppA Using "\fr" in a similar manner will also reverse the lines:

        map \fr   o<Esc>mz'aO<Esc>ma:'a+1,'z-1g/^/m 'a<CR>'add'zdd

Send feedback on this page to
Sven Guckes guckes@math.fu-berlin.de