bracket completion

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

bracket completion

Greg Fitzgerald-2
Anyone know of a way to achieve bracket completion? For example if your
typing a if statement, if (something) { once you type the first bracket
the 2nd one is inserted below for you. Scribes and a few other editors
have this functionality and was hoping to achieve it with Vim. Another
thing that this does, if you were to type $data[' for example. The 2nd '
would be inserted for you after your cursor. Just seems to save time
when I played with scribes a few days ago. I was looking through the
help, scripts and mailing list archives for something like this but have
not hit any matches. Just wondering if people have ideas on how this
could be done or maybe know of an existing way. Thanks in advance.

--Greg
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

A.J.Mechelynck
Greg Fitzgerald wrote:

> Anyone know of a way to achieve bracket completion? For example if your
> typing a if statement, if (something) { once you type the first bracket
> the 2nd one is inserted below for you. Scribes and a few other editors
> have this functionality and was hoping to achieve it with Vim. Another
> thing that this does, if you were to type $data[' for example. The 2nd '
> would be inserted for you after your cursor. Just seems to save time
> when I played with scribes a few days ago. I was looking through the
> help, scripts and mailing list archives for something like this but have
> not hit any matches. Just wondering if people have ideas on how this
> could be done or maybe know of an existing way. Thanks in advance.
>
> --Greg
>

        :inoremap { {<CR>}<Up><End>
        :inoremap [ []<Left>
        :inoremap ( ()<Left>

etc.

This assumes brace indenting is taken care of (by 'cindent' or 'indentexpr').

IIUC, you can still enter an "unpaired brace" (or bracket or paren) by
prefixing it with Ctrl-V (or with Ctrl-Q if Ctrl-V pastes).

Best regards,
Tony.
--
Experience varies directly with equipment ruined.
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

A.J.Mechelynck
A.J.Mechelynck wrote:

> Greg Fitzgerald wrote:
>> Anyone know of a way to achieve bracket completion? For example if
>> your typing a if statement, if (something) { once you type the first
>> bracket
>> the 2nd one is inserted below for you. Scribes and a few other editors
>> have this functionality and was hoping to achieve it with Vim. Another
>> thing that this does, if you were to type $data[' for example. The 2nd '
>> would be inserted for you after your cursor. Just seems to save time
>> when I played with scribes a few days ago. I was looking through the
>> help, scripts and mailing list archives for something like this but have
>> not hit any matches. Just wondering if people have ideas on how this
>> could be done or maybe know of an existing way. Thanks in advance.
>>
>> --Greg
>>
>
>     :inoremap { {<CR>}<Up><End>
>     :inoremap [ []<Left>
>     :inoremap ( ()<Left>
>
> etc.
>
> This assumes brace indenting is taken care of (by 'cindent' or
> 'indentexpr').
>
> IIUC, you can still enter an "unpaired brace" (or bracket or paren) by
> prefixing it with Ctrl-V (or with Ctrl-Q if Ctrl-V pastes).
>
> Best regards,
> Tony.

P.S. If you implement it for quotes, you may want to disable it for vimscript,
which has unpaired double quotes (marking off comments) and unpaired single
and double quotes (in the argument of ":normal" for registers or marks).

Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
156. You forget your friend's name but not her e-mail address.
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Greg Fitzgerald-2
On Sun, Apr 01, 2007 at 06:01:34AM +0200, A.J.Mechelynck wrote:

> A.J.Mechelynck wrote:
> >Greg Fitzgerald wrote:
> >>Anyone know of a way to achieve bracket completion? For example if
> >>your typing a if statement, if (something) { once you type the first
> >>bracket
> >>the 2nd one is inserted below for you. Scribes and a few other editors
> >>have this functionality and was hoping to achieve it with Vim. Another
> >>thing that this does, if you were to type $data[' for example. The 2nd '
> >>would be inserted for you after your cursor. Just seems to save time
> >>when I played with scribes a few days ago. I was looking through the
> >>help, scripts and mailing list archives for something like this but have
> >>not hit any matches. Just wondering if people have ideas on how this
> >>could be done or maybe know of an existing way. Thanks in advance.
> >>
> >>--Greg
> >>
> >
> >    :inoremap { {<CR>}<Up><End>
> >    :inoremap [ []<Left>
> >    :inoremap ( ()<Left>
> >
> >etc.
> >
> >This assumes brace indenting is taken care of (by 'cindent' or
> >'indentexpr').
> >
> >IIUC, you can still enter an "unpaired brace" (or bracket or paren) by
> >prefixing it with Ctrl-V (or with Ctrl-Q if Ctrl-V pastes).
> >
> >Best regards,
> >Tony.
>
> P.S. If you implement it for quotes, you may want to disable it for
> vimscript, which has unpaired double quotes (marking off comments) and
> unpaired single and double quotes (in the argument of ":normal" for
> registers or marks).
>
> Best regards,
> Tony.
> --
> hundred-and-one symptoms of being an internet addict:
> 156. You forget your friend's name but not her e-mail address.

Great advice Tony. Thanks for the really quick response as well.
I'll just add a statment enabling this for certain languages. This has
also giving me a couple new ideas to play with. Thanks again. :)

--Greg
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Fritz Mehner
In reply to this post by A.J.Mechelynck
A.J.Mechelynck schrieb:

> Greg Fitzgerald wrote:
>
>> Anyone know of a way to achieve bracket completion? For example if
>> your typing a if statement, if (something) { once you type the first
>> bracket
>> the 2nd one is inserted below for you. Scribes and a few other editors
>> have this functionality and was hoping to achieve it with Vim. Another
>> thing that this does, if you were to type $data[' for example. The 2nd '
>> would be inserted for you after your cursor. Just seems to save time
>> when I played with scribes a few days ago. I was looking through the
>> help, scripts and mailing list archives for something like this but have
>> not hit any matches. Just wondering if people have ideas on how this
>> could be done or maybe know of an existing way. Thanks in advance.
>>
>> --Greg
>>
>
>     :inoremap { {<CR>}<Up><End>
>     :inoremap [ []<Left>
>     :inoremap ( ()<Left>
>
> etc.
>
> This assumes brace indenting is taken care of (by 'cindent' or
> 'indentexpr').
>
> IIUC, you can still enter an "unpaired brace" (or bracket or paren) by
> prefixing it with Ctrl-V (or with Ctrl-Q if Ctrl-V pastes).
>
> Best regards,
> Tony.

In addition I use the following settings

vnoremap  (  s()<Esc>P<Right>
vnoremap  [  s[]<Esc>P<Right>
vnoremap  {  s{}<Esc>P<Right>

to surround a  selection in visual mode.
Regards,
Fritz




Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Panos Laganakos
Those are great, thanks alot :)

On 4/1/07, Fritz Mehner <[hidden email]> wrote:

> A.J.Mechelynck schrieb:
>
> > Greg Fitzgerald wrote:
> >
> >> Anyone know of a way to achieve bracket completion? For example if
> >> your typing a if statement, if (something) { once you type the first
> >> bracket
> >> the 2nd one is inserted below for you. Scribes and a few other editors
> >> have this functionality and was hoping to achieve it with Vim. Another
> >> thing that this does, if you were to type $data[' for example. The 2nd '
> >> would be inserted for you after your cursor. Just seems to save time
> >> when I played with scribes a few days ago. I was looking through the
> >> help, scripts and mailing list archives for something like this but have
> >> not hit any matches. Just wondering if people have ideas on how this
> >> could be done or maybe know of an existing way. Thanks in advance.
> >>
> >> --Greg
> >>
> >
> >     :inoremap { {<CR>}<Up><End>
> >     :inoremap [ []<Left>
> >     :inoremap ( ()<Left>
> >
> > etc.
> >
> > This assumes brace indenting is taken care of (by 'cindent' or
> > 'indentexpr').
> >
> > IIUC, you can still enter an "unpaired brace" (or bracket or paren) by
> > prefixing it with Ctrl-V (or with Ctrl-Q if Ctrl-V pastes).
> >
> > Best regards,
> > Tony.
>
> In addition I use the following settings
>
> vnoremap  (  s()<Esc>P<Right>
> vnoremap  [  s[]<Esc>P<Right>
> vnoremap  {  s{}<Esc>P<Right>
>
> to surround a  selection in visual mode.
> Regards,
> Fritz
>
>
>
>
>


--
Panos Laganakos
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

nephish
i am finding these usefull too, thanks
sk

On 4/2/07, Panos Laganakos <[hidden email]> wrote:

> Those are great, thanks alot :)
>
> On 4/1/07, Fritz Mehner <[hidden email]> wrote:
> > A.J.Mechelynck schrieb:
> >
> > > Greg Fitzgerald wrote:
> > >
> > >> Anyone know of a way to achieve bracket completion? For example if
> > >> your typing a if statement, if (something) { once you type the first
> > >> bracket
> > >> the 2nd one is inserted below for you. Scribes and a few other editors
> > >> have this functionality and was hoping to achieve it with Vim. Another
> > >> thing that this does, if you were to type $data[' for example. The 2nd '
> > >> would be inserted for you after your cursor. Just seems to save time
> > >> when I played with scribes a few days ago. I was looking through the
> > >> help, scripts and mailing list archives for something like this but have
> > >> not hit any matches. Just wondering if people have ideas on how this
> > >> could be done or maybe know of an existing way. Thanks in advance.
> > >>
> > >> --Greg
> > >>
> > >
> > >     :inoremap { {<CR>}<Up><End>
> > >     :inoremap [ []<Left>
> > >     :inoremap ( ()<Left>
> > >
> > > etc.
> > >
> > > This assumes brace indenting is taken care of (by 'cindent' or
> > > 'indentexpr').
> > >
> > > IIUC, you can still enter an "unpaired brace" (or bracket or paren) by
> > > prefixing it with Ctrl-V (or with Ctrl-Q if Ctrl-V pastes).
> > >
> > > Best regards,
> > > Tony.
> >
> > In addition I use the following settings
> >
> > vnoremap  (  s()<Esc>P<Right>
> > vnoremap  [  s[]<Esc>P<Right>
> > vnoremap  {  s{}<Esc>P<Right>
> >
> > to surround a  selection in visual mode.
> > Regards,
> > Fritz
> >
> >
> >
> >
> >
>
>
> --
> Panos Laganakos
>
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Greg Matheson
On Mon, 02 Apr 2007, shawn bright wrote:

> i am finding these usefull too, thanks

Check out Luc Hermitte's development of Stephen Riehm's
bracketing macros.

http://hermitte.free.fr/vim/settings.php#settings

--
Greg Matheson                I have an elaborate mnemonic for
                             remembering what day it is. It's
                             called the number system.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

nephish
this looks like exactly what i am after.
i am kind of a newbie here, and cant quite get it to work right.
i believe that i need a python.vim file in /ftplugin directory.
but i dont know how to word it to make this plugin work,
could anyone kinda help me here, i can't make out what i should do
from the docs on the website that you linked to

thanks for any tips

sk

On 4/2/07, Greg Matheson <[hidden email]> wrote:

> On Mon, 02 Apr 2007, shawn bright wrote:
>
> > i am finding these usefull too, thanks
>
> Check out Luc Hermitte's development of Stephen Riehm's
> bracketing macros.
>
> http://hermitte.free.fr/vim/settings.php#settings
>
> --
> Greg Matheson                I have an elaborate mnemonic for
>                              remembering what day it is. It's
>                              called the number system.
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

nephish
whoa !, nevermind, found an example file on his website, tried it and works,.
sorry, my own rftm mistake

sk

On 4/2/07, shawn bright <[hidden email]> wrote:

> this looks like exactly what i am after.
> i am kind of a newbie here, and cant quite get it to work right.
> i believe that i need a python.vim file in /ftplugin directory.
> but i dont know how to word it to make this plugin work,
> could anyone kinda help me here, i can't make out what i should do
> from the docs on the website that you linked to
>
> thanks for any tips
>
> sk
>
> On 4/2/07, Greg Matheson <[hidden email]> wrote:
> > On Mon, 02 Apr 2007, shawn bright wrote:
> >
> > > i am finding these usefull too, thanks
> >
> > Check out Luc Hermitte's development of Stephen Riehm's
> > bracketing macros.
> >
> > http://hermitte.free.fr/vim/settings.php#settings
> >
> > --
> > Greg Matheson                I have an elaborate mnemonic for
> >                              remembering what day it is. It's
> >                              called the number system.
> >
> > --
> > This message has been scanned for viruses and
> > dangerous content by MailScanner, and is
> > believed to be clean.
> >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Zarko Coklin-2
In reply to this post by Greg Fitzgerald-2
It is hard to expand on Tony's feedback, ever. Still,
I found the following works a bit better. Not only
that it creates a right brace but it also places a
cursor on the right spot (taking into consideration
indentation if you set it).


:inoremap { {<CR>}<Up><CR><End>
:inoremap [ []<Left>
:inoremap ( ()<Left>

Regards,
Zarko Coklin


 
____________________________________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121
Reply | Threaded
Open this post in threaded view
|

RE: bracket completion

Waters, Bill
In reply to this post by Greg Fitzgerald-2
Can you provide and example of how to do this?

Thanks,
Bill


> >
> >    :inoremap { {<CR>}<Up><End>
> >    :inoremap [ []<Left>
> >    :inoremap ( ()<Left>
> >
>
> I'll just add a statment enabling this for certain languages. This has
> also giving me a couple new ideas to play with. Thanks again. :)
>
> --Greg
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

A.J.Mechelynck
In reply to this post by Zarko Coklin-2
Zarko Coklin wrote:

> It is hard to expand on Tony's feedback, ever. Still,
> I found the following works a bit better. Not only
> that it creates a right brace but it also places a
> cursor on the right spot (taking into consideration
> indentation if you set it).
>
>
> :inoremap { {<CR>}<Up><CR><End>
> :inoremap [ []<Left>
> :inoremap ( ()<Left>
>
> Regards,
> Zarko Coklin

"The right spot" depends on your C coding style: your mapping might apply for

        if (condition) {
                statement;
                statement;
        }

and

        void function functionname(void* p) {
                statement;
                statement;
        }

though it might be better to place <CR> _after_ <End> in the {rhs} to avoid
splitting a word in the middle. Mine is better for

        if (condition)
        { statement;
                statement;
        }

and

        void function functionname(void* p)
        { statement;
                statement;
        }

and can still be used for yours, by hitting <Enter> after the mapped {


Best regards,
Tony.
--
Taxes are going up so fast, the government is likely to price itself
out of the market.
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Luc Hermitte
In reply to this post by nephish
Hello,

* On Mon, Apr 02, 2007 at 10:38:14AM -0500, shawn bright <[hidden email]> wrote:
> >> Check out Luc Hermitte's development of Stephen Riehm's
> >> bracketing macros.
> >>
> >> http://hermitte.free.fr/vim/settings.php#settings

> On 4/2/07, shawn bright <[hidden email]> wrote:
> >this looks like exactly what i am after.  i am kind of a newbie here,
> >and cant quite get it to work right.
> >i believe that i need a python.vim file in /ftplugin directory.

Only if you want to customize the bracketing system for python.

> >but i dont know how to word it to make this plugin work,
> >could anyone kinda help me here, i can't make out what i should do
> >from the docs on the website that you linked to

> whoa !, nevermind, found an example file on his website, tried it and
> works,.
> sorry, my own rftm mistake


The doc is a little bit outdated. The plugin used to word standalone.
But now there are a lot of inter-dependendies between by plugins -- I'm
still in the process of refactoring everything. As a consequence,
prefer the tarball archives.

lh-map-tools.tar.gz should be enough -- but don't forget to define a
ftplugin suited to your needs. If you want a more complete suite,
check the C&C++ ftplugins suite (which encapsulates/contains map-tools),
which is the most complete of all [1]. There are a few other suites,
which are not really maintained anymore. [2]

If you have any questions feel free to ask. I've tried to write a
documentation (the one in the tarball) as complete as I could, but I may
have missed a few details.

HTH,

[1] it contains many mappings to insert control-statements (if, for,
...) in every mode.
[2] http://hermitte.free.fr/vim/ressources -> *.tar.gz

--
Luc Hermitte
http://hermitte.free.fr/vim/
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Panos Laganakos
In reply to this post by A.J.Mechelynck
One thing that would also be great, was if you were able to "tab" your
way out of it, ie move to the outside of the bracket, once you're
done. Now you need to either press right, to move ahead (which is not
quite vim-ish), or hit escape and Shift_A, to resume editing.

Only possible way I can think of, is to use a snippet system, like
snippetsEmu[1] or something. Any other suggestions?


[1] http://www.vim.org/scripts/script.php?script_id=1318

On 4/2/07, A.J.Mechelynck <[hidden email]> wrote:

> Zarko Coklin wrote:
> > It is hard to expand on Tony's feedback, ever. Still,
> > I found the following works a bit better. Not only
> > that it creates a right brace but it also places a
> > cursor on the right spot (taking into consideration
> > indentation if you set it).
> >
> >
> > :inoremap { {<CR>}<Up><CR><End>
> > :inoremap [ []<Left>
> > :inoremap ( ()<Left>
> >
> > Regards,
> > Zarko Coklin
>
> "The right spot" depends on your C coding style: your mapping might apply for
>
>         if (condition) {
>                 statement;
>                 statement;
>         }
>
> and
>
>         void function functionname(void* p) {
>                 statement;
>                 statement;
>         }
>
> though it might be better to place <CR> _after_ <End> in the {rhs} to avoid
> splitting a word in the middle. Mine is better for
>
>         if (condition)
>         {       statement;
>                 statement;
>         }
>
> and
>
>         void function functionname(void* p)
>         {       statement;
>                 statement;
>         }
>
> and can still be used for yours, by hitting <Enter> after the mapped {
>
>
> Best regards,
> Tony.
> --
> Taxes are going up so fast, the government is likely to price itself
> out of the market.
>


--
Panos Laganakos
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Luc Hermitte
* On Tue, Apr 03, 2007 at 02:14:59AM +0300, Panos Laganakos <[hidden email]> wrote:
> One thing that would also be great, was if you were able to "tab" your
> way out of it, ie move to the outside of the bracket, once you're
> done. Now you need to either press right, to move ahead (which is not
> quite vim-ish), or hit escape and Shift_A, to resume editing.
>
> Only possible way I can think of, is to use a snippet system, like
> snippetsEmu[1] or something. Any other suggestions?

Well. You can use my bracketing system, or the fork of mu-template I'm
maintaining (which relies on the bracketing system) -- see my signature.
The marker/placeholder can be easily enable or disabled, cutomized for
every language, ...

--
Luc Hermitte
http://hermitte.free.fr/vim/ressources/
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

nephish
Thanks Luc,
i got the main functionality working, pretty much. I only really
desire the bracket matching, and so far, i am really pleased. They all
work except the [] . So i think maybe there is a conflict with another
plugin ( i have the snippets-Emu, supertabs, and taglist plugins also.
) The overall effect is really cool.

thanks again.

sk

On 4/2/07, Luc Hermitte <[hidden email]> wrote:

> * On Tue, Apr 03, 2007 at 02:14:59AM +0300, Panos Laganakos <[hidden email]> wrote:
> > One thing that would also be great, was if you were able to "tab" your
> > way out of it, ie move to the outside of the bracket, once you're
> > done. Now you need to either press right, to move ahead (which is not
> > quite vim-ish), or hit escape and Shift_A, to resume editing.
> >
> > Only possible way I can think of, is to use a snippet system, like
> > snippetsEmu[1] or something. Any other suggestions?
>
> Well. You can use my bracketing system, or the fork of mu-template I'm
> maintaining (which relies on the bracketing system) -- see my signature.
> The marker/placeholder can be easily enable or disabled, cutomized for
> every language, ...
>
> --
> Luc Hermitte
> http://hermitte.free.fr/vim/ressources/
>
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Luc Hermitte
shawn bright <[hidden email]> wrote:

> i got the main functionality working, pretty much. I only really
> desire the bracket matching, and so far, i am really pleased. They all
> work except the [] . So i think maybe there is a conflict with another
> plugin ( i have the snippets-Emu, supertabs, and taglist plugins also.
> ) The overall effect is really cool.

I can't tell if there are conflicts with these plugins as I don't use them.

Try a
   :verbose imap [

If my plugin is correctly working, and not overidden, it should point to a
mapping defined in plugin/common_brackets.vim


> thanks again.

You're welcome.


--
Luc Hermitte
http://hermitte.free.fr/vim/
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Karl Guertin
In reply to this post by Greg Fitzgerald-2
On 3/31/07, Greg Fitzgerald <[hidden email]> wrote:
> Anyone know of a way to achieve bracket completion?

I've been sitting on a plugin that does this for a month or so. The
main difference between my plugin and the rest of the options here is
that I do the completion without breaking history or repeat.

Freshly uploaded to vim.org:

http://www.vim.org/scripts/script.php?script_id=1849

This plugin was pared down from a larger script that included a set of
less reusable mappings, so let me know if there's a problem.
Reply | Threaded
Open this post in threaded view
|

Re: bracket completion

Silent1
Just tried the plugin and it works great, the only issue i'm having is
typing '{'
results in this
'{|}' not
{
   |
}
where | is the cursor position. Is there any option to change this or
am i doing something wrong? Thanks
--Brendon

On 4/3/07, Karl Guertin <[hidden email]> wrote:

> On 3/31/07, Greg Fitzgerald <[hidden email]> wrote:
> > Anyone know of a way to achieve bracket completion?
>
> I've been sitting on a plugin that does this for a month or so. The
> main difference between my plugin and the rest of the options here is
> that I do the completion without breaking history or repeat.
>
> Freshly uploaded to vim.org:
>
> http://www.vim.org/scripts/script.php?script_id=1849
>
> This plugin was pared down from a larger script that included a set of
> less reusable mappings, so let me know if there's a problem.
>
12