Thursday, December 2, 2010

Re: inoremap doesn't work!

On Thu, 2 Dec 2010, zhang listar wrote:

> 2010/12/1 Ben Fritz
>>
>> On Nov 30, 5:47 am, zhang listar wrote:
>>> :inoremap ( ()<ESC>i
>>> :inoremap ) <c-r>=ClosePair(')')<CR>
>>> :inoremap { {}<ESC>i
>>> :inoremap } <c-r>=ClosePair('}')<CR>
>>> :inoremap [ []<ESC>i
>>> :inoremap ] <c-r>=ClosePair(']')<CR>
>>> :inoremap < <><ESC>i
>>> :inoremap > <c-r>=ClosePair('>')<CR>
>>>
>>> function ClosePair(char)
>>> if getline('.')[col('.') - 1] == a:char
>>> return "\<Right>"
>>> else
>>> return a:char
>>> endif
>>> endf
>>>
>>> I have added the lines above to my vimrc, but vim does't
>>> automatically complete bracket,
>>> What's wrong with my vim?
>>> The vimrc is as follows:
>>>
>> I don't see the content above in your .vimrc you posted. Are you sure
>> you added it?

It appeared in the other (double-) post to which I replied. Odd.


>> On a related note, I like using <Left> instead of <Esc>i in the
>> mappings I have that do similar things. Fewer side effects.

I agree with this advice.


>> See our tip on the subject:
>> http://vim.wikia.com/wiki/Automatically_append_closing_characters
>> <http://www.vim.org/maillist.php>
>>
>
> I am sure that I have added the content to my vimrc. Now, the
> character {, [ works fine.
> But when I type (, vim can't automatically append ) for me. Instead,
> the plugin acp or neocomplcache(I am not sure which one) take effect,
> and pops up a menu to choose the item. I doubt that some plugin of
> vim has affect inoremap of ( .

If when you type '(' some other plugin takes effect, why wouldn't you
think it affected the inoremap? Plugins use the same mechanisms you're
using (:inoremap, etc.). That's probably what's happening.

First, try:

:imap (
:map (

To see if there are any mappings defined for '('. (My guess is that
there's at least one.)

Then, try running Vim with the --noplugin flag, and see if any are still
there. Or even if not, just to see if that clears up the problem.

If one of those plugins defines a mapping, there's certainly a way to disable
it. Depends on how the plugin sets it up, though, what the best way
will be. (modifying the plugin directly, moving your mappings to an
'after' file [see: :help after-directory], moving your mappings to an
autocmd.)

--
Best,
Ben

--
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