Closures autocomplete

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Closures autocomplete

Fabien Meghazi-2

Hi all,

I was testing codepress (http://www.codepress.org/) and I was pleased
with the autocomplete of paired chars used in programming such as [  ]
  (  )  "  " , etc...
When you type a  [   the corresponding  ] is append and the cursor is
placed in between.
You guess my question : "Is it possible to do this in vim ?"
I mean in insert mode and without interaction, should be automatic.

Is it possible ?

--
Fabien Meghazi

Website: http://www.amigrave.com
Email: [hidden email]
IM: [hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Closures autocomplete

Ted Pavlic

The VIM-LaTeX plugin makes use of Vim's ability to do exactly this. For
example, when I type:

((

Immediately I get the expansion:

\left( \right)<++>

where my cursor is put in between the \left( and \right). When I am done
typing, I type Cntrl+J which positions my cursor at the <++> and gets
rid of it.

Similarly, inside Vim I can try something like:

:call IMAP('(','(<++>)<++>','')

and now, in insert mode, when I type:

[

I get

[]<++>

where my cursor is placed in between the [ and ].

--Ted

Fabien Meghazi wrote:

> Hi all,
>
> I was testing codepress (http://www.codepress.org/) and I was pleased
> with the autocomplete of paired chars used in programming such as [  ]
>   (  )  "  " , etc...
> When you type a  [   the corresponding  ] is append and the cursor is
> placed in between.
> You guess my question : "Is it possible to do this in vim ?"
> I mean in insert mode and without interaction, should be automatic.
>
> Is it possible ?
>
> --
> Fabien Meghazi
>
> Website: http://www.amigrave.com
> Email: [hidden email]
> IM: [hidden email]
>
> >
>

--
Ted Pavlic <[hidden email]>

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Closures autocomplete

Tony Mechelynck
In reply to this post by Fabien Meghazi-2

Fabien Meghazi wrote:

> Hi all,
>
> I was testing codepress (http://www.codepress.org/) and I was pleased
> with the autocomplete of paired chars used in programming such as [  ]
>   (  )  "  " , etc...
> When you type a  [   the corresponding  ] is append and the cursor is
> placed in between.
> You guess my question : "Is it possible to do this in vim ?"
> I mean in insert mode and without interaction, should be automatic.
>
> Is it possible ?

IIRC, this was asked repeatedly shortly before the vim-org servers at Berlin U
went down. Here are a few examples (for C):

        :imap   "   ""<Left>
        :imap   (   ()<Left>
        :imap   [   []<Left>
        :imap   {   {<CR>}<Up><End>
        :imap   /*  /*<Space><Space>*/<Left><Left><Left>

etc.

You may want not to map the single quote because it is also the apostrophe.


Best regards,
Tony.
--
A total abstainer is one who abstains from everything but abstention,
and especially from inactivity in the affairs of others.
                -- Ambrose Bierce, "The Devil's Dictionary"

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Closures autocomplete

Fabien Meghazi-2

> IIRC, this was asked repeatedly shortly before the vim-org servers at Berlin U
> went down. Here are a few examples (for C):
>         :imap   "   ""<Left>
>         :imap   (   ()<Left>
>         :imap   [   []<Left>
>         :imap   {   {<CR>}<Up><End>
>         :imap   /*  /*<Space><Space>*/<Left><Left><Left>

Thanks a lot Tony !!

Do you have any idea why

 :imap   "   ""<Left>

causes vim to burn 100% cpu and being unresponsive as soon as   "   is typed ?
All the other mappings are working ok.

--
Fabien Meghazi

Website: http://www.amigrave.com
Email: [hidden email]
IM: [hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Closures autocomplete

Michael F. Lamb

Fabien Meghazi wrote:

>> IIRC, this was asked repeatedly shortly before the vim-org servers at Berlin U
>> went down. Here are a few examples (for C):
>>         :imap   "   ""<Left>
>>         :imap   (   ()<Left>
>>         :imap   [   []<Left>
>>         :imap   {   {<CR>}<Up><End>
>>         :imap   /*  /*<Space><Space>*/<Left><Left><Left>
>
> Thanks a lot Tony !!
>
> Do you have any idea why
>
>  :imap   "   ""<Left>
>
> causes vim to burn 100% cpu and being unresponsive as soon as   "   is typed ?
> All the other mappings are working ok.

:imap should be :inoremap in all of the above mappings, otherwise you
risk weird recursive applications like that.

Since Tony's post, I took a moment to update the vim wiki about this
topic, have a look and improve it if you like:

http://vim.wikia.com/wiki/Automatically_append_closing_characters

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Closures autocomplete

Tony Mechelynck
In reply to this post by Fabien Meghazi-2

Fabien Meghazi wrote:

>> IIRC, this was asked repeatedly shortly before the vim-org servers at Berlin U
>> went down. Here are a few examples (for C):
>>         :imap   "   ""<Left>
>>         :imap   (   ()<Left>
>>         :imap   [   []<Left>
>>         :imap   {   {<CR>}<Up><End>
>>         :imap   /*  /*<Space><Space>*/<Left><Left><Left>
>
> Thanks a lot Tony !!
>
> Do you have any idea why
>
>  :imap   "   ""<Left>
>
> causes vim to burn 100% cpu and being unresponsive as soon as   "   is typed ?
> All the other mappings are working ok.
>

Maybe it treats it as a recursive mapping (trying to perpetually expand the
second "). Try

        :inoremap   "   ""<Left>

instead.


Best regards,
Tony.
--
Death is Nature's way of recycling human beings.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Closures autocomplete

Tony Mechelynck
In reply to this post by Michael F. Lamb

Michael F. Lamb wrote:

> Fabien Meghazi wrote:
>>> IIRC, this was asked repeatedly shortly before the vim-org servers at Berlin U
>>> went down. Here are a few examples (for C):
>>>         :imap   "   ""<Left>
>>>         :imap   (   ()<Left>
>>>         :imap   [   []<Left>
>>>         :imap   {   {<CR>}<Up><End>
>>>         :imap   /*  /*<Space><Space>*/<Left><Left><Left>
>> Thanks a lot Tony !!
>>
>> Do you have any idea why
>>
>>  :imap   "   ""<Left>
>>
>> causes vim to burn 100% cpu and being unresponsive as soon as   "   is typed ?
>> All the other mappings are working ok.
>
> :imap should be :inoremap in all of the above mappings, otherwise you
> risk weird recursive applications like that.
>
> Since Tony's post, I took a moment to update the vim wiki about this
> topic, have a look and improve it if you like:
>
> http://vim.wikia.com/wiki/Automatically_append_closing_characters

For the others it is useful but not required, because when the {rhs} starts
with the {lhs} that part is not re-expanded (see ":help recursive-mapping").



Best regards,
Tony.
--
You need no longer worry about the future.  This time tomorrow you'll
be dead.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---