If you find the need to create your own macros, then you can use the
IMAP()
function provided with Latex-Suite. See Why use IMAP()
for a short
explanation of why you might prefer IMAP()
over
Vim's standard :imap
command. An example best
explains the usage:
:call IMAP('NOM', '\nomenclature{<++>}<++>', 'tex')
This will create a Latex-Suite-style mapping, where if you type
NOM
in insert mode, you will get
\nomenclature{<++>}<++>
with the cursor left in
place of the first <++>
characters. See IMAP() syntax for
a detailed explanation of the IMAP()
command.
For maps which are triggered for a given filetype, the
IMAP()
command above should be put in the filetype
plugin script for that file. For example, for tex-specific mappings,
the IMAP()
calls should go in
$VIM/ftplugin/tex.vim
. For globally visible maps,
you will need to use the following in either your
~/.vimrc
or a file in your
$VIM/plugin
directory.
augroup MyIMAPs au! au VimEnter * call IMAP('Foo', 'foo', '') augroup END
IMAP
mappings can be removed by
IUNMAP
, e.g.,
call IUNMAP('FEM','tex')
Using IMAP
instead of Vim's built-in
:imap
command has a couple of advantages:
:imap
. if you type
the left hand side too slowly, then the mapping will not be
activated.
Formally, the syntax which is used for the IMAP
function is:
call IMAP (lhs, rhs, ft [, phs, phe])
Argument | Explanation |
---|---|
lhs |
This is the "left-hand-side" of the mapping. When you use
If you have two mappings which end in a common
call IMAP('BarFoo', 'something', 'tex') call IMAP('Foo', 'something else', 'tex')
Then typing
Also, the nature of call IMAP('foo', 'something', 'tex') call IMAP('foobar', 'something else', 'tex')
Then you will never be able to trigger |
rhs |
The "right-hand-side" of the mapping. This is the expansion you
will get when you type
This string can also contain special characters such as
:call IMAP('EFE', "\\begin{figure}\<CR><++>\\end{figure}<++>", 'tex')
With this, typing You can also set up a Latex-Suite style mapping which calls a custom function as follows: :call IMAP('FOO', "\<C-r>=MyFoonction()\<CR>", 'tex')
where call IMAP('FOO', "\<C-r>=AskVimFunc()\<CR>", 'vim') " Askvimfunc: Asks For Function Name And Sets Up Template " Description: function! AskVimFunc() let name = input('Name of the function : ') if name == '' let name = "<+Function Name+>" end let islocal = input('Is this function scriptlocal ? [y]/n : ', 'y') if islocal == 'y' let sidstr = '<SID>' else let sidstr = '' endif return IMAP_PutTextWithMovement( \ "\" ".name.": <+short description+> \<cr>" . \ "Description: <+long description+>\<cr>" . \ "\<C-u>function! ".name."(<+arguments+>)<++>\<cr>" . \ "<+function body+>\<cr>" . \ "endfunction \" " \ ) endfunction
|
ft |
The file type for which this mapping is active. When this string is left empty, the mapping applies for all file-types. A filetype specific mapping will always take precedence. |
phs, phe |
If you prefer to write the
Note that the |