How to delete matching brace when deleting a brace?

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

How to delete matching brace when deleting a brace?

Goli, Rajesh (Rajesh)
I have something like

{ blah blah
...
blah }

I can go to the matching brace from one brace by pressing %. But once I
delete a brace its 'match' is lost. How can I delete them both without
having to manually note down the position of the matching brace?

TIA
Rajesh
Reply | Threaded
Open this post in threaded view
|

Re: How to delete matching brace when deleting a brace?

Jürgen Krämer

Hi,

Goli, Rajesh (Rajesh) wrote:

>
> I have something like
>
> { blah blah
> ...
> blah }
>
> I can go to the matching brace from one brace by pressing %. But once I
> delete a brace its 'match' is lost. How can I delete them both without
> having to manually note down the position of the matching brace?

put the cursor anywhere inside or on the opening or closing braces and
enter

  da}

Regards,
J?rgen

--
J?rgen Kr?mer                              Softwareentwicklung
HABEL GmbH & Co. KG                        mailto:[hidden email]
Hinteres ?schle 2                          Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim                    Fax: +49 / 74 61 / 93 53 - 99
Reply | Threaded
Open this post in threaded view
|

Re: How to delete matching brace when deleting a brace?

Jürgen Krämer

Hi,

J?rgen Kr?mer wrote:

> Hi,
>
> Goli, Rajesh (Rajesh) wrote:
>
> > I have something like
> >
> > { blah blah
> > ...
> > blah }
> >
> > I can go to the matching brace from one brace by pressing %. But once I
> > delete a brace its 'match' is lost. How can I delete them both without
> > having to manually note down the position of the matching brace?
>
>
> put the cursor anywhere inside or on the opening or closing braces and
> enter
>
>   da}

probably I mis-read your question -- if you only want to delete the
braces and not the text between them put the cursor on one of them and
enter

  %x``

Regards,
J?rgen

--
J?rgen Kr?mer                              Softwareentwicklung
HABEL GmbH & Co. KG                        mailto:[hidden email]
Hinteres ?schle 2                          Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim                    Fax: +49 / 74 61 / 93 53 - 99
Reply | Threaded
Open this post in threaded view
|

RE: How to delete matching brace when deleting a brace?

Goli, Rajesh (Rajesh)
In reply to this post by Goli, Rajesh (Rajesh)
Jürgen,

I want to delete 'just the braces'. But da would delete everything that is
enclosed in the braces too, wouldnt it?

-Rajesh

-----Original Message-----
From: Jürgen Krämer [mailto:[hidden email]]
Sent: Monday, September 05, 2005 6:31 PM
To: vim mailing list
Subject: Re: How to delete matching brace when deleting a brace?



Hi,

Goli, Rajesh (Rajesh) wrote:

>
> I have something like
>
> { blah blah
> ...
> blah }
>
> I can go to the matching brace from one brace by pressing %. But once I
> delete a brace its 'match' is lost. How can I delete them both without
> having to manually note down the position of the matching brace?

put the cursor anywhere inside or on the opening or closing braces and
enter

  da}

Regards,
Jürgen

--
Jürgen Krämer                              Softwareentwicklung
HABEL GmbH & Co. KG                        mailto:[hidden email]
Hinteres Öschle 2                          Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim                    Fax: +49 / 74 61 / 93 53 - 99
Reply | Threaded
Open this post in threaded view
|

Re: How to delete matching brace when deleting a brace?

Tim Chase-2
In reply to this post by Jürgen Krämer
>>{ blah blah
>>...
>>blah }
>>
>> I can go to the matching brace from one brace by pressing %.
>> But once I delete a brace its 'match' is lost. How can I
>> delete them both without having to manually note down the
>> position of the matching brace?
>
>
> put the cursor anywhere inside or on the opening or closing
> braces and enter
>
> da}

Yes, "da}" will delete the braces *and their content*.  I'm not
sure this is what the OP was asking for.  (then again, I could
well be wrong on this :)

