sponsor Vim development Vim logo Vim Book Ad

imaps.vim : another template or stub expander

 script karma  Rating 62/22, Downloaded by 3868  Comments, bugs, improvements  Vim wiki

created by
Srinath Avadhanula
 
script type
utility
 
description
imaps.vim is yet another template expander or Stubs expander like several
others out there.

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

\begin{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 '\' after something which
is not defined as a keyword for the current filetype, then you will simply
get a '\'.

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

\begin{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       = "\\begin{itemize}\<cr>\\item ä\<cr>\\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 <C-k> + 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
   "<C-r>=". for example, the following line does the date thingie:

   let s:_date = "\<c-r>=strftime('%b %d %Y')\<cr>"
    
   (":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:)

 
install details
drop in your plugin directory or (not recommended) source it from your .vimrc
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
imaps.vim 1.0 2002-03-12 6.0 Srinath Avadhanula Initial upload
ip used for rating: 34.228.7.237

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github