Home > imaps.vim

imaps.vim

Imaps.vim is a project mainly written in Vim Script, it's free.

another template or stub expander

This is a mirror of http://www.vim.org/scripts/script.php?script_id=244

imaps.vim is yet another template expander or Stubs expander like several others out there.

The expander works by the user pressing '&#039 (or whatever the leader character is), after a "keyword". the keywords are filetype specific. to give an example, suppose you press '&#039 after the word 'bfg' in a latex file (filetype = tex), then the word 'bfg' will expand to:

egin{figure}[h] centerline{psfig{figure=*.eps}} caption{} label{fig:} end{figure}

and the cursor will be placed where '*' is shown. vim remains in insert mode so that you can continue typing. if you type '&#039 after something which is not defined as a keyword for the current filetype, then you will simply get a '&#039.

the file already contains several mappings mainly for latex and some for html. however it should be very easy to extend it to your liking. it should be fairly obvious how to extend it if you look at the file, but here's the little description:

suppose you want the keyword 'bit' to expand to

egin{itemize} item * end{itemize}

and have the cursor be positioned where '*' is shown, add the following line to imaps.vim (actually, this line is already there, but it makes for a good example)

let s:tex_bit = "egin{itemize}item äend{itemize}"

explanation:

  1. the suffix 's:' is to make it script specific.
  2. then 'tex' makes imaps.vim treat 'deg' as a keyword only for latex files.
  3. 'bit' is the keyword itself.
  4. the rhs is what you want to have 'bit' expand to. if you want the cursor not to be positioned anywhere special, then nothing needs to be done. the cursor will be placed at the end. However, if like in this example, you want it to be at a specific place, put a "ä" (the a-double-dot character) where you want the cursor to be. (the ä character is obtained by typing control-k-a-colon + a + : ).

NOTE:

  1. if you want a "dynamic" rhs, i.e you want the keyword 'date' to expand to the present date, then you can have the rhs begin with the string "=". for example, the following line does the date thingie:

    let s:_date = "=strftime('%b %d %Y')"

    (":help i_CTRL-R" for how this works).

  2. if you want a keyword to be filetype insensetive (i.e to work across all files) like the date thing above, then like the example above, do not prepend any file type, just use

    let s:_keyword = expansion

    (note the leading underscore after s:)

Previous:Buffer-Menus