News for hackers. Stuff that matters.
Re:Resolving the Great Undo-Redo Quandary by quartz on Friday November 11, 2022 @09:31AM (#33561210)
Semi-related: What I really wish all my editors and IDEs would have is some kind of "delete history" view into my deleted text (especially blocks of text).

I'll often delete something, then work for a while, then realize I need that thing back again so I have to VERY carefully undo everything after the delete until I get to a point in history before it, copy the deleted text, then re-do everything back to my original state while making sure not to accidentally execute any inputs which would burn down the redo stack.

Re:Resolving the Great Undo-Redo Quandary by headPoet on Friday November 11, 2022 @09:40AM (#33561357)
A lot of IDEs (I know Eclipse and VSCode both do this) will create a copy of the file you're working on each time you hit save. You can then navigate back through the local history of the file.

I'm conditioned to hit Ctrl+S with almost every change, so this gives me a very detailed history of my revisions.

Re:Resolving the Great Undo-Redo Quandary by lelanthran on Friday November 11, 2022 @09:41AM (#33561368)
Vim stores all deleted text automatically, up to a max of 10, I think.

Probably very possible to extend that with some advanced vimscripting.

Re:Resolving the Great Undo-Redo Quandary by cpcallen on Friday November 11, 2022 @09:44AM (#33561397)
In this thread: people discussing all the excellent features they wish their text editor had that emacs (and/or vim) has had for literally decades.
Re:Resolving the Great Undo-Redo Quandary by JackFr on Friday November 11, 2022 @10:00AM (#33561600)
And/or JetBrains.

Makes me wonder honestly what tool in widespread use doesn’t have this? Notepad?

Re:Resolving the Great Undo-Redo Quandary by nouveaux on Friday November 11, 2022 @09:48AM (#33561465)
Vim supports practically unlimited undo with branching history. You can visualize it and hop to any undo with a plugin.

https://github.com/simnalamburt/vim-mundo

Re:Resolving the Great Undo-Redo Quandary by lelanthran on Friday November 11, 2022 @10:34AM (#33562070)
Yes, but GP wanted something that would just keep all deleted text.

Sort of, anytime you delete something, that text gets stored somewhere in case, 2 hours later, you realised you wanted it.

Re:Resolving the Great Undo-Redo Quandary by quag on Friday November 11, 2022 @11:23AM (#33562734)
Yes, vim’s “set undofile” will create a persistent undo file that stores all changes to the file indefinitely. You can undo changes made months ago over reboots. If you move the undo file between machines, you can undo on different computers.

Undoing a change from 2 hours ago in the same editing session is the trivial use case for undofile.

Re:Resolving the Great Undo-Redo Quandary by lelanthran on Friday November 11, 2022 @05:43PM (#33567853)
But undoing is not what the original commenter wanted.
Re:Resolving the Great Undo-Redo Quandary by quag on Saturday November 12, 2022 @05:57PM (#33578025)
When set undofile is combined with :earlier and :later being used in place of undo and redo I think vim behaves as the author describes.
Re:Resolving the Great Undo-Redo Quandary by vvillena on Friday November 11, 2022 @09:45AM (#33561410)
Jetbrains IDEs can do this using the local history feature. Browse through time on a separate tab, copy what you need, and paste it back into the present.
Re:Resolving the Great Undo-Redo Quandary by Larrikin on Friday November 11, 2022 @10:00AM (#33561612)
Whats even more amazing is that you can right click the package/folder and get local history and see entire files that you previously deleted.

Took me a while to discover this but has saved me almost as many times as local history in a file. Also makes me feel much better when refactoring and deleting tons of old code.

Re:Resolving the Great Undo-Redo Quandary by xixixao on Friday November 11, 2022 @09:46AM (#33561432)
You can use “cut” instead of “delete” and clipboard with history tracking, for example Alfred on macOS.

Then you cut, do some changes, and later on realize you wanted something from the cut code, bring out the clipboard history and fish out what you need.

Re:Resolving the Great Undo-Redo Quandary by tartoran on Friday November 11, 2022 @09:59AM (#33561594)
Yes, but having thousands of snippets in a bucket can be quite confusing too, where do the pieces go back and so on.

For this reason I comment out code then keep it until I’m sure I no longer need it. This works in sessions, and do the final delete, clean up etc at the end of the session before committing the changes to the repo. I see devs keeping commented out code in repos but that adds too much noise, makes the code a real mess..

Re:Resolving the Great Undo-Redo Quandary by chrisshroba on Friday November 11, 2022 @10:05AM (#33561681)
Maccy is a great free and open source clipboard history tool with a nice interface (Alfred requires the power pack purchase for this feature)
Re:Resolving the Great Undo-Redo Quandary by quartz on Friday November 11, 2022 @09:48AM (#33561459)
Oh cool-- are you saying Alfred will let me override the delete key in the case of highlighted text so it always executes a cut instead?
Re:Resolving the Great Undo-Redo Quandary by lyjackal on Friday November 11, 2022 @09:50AM (#33561480)
I think they’re just referring to a clipboard history offered by Alfred, not remapping the delete key
Re:Resolving the Great Undo-Redo Quandary by jorams on Friday November 11, 2022 @03:14PM (#33566193)
Emacs does this by default. Anything you delete ends up in the "kill ring", and you can cycle through that when pasting ("yanking") something. Packages like Consult[1] provide version of the yank-pop command that, instead of cycling through the kill ring, make it searchable.

[1]: https://github.com/minad/consult

Re:Resolving the Great Undo-Redo Quandary by tezza on Friday November 11, 2022 @09:52AM (#33561493)
Eclipse has “local history” for each file save operation.

You can even do a graphical diff against each candidate timestamp in a gui wizard

As others have mentioned JetBrains cloned this feature too

Re:Resolving the Great Undo-Redo Quandary by sporedro on Friday November 11, 2022 @09:53AM (#33561513)
Just a list of tools that have this, in case you use any of them and didn’t know: Vim - has this with undo tree Emacs - has this as well Jetbrains - IDE’s have this with local history they show changes made. VScode has this I’m pretty sure by default otherwise there’s a plug-in for it since I remember doing it. Also just want to add something really cool about vim and undo/redos that relates to this post. With vim your able to “block” or “bunch” your changes which allows you to control what an undo will do. For example, going into insert mode and typing a sentence than exiting insert mode would be one “bunch” and undo would undo that entire sentence. If you wanted to you can control it by leaving insert mode after a adding a single word or making a single edit and that will be what the undo will revert. Probably rambling a bit here, but the concept of controlling what will be undone/redone is a really neat feature of vim.