ne icon indicating copy to clipboard operation
ne copied to clipboard

[Feature Request] a way to move cursor to end of paste

Open uvtc opened this issue 3 years ago • 6 comments

I posted a question about this to the forum, but thought it deserved a ticket here.

It would be useful if, after a paste, if ne could automatically move the cursor to the location at the end of the pasted content. Currently, ne does not move the cursor when pasting.

I find that most of the time, when I paste something, I want to be typing after what I pasted, rather than before it.

This seems like a good candidate for a default pref, because long-time users may prefer the current behaviour, while new users or those familiar and comfortable with other editors may wish the alternative behaviour.

Another option might be to add a MoveEOP command (move to end of paste).

A third option might be to add another automatic bookmark, for example, ^k gbm +, to take you to the location at the end of the pasted content.

(For those latter 2 options, I suppose if I want the paste behaviour to be automatic, I'd need to create a small macro to paste and then do them, and then map that macro to ^v.)

uvtc avatar Jul 02 '22 16:07 uvtc

The MoveEOP thing seems a good idea and easy to implement. Todd, your opinion?

vigna avatar Jul 03 '22 10:07 vigna

I agree this is a legitimate problem. I have on occasion done a "MoveRight, SetBookMark, MoveLeft, Paste, [...] GotoBookMark" sequence specifically to work around it. But that fails at the end of a document, or at the end of a line if FreeForm is not set, and perhaps other cases.

It might seem like a good candidate for a default pref. But, as per the previous paragraph, behavioral changes due to prefs make writing robust macros much harder, and sometime impossible.

Similarly, we already have lots of commands for moving the cursor. If one of them can address this problem without undue complication, I'd prefer that solution, especially if it has a similar feel to other commands.

In keeping with the NextWord and PrevWord commands, both of which optionally take '<' and '>' flags to indicate which end of the next or previous word to land on, I'm leaning toward having Paste set two automatic bookmarks, such that gmb < and gbm > would take you to the left and right ends of the most recent Paste. This would allow you to move around and keep making changes while keeping either end of your last Paste easy to reach - assuming of course that you don't Erase the text containing the bookmark first. It also seems robust wrt various prefs.

Although not as easy to implement as MoveEOP would be, this feels like the more correct solution to me. If there's no compelling reason not to, I'll start implementation ASAP.

utoddl avatar Jul 03 '22 13:07 utoddl

Setting of automatic bookmarks < and > after a paste would also enable one to bounce back and forth between the start and end of the most recent paste:

^k gbm >
^k gbm -
^k <Ret>     # <--- because ^k remembers the last command I ran
^k <Ret>
...

similar to bouncing back and forth between matching braces. Neat extra feature that I imagine could be useful if you're taking your time writing something, mulling over a recent paste. :)

. . .

BTW, I was surprised and impressed with how smart gbm is. I originally assumed it just kept track of line and col nums, but even if I add lines or other text after setting the bookmark, regardless, gbm still remembers where in the text I was. Powerful feature.

uvtc avatar Jul 03 '22 20:07 uvtc

There is now a paste-sets-bookmarks branch for interested parties to try. Comments welcome.

utoddl avatar Jul 03 '22 22:07 utoddl

Wow!! Thanks, Todd!

The feature works great for me. I tried copy/pasting multiple lines, and also line fragments.

Seems to work correctly with PasteVert as well, but I don't regularly use PasteVert.

I also created a macro: ~/.ne/paste-to-append containing:

Paste
GotoBookmark >

and in my ~/.ne/.keys file, included this:

# Change ^v from Paste to paste-to-append
KEY 16 paste-to-append

Works perfectly! :D Bouncing back and forth works great too.

I see (from the sbm docs, and from trying it) that you can also manually set both the < and > bookmarks, though not sure why you'd want to do that.

Regarding the docs, I noticed that the heading for GotoBookmark is missing the ?.

uvtc avatar Jul 04 '22 01:07 uvtc

For reference, I see that the GotoBookmark doc issue (missing ?) was fixed with 5d18368 .

uvtc avatar Sep 27 '22 02:09 uvtc