Thursday, April 28, 2011

Re: why does :copy move the cursor?

On 04/28/2011 12:52 PM, Jean-Rene David wrote:
> Lately I've been using the Ex commands :d, :t, :m to shuffle
> text around while editing.
[snip]
> I wonder why my cursors is *moved* to line 150 after the
> command.
>
> I was wondering if others had thoughts on this behavior. Is
> there a use of them where that behavior makes more sense than
> leaving the cursor where it is?

I often use the following:

:g/pattern/t.|s/./=/g

to "title-ize" (underline with a same-length row of "===") lines
matching /pattern/

I also use something like

:t$s#3/4/2011#3/18/2011

in some of my log-files to copy the current-dated log-line to the
bottom of the file and change the date.

So I can see doing either (move or not-move the cursor), and I
can see use cases for both. Vim's behavior is likely just an
artifact of "ed did it that way, and the original vi did it that
way". Fortunately, my previous location is just a control+O away
for when I want to be at the source location instead of the
destination location.

The one reason I *do* use :m and :t frequently is to swap lines
without trampling my scratch register. I could do

ddp

but it's just about as easy (and mentally hard-coded) to issue

:m+

and preserve my scratch register. Same goes for copying the
line. I could just issue

Yp

but if I want to keep my scratch-register contents, I'll just issue

:t.


> Is there a way I may have overlooked to change that behavior?

I don't know of any option to change the behavior.

Just my use-cases and thoughts on them,

-tim


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

No comments:

Post a Comment