It sounded like the OP wanted to be able to un-brace-ify the
text, so that if you have, say

        if (foo) {
                bar;
                baz;
        }

to change it to something like

        if (foo)
                bar;
                baz

when the cursor is on either the opening or closing brace.

The solution, as I understand it would be to go to the matching
item first, delete it, and then use backtick-backtick to return
to the previous location and delete it.  Something like the
following mapping may do the trick

        :nnoremap <f4> %x``x

which might be smartly wrapped in a check first to ensure that
you're currently sitting on a germane character, as otherwise,
you may get some surprising results:

nnoremap <f4> :if getline(".")[col(".")-1]=~'[[(){}\]]' <bar> exe
"norm %x``x" <bar> endif<cr>

Note that this only works for the single-character pairs.  The
"%" is smart enough to jump to C-style comments /* ... */ and
preprocessor conditionals (#if/#ifdef/#else/#endif) as well.

I have found an odd edgecase where, if you're on the closing
item, there's stuff after the closing item, and it's on the same
line as its opening mate, it doesn't quite work correctly.  If
you're on the opening item for a pair on a single line, it works
fine.  A little more "if" logic in the mapping might do the trick
to check for this.  But that gets kinda ugly pretty fast :)

Hope this helps,

-tim




Reply | Threaded
Open this post in threaded view
|

is there a way to add double quote to the sentence

Vu The Cuong
Hi all,
I just wander is there a way to add double quote to the sentence (not a
single word)
thanks.

Reply | Threaded
Open this post in threaded view
|

Re: is there a way to add double quote to the sentence

Bugzilla from peterp@stack.nl
Op Tuesday 06 September 2005 03:33, schreef Vu The Cuong:
> Hi all,
> I just wander is there a way to add double quote to the sentence (not a
> single word)
> thanks.

Sure, use:
:s/.*/"&"/

Which does the following:
:   enter command-line mode
s   start a substitute command
.*  match everything (on the current line)
"&" replace with a quote, what was matched (&) and another quote


Peter Palm
Reply | Threaded
Open this post in threaded view
|

Re: is there a way to add double quote to the sentence

Dominic Evans
I think he wanted it around a sentence rather than around a line.

Easiest way is just to do it using the movement

<Esc>(i"<Esc>)bi"

<Esc> - command mode
( - move to beginning of sentence
i - insert
" - quote
<Esc> - back to command mode
) - move to beginning of next sentence
b - move back to full stop of previous sentence
i - insert
" - quote

If you actually do that process a lot you can map it to a key/command
quite easily but its probably better just to memorise the ideas behind
it :)

Cheers,
Dom

On 06/09/05, Peter Palm <[hidden email]> wrote:

> Op Tuesday 06 September 2005 03:33, schreef Vu The Cuong:
> > Hi all,
> > I just wander is there a way to add double quote to the sentence (not a
> > single word)
> > thanks.
>
> Sure, use:
> :s/.*/"&"/
>
> Which does the following:
> :   enter command-line mode
> s   start a substitute command
> .*  match everything (on the current line)
> "&" replace with a quote, what was matched (&) and another quote
>
>
> Peter Palm
>
Reply | Threaded
Open this post in threaded view
|

RE: is there a way to add double quote to the sentence

Goli, Rajesh (Rajesh)
In reply to this post by Vu The Cuong
:map <f8> vasv`<i"<esc>`>i"<esc>

v:     enter visual mode
as:    select a sentence
v:     end visual mode
`<:    move to the beginning of previous selection
i:     enter insert mode
":     enter the char "
<esc>: back to normal mode
`>:    move the to end of the previous selection
i":    insert "
<esc>: back to normal mode

-Rajesh

-----Original Message-----
From: Vu The Cuong [mailto:[hidden email]]
Sent: Tuesday, September 06, 2005 7:04 AM
To: [hidden email]
Subject: is there a way to add double quote to the sentence


Hi all,
I just wander is there a way to add double quote to the sentence (not a
single word)
thanks.