This repository has been archived on 2023-10-17. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.vim/doc/imaps.txt

87 lines
3.3 KiB
Plaintext

IMAP -- A fluid replacement for :imap
*imaps.txt*
Srinath Avadhanula <srinath AT fastmail DOT fm>
Abstract
========
This plugin provides a function IMAP() which emulates vims |:imap| function. The
motivation for providing this plugin is that |:imap| suffers from problems
which get increasingly annoying with a large number of mappings.
Consider an example. If you do >
imap lhs something
then a mapping is set up. However, there will be the following problems:
1. The 'ttimeout' option will generally limit how easily you can type the lhs.
if you type the left hand side too slowly, then the mapping will not be
activated.
2. If you mistype one of the letters of the lhs, then the mapping is deactivated
as soon as you backspace to correct the mistake.
3. The characters in lhs are shown on top of each other. This is fairly
distracting. This becomes a real annoyance when a lot of characters initiate
mappings.
This script provides a function IMAP() which does not suffer from these
problems.
*imaps.txt-toc*
|im_1| Using IMAP
================================================================================
Using IMAP *im_1* *imaps-usage*
Each call to IMAP is made using the syntax: >
call IMAP (lhs, rhs, ft [, phs, phe])
This is equivalent to having <lhs> map to <rhs> for all files of type <ft>.
Some characters in the <rhs> have special meaning which help in cursor placement
as described in |imaps-placeholders|. The optional arguments define these
special characters.
Example One: >
call IMAP ("bit`", "\\begin{itemize}\<cr>\\item <++>\<cr>\\end{itemize}<++>", "tex")
This effectively sets up the map for "bit`" whenever you edit a latex file. When
you type in this sequence of letters, the following text is inserted: >
\begin{itemize}
\item *
\end{itemize}<++>
where * shows the cursor position. The cursor position after inserting the text
is decided by the position of the first "place-holder". Place holders are
special characters which decide cursor placement and movement. In the example
above, the place holder characters are <+ and +>. After you have typed in the
item, press <C-j> and you will be taken to the next set of <++>'s. Therefore by
placing the <++> characters appropriately, you can minimize the use of movement
keys.
Set g:Imap_UsePlaceHolders to 0 to disable placeholders altogether.
Set g:Imap_PlaceHolderStart and g:Imap_PlaceHolderEnd to something else if you
want different place holder characters. Also, b:Imap_PlaceHolderStart and
b:Imap_PlaceHolderEnd override the values of g:Imap_PlaceHolderStart and
g:Imap_PlaceHolderEnd respectively. This is useful for setting buffer specific
place holders.
Example Two: You can use the <C-r> command to insert dynamic elements such as
dates. >
call IMAP ('date`', "\<c-r>=strftime('%b %d %Y')\<cr>", '')
With this mapping, typing date` will insert the present date into the file.
================================================================================