behaviour of d_

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

behaviour of d_

esquifit-2
Hi,

Given a file with the following lines (cursor position at '|')

First line
  Second line beginning |with whitespace
Third line

the following commands produce the indicated results:
1) _  goes to first non-blank character in the same line ('S')
2) v_   visually select region between 'S' and cursor position
3) d_  deletes the *whole* second line (even characters after the current cursor position)

1 and 2 work as I'd expect. I don't understand the behaviour of d_ though.
According to :he d

"An exception for the d{motion} command: If the motion is not linewise, the
start and end of the motion are not in the same line, and there are only
blanks before the start and after the end of the motion, the delete becomes
linewise.  This means that the delete also removes the line of blanks that you
might expect to remain."

However this doesn't cover my example since the condition 'start and end of the motion are not in the same line' doesn't apply. I wasn't able to find another documented exception.

Is this a bug or am I missing something?

I'm using Wu Yongwei's build [1] of gvim on Win7:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Nov 22 2012 04:16:46)
MS-Windows 32-bit GUI version with OLE support
Included patches: 1-725
Compiled by Yongwei@Shanghai

[1] http://wyw.dcweb.cn/#download

Same behaviour in Cygwin:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Aug 31 2012 02:21:53)
Included patches: 1-646
Compiled by Cygwin Ports <[hidden email]>


Thanks and regards
e.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

Christian Brabandt
Hi esquifit!

On Sa, 08 Dez 2012, esquifit wrote:

> Hi,
>
> Given a file with the following lines (cursor position at '|')
>
> First line
>   Second line beginning |with whitespace
> Third line
>
> the following commands produce the indicated results:
> 1) _  goes to first non-blank character in the same line ('S')
> 2) v_   visually select region between 'S' and cursor position
> 3) d_  deletes the *whole* second line (even characters after the current cursor position)
>
> 1 and 2 work as I'd expect. I don't understand the behaviour of d_ though.
> According to :he d
>
> "An exception for the d{motion} command: If the motion is not linewise, the
> start and end of the motion are not in the same line, and there are only
> blanks before the start and after the end of the motion, the delete becomes
> linewise.  This means that the delete also removes the line of blanks that you
> might expect to remain."
>
> However this doesn't cover my example since the condition 'start and end of the motion are not in the same line' doesn't apply. I wasn't able to find another documented exception.
>
> Is this a bug or am I missing something?

_ is a linewise motion, so you are deleting the complete line.
You should however be able to use the o_v operator to force the motion
to be characterwise, however, for some reason, this does not seem to
work with d

regards,
Christian
--
Ein Mann, der seine Frau liebt, achtet nicht auf ihr Kleid, sondern
auf seine Frau. Fängt er an, auf die Kleidung zu achten, hat seine
Liebe schon nachgelassen.
                -- Werner Mitsch

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

esquifit-2
In reply to this post by esquifit-2
On Saturday, December 8, 2012 1:17:32 PM UTC+1, esquifit wrote:

> First line
>   Second line beginning |with whitespace
> Third line
>
> the following commands produce the indicated results:
> 1) _  goes to first non-blank character in the same line ('S')
> 2) v_   visually select region between 'S' and cursor position
> 3) d_  deletes the *whole* second line (even characters after the current cursor position)
>
> 1 and 2 work as I'd expect. I don't understand the behaviour of d_ though.

Forget it, found the answer:

http://vim.1045645.n5.nabble.com/Strange-behavior-of-d-td1154470.html

Thanks and regards
e.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

Christian Brabandt
In reply to this post by Christian Brabandt
Hi

On Sa, 08 Dez 2012, Christian Brabandt wrote:

> > Given a file with the following lines (cursor position at '|')
> >
> > First line
> >   Second line beginning |with whitespace
> > Third line
> >
> > the following commands produce the indicated results:
> > 1) _  goes to first non-blank character in the same line ('S')
> > 2) v_   visually select region between 'S' and cursor position
> > 3) d_  deletes the *whole* second line (even characters after the current cursor position)
> >
> > 1 and 2 work as I'd expect. I don't understand the behaviour of d_ though.
> > According to :he d
> >
> > "An exception for the d{motion} command: If the motion is not linewise, the
> > start and end of the motion are not in the same line, and there are only
> > blanks before the start and after the end of the motion, the delete becomes
> > linewise.  This means that the delete also removes the line of blanks that you
> > might expect to remain."
> >
> > However this doesn't cover my example since the condition 'start and end of the motion are not in the same line' doesn't apply. I wasn't able to find another documented exception.
> >
> > Is this a bug or am I missing something?
>
> _ is a linewise motion, so you are deleting the complete line.
> You should however be able to use the o_v operator to force the motion
> to be characterwise, however, for some reason, this does not seem to
> work with d

Bram,
strangely enough, dv_ only works when 'startofline' is set, but
does not, when 'sol' is unset.

This patch fixes it, by making sure, if motion_type_force is set to 'v'
or Ctrl_V 'startofline' option does not apply (as stated by :h 'sol')

(motion_type hasn't been set to MCHAR yet).

diff --git a/src/normal.c b/src/normal.c
--- a/src/normal.c
+++ b/src/normal.c
@@ -8628,7 +8628,9 @@
     cap->oap->motion_type = MLINE;
     if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL)
        clearopbeep(cap->oap);
-    else if (  cap->oap->op_type == OP_DELETE
+    else if (  ( cap->oap->op_type == OP_DELETE /* only with linwise motions */
+               && cap->oap->motion_force != 'v'
+               && cap->oap->motion_force != Ctrl_V)
            || cap->oap->op_type == OP_LSHIFT
            || cap->oap->op_type == OP_RSHIFT)
        beginline(BL_SOL | BL_FIX);


regards,
Christian
--
Jeder Mensch hat ein Brett vor dem Kopf, es kommt nur auf die Entfernung an.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

Bram Moolenaar

Christian Brabandt wrote:

> On Sa, 08 Dez 2012, Christian Brabandt wrote:
>
> > > Given a file with the following lines (cursor position at '|')
> > >
> > > First line
> > >   Second line beginning |with whitespace
> > > Third line
> > >
> > > the following commands produce the indicated results:
> > > 1) _  goes to first non-blank character in the same line ('S')
> > > 2) v_   visually select region between 'S' and cursor position
> > > 3) d_  deletes the *whole* second line (even characters after the current cursor position)
> > >
> > > 1 and 2 work as I'd expect. I don't understand the behaviour of d_ though.
> > > According to :he d
> > >
> > > "An exception for the d{motion} command: If the motion is not linewise, the
> > > start and end of the motion are not in the same line, and there are only
> > > blanks before the start and after the end of the motion, the delete becomes
> > > linewise.  This means that the delete also removes the line of blanks that you
> > > might expect to remain."
> > >
> > > However this doesn't cover my example since the condition 'start and end of the motion are not in the same line' doesn't apply. I wasn't able to find another documented exception.
> > >
> > > Is this a bug or am I missing something?
> >
> > _ is a linewise motion, so you are deleting the complete line.
> > You should however be able to use the o_v operator to force the motion
> > to be characterwise, however, for some reason, this does not seem to
> > work with d
>
> Bram,
> strangely enough, dv_ only works when 'startofline' is set, but
> does not, when 'sol' is unset.
>
> This patch fixes it, by making sure, if motion_type_force is set to 'v'
> or Ctrl_V 'startofline' option does not apply (as stated by :h 'sol')
>
> (motion_type hasn't been set to MCHAR yet).
>
> diff --git a/src/normal.c b/src/normal.c
> --- a/src/normal.c
> +++ b/src/normal.c
> @@ -8628,7 +8628,9 @@
>      cap->oap->motion_type = MLINE;
>      if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL)
>         clearopbeep(cap->oap);
> -    else if (  cap->oap->op_type == OP_DELETE
> +    else if (  ( cap->oap->op_type == OP_DELETE /* only with linwise motions */
> +               && cap->oap->motion_force != 'v'
> +               && cap->oap->motion_force != Ctrl_V)
>             || cap->oap->op_type == OP_LSHIFT
>             || cap->oap->op_type == OP_RSHIFT)
>         beginline(BL_SOL | BL_FIX);

Thanks.  It's probably not difficult to add a test for this...

--
hundred-and-one symptoms of being an internet addict:
124. You begin conversations with, "Who is your internet service provider?"

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

esquifit-2
In reply to this post by Christian Brabandt
On Saturday, December 8, 2012 1:37:52 PM UTC+1, Christian Brabandt wrote:
>
> _ is a linewise motion, so you are deleting the complete line.
> You should however be able to use the o_v operator to force the motion
> to be characterwise, however, for some reason, this does not seem to
> work with d

Hi Christian,
Thanks for your reply. It came almost simultaneously with my own and I didn't notice it until now. Thanks also for the hint regarding startofline.  I have this option set in my system, therefore I can use dv_ without problems.

Regards
e.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

Christian Brabandt
In reply to this post by Bram Moolenaar
Hi Bram!

On Sa, 08 Dez 2012, Bram Moolenaar wrote:

> Thanks.  It's probably not difficult to add a test for this...

Yeah, I thought about this, after I sent the mail. Anyways, here is the
patch including a test.

regards,
Christian
--
Schöpferische Gemüter haben immer gewußt,
wie sie jede Art von schlechter Erziehung überleben.
                -- Anna Freud

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

dv_.diff (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

Christian Brabandt

On So, 09 Dez 2012, Christian Brabandt wrote:
> On Sa, 08 Dez 2012, Bram Moolenaar wrote:
> > Thanks.  It's probably not difficult to add a test for this...
>
> Yeah, I thought about this, after I sent the mail. Anyways, here is the
> patch including a test.

Sorry, small error in the testfile. Here is the correct patch.


regards,
Christian
--
Demokratie ist eine Form der Regierung bei der durch die Wahl einer
inkompetenten Masse eine korrupte Minderheit ernannt wird.
                -- George Bernard Shaw

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

dv_.diff (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

Bram Moolenaar
In reply to this post by Christian Brabandt

Christian Brabandt wrote:

> Hi Bram!
>
> On Sa, 08 Dez 2012, Bram Moolenaar wrote:
>
> > Thanks.  It's probably not difficult to add a test for this...
>
> Yeah, I thought about this, after I sent the mail. Anyways, here is the
> patch including a test.

Thanks!  I think it's a good habit to add a test if we fix something.
It might break again.


--
I'm writing a book.  I've got the page numbers done.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

ping song
On 12/9/2012 9:44 AM, Bram Moolenaar wrote:

> Christian Brabandt wrote:
>
>> Hi Bram!
>>
>> On Sa, 08 Dez 2012, Bram Moolenaar wrote:
>>
>>> Thanks.  It's probably not difficult to add a test for this...
>> Yeah, I thought about this, after I sent the mail. Anyways, here is the
>> patch including a test.
> Thanks!  I think it's a good habit to add a test if we fix something.
> It might break again.
>
>
any, overall, if d_ is same as dd, why bother the complexity? or are
there any extra value of using d_ that I missed?

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

Christian Brabandt
On Mon, December 10, 2012 01:43, ping wrote:
> any, overall, if d_ is same as dd, why bother the complexity? or are
> there any extra value of using d_ that I missed?

The functionality is there and probably also being demanded by POSIX.
But in any case, it should work, no matter what some options are set to.

regards,
Christian

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

Benjamin Fritz
In reply to this post by ping song
On Sunday, December 9, 2012 6:43:23 PM UTC-6, ping wrote:
>
> any, overall, if d_ is same as dd, why bother the complexity? or are
>
> there any extra value of using d_ that I missed?

There is value in the _ motion, which goes to the first non-blank character in a line. It is like ^, but also takes a count to go to a different line than the current in one motion. It is also easier to reach than ^ on a Dvorak keyboard.

There is value in the d command combining with any arbitrary motion command.

dd is provided for an easy way to delete one or more entire lines. The fact that this convenience command does the same thing as combining the d command with certain motions is irrelevant to the usefulness of those motions, and also irrelevant to whether the d command should combine with that motion (it should combine with all motions).

--
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
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of d_

ping song

On 12/10/2012 10:52 AM, Ben Fritz wrote:
> There is value in the _ motion, which goes to the first non-blank character in a line. It is like ^, but also takes a count to go to a different line than the current in one motion. It is also easier to reach than ^ on a Dvorak keyboard.

got it better now, thanks!

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