Thursday, December 1, 2022

Re: List of changed lines


On Thu, Dec 1, 2022 at 9:52 AM Christian Brabandt <cblists@256bit.org> wrote:

On Do, 01 Dez 2022, Salman Halim wrote:

> Hello,
>
> Is it possible, either natively or through Vim script (I'm happy to write the
> code, but not sure what to look for), to get a list of the lines that have been
> changed since a particular moment?
>
 
I would use one of the undo plugins (like gundo python or undotree
vimscript) plugins for this. I think they also show the diff between
versions.

I even created a plugin histwin when the persistence undo feature was
introduced, that allowed you to tag certain states and allowed to show
you the diff between states

Best,
Christian


Christian,

Thanks for your response. I actually already use Gundo. I'm not trying to visually step through the changes. I literally want to end up with a Vim9 function that, when called with a time (such as for :earlier) or 'since last save', returns me a list of changed lines. I then will use that list to execute commands on those lines, such as removing trailing whitespace or reformatting them.

For various reasons, I am not in a position to do those operations on the entire file, only on the bits I personally changed or added. I noticed that Eclipse has an option to only affect the lines that were explicitly modified, so was wondering if it was possible to do something like that in Vim.

One obvious way would be to have Vim go to the :earlier state, grab the contents of the buffer, come back to 'now' and then manually do a diff to see what's changed. However, that seems expensive for a large file. I was wondering, instead, if there might be a way to somehow get access to the undo information kept by Vim. I tried :wundo, but the file that was written was in a binary format, so wasn't something I could parse.

All the best,

Salman

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEeXHyUS7eMF1SX1_9Vj_XLOtDPDRei1OeEt%2BX%2Bnrrx8pg%40mail.gmail.com.

No comments: