4

Moved lines are frequently annotated as deletes and adds but they can be shown as moved-from and moved-to instead.

Like in this screenshot of Notepad++.

Notepad++ diff'ing moved lines

5
  • 1
    I don't get what you want. Can you maybe demonstrate this with a small example?
    – Bernhard
    Commented Jun 28, 2013 at 14:23
  • If you're looking for alternatives to vimdiff & diff just search this site, it's been pretty well covered already: unix.stackexchange.com/questions/tagged/diff
    – slm
    Commented Jun 28, 2013 at 15:30
  • @Bernhard I posted a screen shot of Notepad++ feature of diff'ing moved lines. I'm looking for a cli alternative, preferably in vim.
    – 1.61803
    Commented Jun 28, 2013 at 17:38
  • @slm, I want to diff moved lines preferably in vim.
    – 1.61803
    Commented Jun 28, 2013 at 17:40
  • Wikipedia has a (short) list of tools that can do this. I have only used meld and it can't really detect moved lines (it kinda does) so take the list with a grain of salt.
    – terdon
    Commented Jun 28, 2013 at 18:29

1 Answer 1

1

For its diff view, Vim relies on the output of the diff tool, which consists of line insertions (+) and deletions (-), but no moves. For convenience, Vim is able to highlight changes within a line, but it does not detect moves of (blocks of) lines, unlike Notepad++. You would need to implement this kind of feature yourself (e.g. using the sign column to show the moves).

4
  • could you please elaborate in detail on that implementation in order to mark your answer?
    – 1.61803
    Commented Jun 28, 2013 at 19:21
  • You would need to get the changes (either by querying the Vim buffers for the lines highlighted in the Diff... highlight groups, or by running the diff tool yourself again, write a clever algorithm to detect the moves, and then use :sign place commands to attach the movement markers to the two diff buffers. Commented Jun 28, 2013 at 19:40
  • Alternatively, you could patch the Vim source code itself; getting at the diff information would be easier than in Vimscript. Such a patch (maybe using different colors rather than signs) could even be accepted into mainline Vim! Commented Jun 28, 2013 at 19:42
  • I rather hoped for a vimscript or a more feasible workaround. I leave it open for now.
    – 1.61803
    Commented Jun 28, 2013 at 23:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .