Monday, June 28, 2010

Re: Conditional imap

On Mon, June 28, 2010 11:46 am, gitterrost4 wrote:
> I am using vim mostly for LaTeX-editing. now I would like to imap the
> sequence "(<Tab>" to "\left(".
>
> The Problem being that "\left(" is only valid in Math-Mode.
>
> So I would like to first check (by regex) if I am in a Math-environment
> (e.g count the number of "$"-signs) and if so, imap the above mentioned.
>
> Is there any way of doing that?

You can use map-expressions, as explained in :h map-expression

Excuse my LaTeX skills, I haven't used math-mode in a while, but something
like this should work:

imap <expr> <Tab> synIDattr(synID(line('.'), col('.'), 1), "name")=~
"texMath" ? "\left(" : "\t"

(one line)

This obviously requires a working Syntax highlighting (e.g. :syntax on)
and I am not sure, if the name "texMath" matches all different TeX Math
environments.

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment