0

As far as I can tell, selection in Visual mode using most text objects results in the cursor being placed at the end of the text object region, whether that's linewise or characterwise.

However, using the same text object in Operator-pending mode results in the cursor being placed at the beginning of the text object region after the operation finishes.

For example, some Python code, with cursor indicated by :

print(123)

class Y:
    def g(x│x, yy, zz):
        return

print(456)

If I use gUip, I get:

print(123)

│CLASS Y:
    DEF G(XX, YY, ZZ):
        RETURN

print(456)

But if I use ip in Visual mode, I get:

print(123)

class Y:                ← selected
    def g(xx, yy, zz):  ← selected
│        return         ← selected

print(456)

In Operator-pending mode, the cursor goes to the beginning of the region. In Visual mode, the cursor goes to the end (linewise) of the region.

Is there a reason for this behavior? Historical? Technical? Is there more subtlety to it than I realize?

1 Answer 1

1

This may help explain things, but I don't think it's definitive:

After applying the operator the cursor is mostly left at the start of the text
that was operated upon.  For example, "yfe" doesn't move the cursor, but "yFe"
moves the cursor leftwards to the "e" where the yank started.

[…]

Instead of first giving the operator and then a motion you can use Visual
mode: mark the start of the text with "v", move the cursor to the end of the
text that is to be affected and then hit the operator.  The text between the
start and the cursor position is highlighted, so you can see what text will
be operated upon.  This allows much more freedom, but requires more key
strokes and has limited redo functionality.  See the chapter on Visual mode
|Visual-mode|.

(Part of :help operator.)

In particular, what's missing for me is the explanation of why v{motion}{operator} doesn't reset the cursor position.

Also note that, while I cannot find a reference for this, most Ex commands leave the cursor at the beginning of any range they were applied to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.