Monday, March 30, 2015

Re: Understanding Vim exclusive motions.

I think i understand what you are saying.  I was misinterpreting the reference manual terms 'start of motion' and 'end of motion'; i was determining start and end of motion based on direction that the cursor moves, which like you said, is not the correct way.

Thanks :),
Arun

On Mon, Mar 30, 2015 at 11:41 AM, Christian Brabandt <cblists@256bit.org> wrote:
Am 2015-03-29 22:46, schrieb arunj:
Hi all,

I have just started with vim, and i need some help.  This is a bit
lengthy, please bear with me :).

I refer to : http://vimdoc.sourceforge.net/htmldoc/motion.html#exclusive.
Specifically, the following text:

Which motions are linewise, inclusive or exclusive is mentioned with the
command.  There are however, two general exceptions:

1. If the motion is exclusive and the end of the motion is in column 1, the
   end of the motion is moved to the end of the previous line and the motion
   becomes inclusive.  Example: `}` moves to the first line after a paragraph,
   but `d}` will not include that line.

Given the following piece of text to start with:

    This is just a random paragraph.

    This is another random paragraph (Some text inside brackets).

    This is a third paragraph.

I start with my cursor on the character `S`, just after the `(`, in
the second paragraph.

I do the following commands - `d}` - in normal mode.  I get the following:

    This is just a random paragraph.

    This is another random paragraph (

    This is a third paragraph.

The cursor is now on the `(` in the second paragraph.  This is
expected as per the rule above: `}` is an exclusive motion, that
causes the cursor to go to column 1 of the blank line between
paragraphs 2 and 3; as per the rule, the cursor goes to the previous
line (on the full-stop), and the motion becomes inclusive (the
full-stop is deleted as part of the `d` operation).

Let's take the original text again, with the cursor again on the `S`.

If i do the following commands - `d{` - in normal mode, i would expect
to get the following, because the `{` is an exclusive motion, and it
causes the cursor to go to column 1 of the blank line between
paragraphs 1 and 2: everything between the full-stop of paragraph 1
and the `S` are deleted, inclusive.

    This is just a random paragraphome text inside brackets).

    This is a third paragraph.

But what actually happens is this:

    This is just a random paragraph.
    Some text inside brackets).

    This is a third paragraph.

With the cursor being on the `S`.

Is this an exception to the exception?  Or am i simply getting it all wrong?

What you are seeing here is, that exclusive/inclusive always works to
that end of the motion that is further away from the buffer's start and
does not depend on the direction of the motion. Therefore the S is not
included in the 'd' command and therefore the empty line won't be joined
with the line above as you expected.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: