Hello,

* On Thu, Jun 29, 2006 at 02:45:16PM +0100, Zhang Le <[EMAIL PROTECTED]> wrote:
> Most of time I want a space after a comma, so I use "imap , , "
> The problem is, sometime I do not want a comma inside square
> brackets in some programming language such python and matlab:
>     a[10,:] or a(10,:)
> 
> Is there a way to not insert a space based on context around the
> cursor so that if the text before cursor is [xxx, or (xxx, no space
> will be inserted?

I see two ways:
1- The first is to rely on ftplugins and :map-<buffer>. This way, you
can specify mappings for specific filetypes. However, it won't be able
to distinguish normal commas, from commas used in arrays.

2- The second is to define context dependent mapping. You can search for
the discussion I had with Dr Bean last week on this topic.
You can search for the following Message-ID on gmane:
    <[EMAIL PROTECTED]>

He used the function InsertIfNotAfter() I define in my C++ ftplugin
cpp_set.vim available in lh-cpp.tar.gz [1].
In your case, I guess it will look like:

    inoremap <silent> ,
        \ <c-r>=InsertIfNotAfter(',', ', ', '[[(][^]]\+')<cr>

HTH, 


[1] http://hermitte.free.fr/vim/ressources/lh-cpp.tar.gz
-- 
Luc Hermitte
http://hermitte.free.fr/vim/

Reply via email to