开发者

help - change diff symbol "<", "|" or ">" to a desired one?

diff -w command is used to create a side by side comparison diff file (instead of parallel)

i then view them using vi via ssh terminal the changes are indicated by either "<" or "|" or ">"

Since the file i am viewing is a source code, navigating to changes alone

using above symbols is difficult since they are also in C source code.

How can i change th开发者_开发百科ese default symbols to desired ones ?

Kindly help. Thanks.


Instead of viewing the output of diff -w in vim, you can use vim's built-in diff:

vim -d file1 file2

This opens vim in a vertical split with both files open, and diff markings in the code. This is what it looks like:

help - change diff symbol "<", "|" or ">" to a desired one?

And it works in a terminal too:

help - change diff symbol "<", "|" or ">" to a desired one?

You can find a short tutorial here


According to my version of diff (2.8.1 from the GNU diffutils by the FSF) -w is used to change the width of the output; The -y parameter outputs side by side comparison. In combination, the two show no further effect than the -y parameter used alone, which means you may have an alias in your terminal profile or in the global terminal profile that aliases diff to diff -y.

I say all this because all options to change the symbols ("<", "|", and ">") conflict with the -y option. If you can live without side-by-side, you have the option of two other included output styles or defining your own. The two output styles are -c (context) and -u (unified). (For more information on what they do see the diff Wikipedia page. For more information on the options see the diff man page.)

A more in depth fix would be to use the following options:

diff --old-group-format="(deleted)---" \
     --new-group-format="(added)---" \
     --changed-group-format="(updated)---" \
     --unchanged-group-format="(nodiff)---" \
     old_file.c new_file.c

Now the old file's lines that are not present in the new file are represented by (deleted)---

The new file's lines that are not present in the old file are represented by (added)---

Lines that have been changed are represented by (updated)---

Lines common to both files are represented by (nodiff)---

Since you seem to do this often enough, you have the option of making it an alias in your terminal profile or writing a small shell script to handle it. For more options, see the manual's section on options and specifically see the section on line group formats for information on what you can put between the quotes in the format definitions.

Of course, if you must have side-by-side, try Nathan Fellman's idea above. Otherwise, there's the option of using a dedicated GUI tool for it such as Kompare.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