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

1.61803
  • 1,201
  • 2
  • 15
  • 23
  • 1
    I don't get what you want. Can you maybe demonstrate this with a small example? – Bernhard Jun 28 '13 at 14:23
  • If you're looking for alternatives to vimdiff & diff just search this site, it's been pretty well covered already: http://unix.stackexchange.com/questions/tagged/diff – slm Jun 28 '13 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 Jun 28 '13 at 17:38
  • @slm, I want to diff moved lines preferably in vim. – 1.61803 Jun 28 '13 at 17:40
  • Wikipedia has a (short) [list of tools](http://en.wikipedia.org/wiki/Comparison_of_file_comparison_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 Jun 28 '13 at 18:29

1 Answers1

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

Ingo Karkat
  • 11,664
  • 1
  • 34
  • 48
  • could you please elaborate in detail on that implementation in order to mark your answer? – 1.61803 Jun 28 '13 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. – Ingo Karkat Jun 28 '13 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! – Ingo Karkat Jun 28 '13 at 19:42
  • I rather hoped for a vimscript or a more feasible workaround. I leave it open for now. – 1.61803 Jun 28 '13 at 23:47