A.J.Mechelynck wrote:
Robert Cussons wrote:

Hi, I think a question like this was posted a long time ago, but I can't remember where or the answer, so please excuse me for asking it again.
If I yank the next word with yw the cursor stays where it is.
However if I want to yank text backwards from my current position for example to get the last word I use yb and the cursor moves to the beginning of the word. As I thought these two motion commands were the inverse and they appear to operate like that, why the difference in their reaction under the y operator?

Thanks
Rob.


The answer doesn't have a help tag, but it is somewhere under the description of the yank command in change.txt:

sorry, did look at the help file, but didn't read the whole section and it was right at the end.... :">


<quote>
Note that after a characterwise yank command, Vim leaves the cursor on the
first yanked character that is closest to the start of the buffer. This means
that "yl" doesn't move the cursor, but "yh" moves the cursor one character
left.
Rationale:      In Vi the "y" command followed by a backwards motion would
sometimes not move the cursor to the first yanked character, because redisplaying was skipped. In Vim it always moves to
                the first character, as specified by Posix.
With a linewise yank command the cursor is put in the first line, but the
column is unmodified, thus it may not be on the first yanked character.
</quote>


Best regards,
Tony.

Few moments pause while I look up what POSIX is........so this method is standard compliant with other Unix systems, but is not so useful for effective text editing IMHO as when I yank text backwards it is because I want to use that text again at some later part of the document (as I like most people, I believe) write documents from start to finish (with a lot of detours admittedly ;-)), so to me it would make more sense to leave the cursor alone. Is this purely a compliance reason then or does someone have some text editing reason for doing it aswell?

If I wanted to change this behaviour, would I be right in thinking that I would have to define the yank command followed by a motion to set a mark, do the yank command then return to that mark? Actually just done a bit of reading in the help file and it appears I don't need marks, I could make use of the `] function, so then all I would want is to change the behaviour of any backwards yank to the same command, but with `] tagged on the end. However, you can only remap single keys can't you, so I guess something like:

nnoremap y<motion> y<motion>`]

wouldn't work, and I wouldn't know how to include the motion without specifying them all individually.

Or is this all a very bad idea and shouldn't be done anyway ;-)

Thanks for any input,
Rob.

Reply via email to