/usr/share/doc/vim/html/diff.html is in vim-doc 2:8.0.1453-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | <HTML>
<HEAD>
<META HTTP-EQUIV="Content-type" content="text/html; charset=ISO-8859-1">
<TITLE>Vim documentation: diff</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>Vim documentation: diff</H1>
<A NAME="top"></A>
<A HREF="index.html">main help file</A>
<HR>
<PRE>
*<A NAME="diff.txt"></A><B>diff.txt</B>* For Vim version 8.0. Last change: 2017 Oct 03
VIM REFERENCE MANUAL by <A HREF="intro.html#Bram">Bram</A> <A HREF="intro.html#Moolenaar">Moolenaar</A>
*<A NAME="diff"></A><B>diff</B>* *<A NAME="vimdiff"></A><B>vimdiff</B>* *<A NAME="gvimdiff"></A><B>gvimdiff</B>* *<A NAME="diff-mode"></A><B>diff-mode</B>*
This file describes the |<A HREF="various.html#+diff">+diff</A>| feature: Showing differences between two to
eight versions of the same file.
The basics are explained in section |<A HREF="usr_08.html#08.7">08.7</A>| of the user manual.
1. Starting diff mode |<A HREF="#start-vimdiff">start-vimdiff</A>|
2. Viewing diffs |<A HREF="#view-diffs">view-diffs</A>|
3. Jumping to diffs |<A HREF="#jumpto-diffs">jumpto-diffs</A>|
4. Copying diffs |<A HREF="#copy-diffs">copy-diffs</A>|
5. Diff options |<A HREF="#diff-options">diff-options</A>|
{not in Vi}
==============================================================================
1. Starting <A HREF="#diff">diff</A> mode *<A NAME="start-vimdiff"></A><B>start-vimdiff</B>*
The easiest way to start editing in <A HREF="#diff">diff</A> mode is with the "<A HREF="#vimdiff">vimdiff</A>" command.
This starts Vim <A HREF="motion.html#as">as</A> usual, and additionally sets up for viewing the differences
between the arguments.
<B> vimdiff file1 file2 [file3 [file4]]</B>
This is equivalent to:
<B> vim -d file1 file2 [file3 [file4]]</B>
You may also use "<A HREF="#gvimdiff">gvimdiff</A>" or "vim <A HREF="starting.html#-d">-d</A> -g". The <A HREF="gui.html#GUI">GUI</A> is started then.
You may also use "viewdiff" or "gviewdiff". Vim starts in readonly mode then.
"<A HREF="change.html#r">r</A>" may be prepended for restricted mode (see |<A HREF="starting.html#-Z">-Z</A>|).
The second and following arguments may also be a directory name. Vim will
then append the file name of the first argument to the directory name to find
the file.
This only works when a standard "<A HREF="#diff">diff</A>" command is available. See <A HREF="options.html#'diffexpr'">'diffexpr'</A>.
Diffs are local to the current tab page |<A HREF="tabpage.html#tab-page">tab-page</A>|. You can't see diffs with
a <A HREF="windows.html#window">window</A> in another <A HREF="intro.html#tab">tab</A> page. This does make <A HREF="motion.html#it">it</A> possible to have several
diffs at the same time, each in their own <A HREF="intro.html#tab">tab</A> page.
What happens is that Vim opens a <A HREF="windows.html#window">window</A> for each of the files. This is like
using the |<A HREF="starting.html#-O">-O</A>| argument. This uses vertical splits. If you prefer horizontal
splits add the |<A HREF="starting.html#-o">-o</A>| argument:
<B> vimdiff -o file1 file2 [file3 [file4]]</B>
If you always prefer horizontal splits include "horizontal" in <A HREF="options.html#'diffopt'">'diffopt'</A>.
In each of the edited files these <A HREF="options.html#options">options</A> are set:
<A HREF="options.html#'diff'">'diff'</A> on
<A HREF="options.html#'scrollbind'">'scrollbind'</A> on
<A HREF="options.html#'cursorbind'">'cursorbind'</A> on
<A HREF="options.html#'scrollopt'">'scrollopt'</A> includes "hor"
<A HREF="options.html#'wrap'">'wrap'</A> off
<A HREF="options.html#'foldmethod'">'foldmethod'</A> "<A HREF="#diff">diff</A>"
<A HREF="options.html#'foldcolumn'">'foldcolumn'</A> value from <A HREF="options.html#'diffopt'">'diffopt'</A>, default is 2
These <A HREF="options.html#options">options</A> are set local to the <A HREF="windows.html#window">window</A>. When editing another file they are
reset to the global value.
The <A HREF="options.html#options">options</A> can still be overruled from a <A HREF="options.html#modeline">modeline</A> when re-editing the file.
However, <A HREF="options.html#'foldmethod'">'foldmethod'</A> and <A HREF="options.html#'wrap'">'wrap'</A> won't be set from a <A HREF="options.html#modeline">modeline</A> when <A HREF="options.html#'diff'">'diff'</A> is
set.
The differences shown are actually the differences in the buffer. Thus if you
make changes after loading a file, these will be included in the displayed
diffs. You might have to <A HREF="#do">do</A> "<A HREF="#:diffupdate">:diffupdate</A>" now and then, not all changes are
immediately taken into account.
In your <A HREF="starting.html#.vimrc">.vimrc</A> file you could <A HREF="#do">do</A> something special when Vim was started in
<A HREF="#diff">diff</A> mode. You could use a construct like this:
<B> if &diff</B>
<B> setup for diff mode</B>
<B> else</B>
<B> setup for non-diff mode</B>
<B> endif</B>
While already in Vim you can start <A HREF="#diff">diff</A> mode in three ways.
*<A NAME="E98"></A><B>E98</B>*
:diffs[plit] {filename} *<A NAME=":diffs"></A><B>:diffs</B>* *<A NAME=":diffsplit"></A><B>:diffsplit</B>*
Open a new <A HREF="windows.html#window">window</A> on the file {filename}. The <A HREF="options.html#options">options</A> are set
<A HREF="motion.html#as">as</A> for "<A HREF="#vimdiff">vimdiff</A>" for the current and the newly opened <A HREF="windows.html#window">window</A>.
Also see <A HREF="options.html#'diffexpr'">'diffexpr'</A>.
*<A NAME=":difft"></A><B>:difft</B>* *<A NAME=":diffthis"></A><B>:diffthis</B>*
:difft[his] Make the current <A HREF="windows.html#window">window</A> part of the <A HREF="#diff">diff</A> <A HREF="windows.html#windows">windows</A>. This sets
the <A HREF="options.html#options">options</A> like for "<A HREF="#vimdiff">vimdiff</A>".
:diffp[atch] {patchfile} *<A NAME="E816"></A><B>E816</B>* *<A NAME=":diffp"></A><B>:diffp</B>* *<A NAME=":diffpatch"></A><B>:diffpatch</B>*
Use the current buffer, patch <A HREF="motion.html#it">it</A> with the <A HREF="#diff">diff</A> found in
{patchfile} and open a buffer on the result. The <A HREF="options.html#options">options</A> are
set <A HREF="motion.html#as">as</A> for "<A HREF="#vimdiff">vimdiff</A>".
{patchfile} can be in any format that the "patch" program
understands or <A HREF="options.html#'patchexpr'">'patchexpr'</A> can handle.
Note that {patchfile} should only contain a <A HREF="#diff">diff</A> for one file,
the current file. If {patchfile} contains diffs for other
files <A HREF="motion.html#as">as</A> well, the results are unpredictable. Vim changes
directory to /tmp to avoid files in the current directory
accidentally being patched. But <A HREF="motion.html#it">it</A> may still result in
various ".rej" files to be created. And when absolute path
names are present these files may get patched anyway.
To make these commands use a vertical split, prepend |<A HREF="windows.html#:vertical">:vertical</A>|. Examples:
<B> :vert diffsplit main.c~</B>
<B> :vert diffpatch /tmp/diff</B>
If you always prefer a vertical split include "vertical" in <A HREF="options.html#'diffopt'">'diffopt'</A>.
*<A NAME="E96"></A><B>E96</B>*
There can be up to eight <A HREF="windows.html#buffers">buffers</A> with <A HREF="options.html#'diff'">'diff'</A> set.
Since the option values are remembered with the buffer, you can edit another
file for a moment and come back to the same file and be in <A HREF="#diff">diff</A> mode again.
*<A NAME=":diffo"></A><B>:diffo</B>* *<A NAME=":diffoff"></A><B>:diffoff</B>*
:diffo[ff] Switch off <A HREF="#diff">diff</A> mode for the current <A HREF="windows.html#window">window</A>. Resets related
<A HREF="options.html#options">options</A> also when <A HREF="options.html#'diff'">'diff'</A> was not set.
:diffo[ff]! Switch off <A HREF="#diff">diff</A> mode for the current <A HREF="windows.html#window">window</A> and in all <A HREF="windows.html#windows">windows</A>
in the current <A HREF="intro.html#tab">tab</A> page where <A HREF="options.html#'diff'">'diff'</A> is set. Resetting
related <A HREF="options.html#options">options</A> only happens in a <A HREF="windows.html#window">window</A> that has <A HREF="options.html#'diff'">'diff'</A> set,
if the current <A HREF="windows.html#window">window</A> does not have <A HREF="options.html#'diff'">'diff'</A> set then no <A HREF="options.html#options">options</A>
in <A HREF="motion.html#it">it</A> are changed.
Hidden <A HREF="windows.html#buffers">buffers</A> are also removed from the <A HREF="eval.html#list">list</A> of diff'ed
<A HREF="windows.html#buffers">buffers</A>.
The `:diffoff` command resets the relevant <A HREF="options.html#options">options</A> to the values they had when
using `:diffsplit`, `:diffpatch` , `:diffthis`. or starting Vim in <A HREF="#diff">diff</A> mode.
When using `:diffoff` <A HREF="if_cscop.html#twice">twice</A> the last saved values are restored.
Otherwise they are set to their default value:
<A HREF="options.html#'diff'">'diff'</A> off
<A HREF="options.html#'scrollbind'">'scrollbind'</A> off
<A HREF="options.html#'cursorbind'">'cursorbind'</A> off
<A HREF="options.html#'scrollopt'">'scrollopt'</A> without "hor"
<A HREF="options.html#'wrap'">'wrap'</A> on
<A HREF="options.html#'foldmethod'">'foldmethod'</A> "manual"
<A HREF="options.html#'foldcolumn'">'foldcolumn'</A> 0
==============================================================================
2. Viewing diffs *<A NAME="view-diffs"></A><B>view-diffs</B>*
The effect is that the <A HREF="#diff">diff</A> <A HREF="windows.html#windows">windows</A> show the same text, with the differences
highlighted. When <A HREF="scroll.html#scrolling">scrolling</A> the text, the <A HREF="options.html#'scrollbind'">'scrollbind'</A> option will make the
text in other <A HREF="windows.html#windows">windows</A> to be scrolled <A HREF="motion.html#as">as</A> well. With vertical splits the text
should be aligned properly.
The alignment of text will go wrong when:
- <A HREF="options.html#'wrap'">'wrap'</A> is on, some lines will be wrapped and occupy two or more screen
lines
- <A HREF="fold.html#folds">folds</A> are open in one <A HREF="windows.html#window">window</A> but not another
- <A HREF="options.html#'scrollbind'">'scrollbind'</A> is off
- changes have been made to the text
- "filler" is not present in <A HREF="options.html#'diffopt'">'diffopt'</A>, deleted/inserted lines makes the
alignment go wrong
All the <A HREF="windows.html#buffers">buffers</A> edited in a <A HREF="windows.html#window">window</A> where the <A HREF="options.html#'diff'">'diff'</A> option is set will join in
the <A HREF="#diff">diff</A>. This is also possible for hidden <A HREF="windows.html#buffers">buffers</A>. They must have been
edited in a <A HREF="windows.html#window">window</A> first for this to be possible. To get rid of the hidden
<A HREF="windows.html#buffers">buffers</A> use `:diffoff!`.
*<A NAME=":DiffOrig"></A><B>:DiffOrig</B>* *<A NAME="diff-original-file"></A><B>diff-original-file</B>*
Since <A HREF="options.html#'diff'">'diff'</A> is a window-local option, it's possible to <A HREF="starting.html#view">view</A> the same buffer
in <A HREF="#diff">diff</A> mode in one <A HREF="windows.html#window">window</A> and "normal" in another <A HREF="windows.html#window">window</A>. It is also
possible to <A HREF="starting.html#view">view</A> the changes you have made to a buffer since the file was
loaded. Since Vim doesn't allow having two <A HREF="windows.html#buffers">buffers</A> for the same file, you
need another buffer. This command is useful:
<B> command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_</B>
<B> \ | diffthis | wincmd p | diffthis</B>
(this is in |<A HREF="vimrc_example.html">vimrc_example.vim</A>|). Use "<A HREF="#:DiffOrig">:DiffOrig</A>" to see the differences
between the current buffer and the file <A HREF="motion.html#it">it</A> was loaded from.
A buffer that is unloaded cannot be used for the <A HREF="#diff">diff</A>. But <A HREF="motion.html#it">it</A> does work for
hidden <A HREF="windows.html#buffers">buffers</A>. You can use "<A HREF="windows.html#:hide">:hide</A>" to close a <A HREF="windows.html#window">window</A> without unloading the
buffer. If you don't want a buffer to remain used for the <A HREF="#diff">diff</A> <A HREF="#do">do</A> "<A HREF="options.html#:set">:set</A>
nodiff" before hiding <A HREF="motion.html#it">it</A>.
*<A NAME=":dif"></A><B>:dif</B>* *<A NAME=":diffupdate"></A><B>:diffupdate</B>*
:dif[fupdate][!] Update the <A HREF="#diff">diff</A> highlighting and <A HREF="fold.html#folds">folds</A>.
Vim attempts to keep the differences updated when you make changes to the
text. This mostly takes care of inserted and deleted lines. Changes within a
line and more complicated changes <A HREF="#do">do</A> not cause the differences to be updated.
To force the differences to be updated use:
<B> :diffupdate</B>
If the ! is included Vim will check if the file was changed externally and
needs to be reloaded. It will prompt for each changed file, like `:checktime`
was used.
Vim will show filler lines for lines that are missing in one <A HREF="windows.html#window">window</A> but are
present in another. These lines were inserted in another file or deleted in
this file. Removing "filler" from the <A HREF="options.html#'diffopt'">'diffopt'</A> option will make Vim not
display these filler lines.
Folds are used to hide the text that wasn't changed. See |<A HREF="fold.html#folding">folding</A>| for all
the commands that can be used with <A HREF="fold.html#folds">folds</A>.
The context of lines above a difference that are not included in the fold can
be set with the <A HREF="options.html#'diffopt'">'diffopt'</A> option. For example, to set the context to three
lines:
<B> :set diffopt=filler,context:3</B>
The diffs are highlighted with these groups:
|<A HREF="syntax.html#hl-DiffAdd">hl-DiffAdd</A>| DiffAdd Added (inserted) lines. These lines exist in
this buffer but not in another.
|<A HREF="syntax.html#hl-DiffChange">hl-DiffChange</A>| DiffChange Changed lines.
|<A HREF="syntax.html#hl-DiffText">hl-DiffText</A>| DiffText Changed text inside a Changed line. Vim
finds the first character that is different,
and the last character that is different
(searching from the end of the line). The
text in between is highlighted. This means
that parts in the middle that are still the
same are highlighted anyway. The <A HREF="options.html#'diffopt'">'diffopt'</A>
flags "iwhite" and "icase" are used here.
|<A HREF="syntax.html#hl-DiffDelete">hl-DiffDelete</A>| DiffDelete Deleted lines. Also called filler lines,
because they don't really exist in this
buffer.
==============================================================================
3. Jumping to diffs *<A NAME="jumpto-diffs"></A><B>jumpto-diffs</B>*
Two commands can be used to jump to diffs:
*<A NAME="[c"></A><B>[c</B>*
<A HREF="#[c">[c</A> Jump backwards to the previous start of a change.
When a <A HREF="intro.html#count">count</A> is used, <A HREF="#do">do</A> <A HREF="motion.html#it">it</A> that many times.
*<A NAME="]c"></A><B>]c</B>*
<A HREF="#]c">]c</A> Jump forwards to the next start of a change.
When a <A HREF="intro.html#count">count</A> is used, <A HREF="#do">do</A> <A HREF="motion.html#it">it</A> that many times.
It is an error if there is no change for the cursor to move to.
==============================================================================
4. Diff <A HREF="uganda.html#copying">copying</A> *<A NAME="copy-diffs"></A><B>copy-diffs</B>* *<A NAME="E99"></A><B>E99</B>* *<A NAME="E100"></A><B>E100</B>* *<A NAME="E101"></A><B>E101</B>* *<A NAME="E102"></A><B>E102</B>* *<A NAME="E103"></A><B>E103</B>*
*<A NAME="merge"></A><B>merge</B>*
There are two commands to copy text from one buffer to another. The result is
that the <A HREF="windows.html#buffers">buffers</A> will be equal within the specified range.
*<A NAME=":diffg"></A><B>:diffg</B>* *<A NAME=":diffget"></A><B>:diffget</B>*
:[range]diffg[et] [bufspec]
Modify the current buffer to <A HREF="undo.html#undo">undo</A> difference with another
buffer. If [bufspec] is given, that buffer is used. If
[bufspec] refers to the current buffer then nothing happens.
Otherwise this only works if there is one other buffer in <A HREF="#diff">diff</A>
mode.
See below for <A HREF="cmdline.html#[range]">[range]</A>.
*<A NAME=":diffpu"></A><B>:diffpu</B>* *<A NAME=":diffput"></A><B>:diffput</B>* *<A NAME="E793"></A><B>E793</B>*
:[range]diffpu[t] [bufspec]
Modify another buffer to <A HREF="undo.html#undo">undo</A> difference with the current
buffer. Just like "<A HREF="#:diffget">:diffget</A>" but the other buffer is modified
instead of the current one.
When [bufspec] is omitted and there is more than one other
buffer in <A HREF="#diff">diff</A> mode where <A HREF="options.html#'modifiable'">'modifiable'</A> is set this fails.
See below for <A HREF="cmdline.html#[range]">[range]</A>.
*<A NAME="do"></A><B>do</B>*
[count]do Same <A HREF="motion.html#as">as</A> "<A HREF="#:diffget">:diffget</A>" without range. The "<A HREF="insert.html#o">o</A>" stands for "obtain"
("dg" can't be used, <A HREF="motion.html#it">it</A> could be the start of "dgg"!). Note:
this doesn't work in <A HREF="visual.html#Visual">Visual</A> mode.
If you give a <A HREF="intro.html#[count]">[count]</A>, <A HREF="motion.html#it">it</A> is used <A HREF="motion.html#as">as</A> the [bufspec] argument
for "<A HREF="#:diffget">:diffget</A>".
*<A NAME="dp"></A><B>dp</B>*
[count]dp Same <A HREF="motion.html#as">as</A> "<A HREF="#:diffput">:diffput</A>" without range. Note: this doesn't work in
<A HREF="visual.html#Visual">Visual</A> mode.
If you give a <A HREF="intro.html#[count]">[count]</A>, <A HREF="motion.html#it">it</A> is used <A HREF="motion.html#as">as</A> the [bufspec] argument
for "<A HREF="#:diffput">:diffput</A>".
When no <A HREF="cmdline.html#[range]">[range]</A> is given, the <A HREF="#diff">diff</A> at the cursor position or just above <A HREF="motion.html#it">it</A> is
affected. When <A HREF="cmdline.html#[range]">[range]</A> is used, Vim tries to only put or get the specified
lines. When there are deleted lines, this may not always be possible.
There can be deleted lines below the last line of the buffer. When the cursor
is on the last line in the buffer and there is no <A HREF="#diff">diff</A> above this line, the
"<A HREF="#:diffget">:diffget</A>" and "<A HREF="#do">do</A>" commands will obtain lines from the other buffer.
To be able to get those lines from another buffer in a <A HREF="cmdline.html#[range]">[range]</A> it's allowed to
use the last line number plus one. This command gets all diffs from the other
buffer:
<B> :1,$+1diffget</B>
Note that deleted lines are displayed, but not counted <A HREF="motion.html#as">as</A> text lines. You
can't move the cursor into them. To fill the deleted lines with the lines
from another buffer use "<A HREF="#:diffget">:diffget</A>" on the line below them.
*<A NAME="E787"></A><B>E787</B>*
When the buffer that is about to be modified is read-only and the <A HREF="autocmd.html#autocommand">autocommand</A>
that is triggered by |<A HREF="autocmd.html#FileChangedRO">FileChangedRO</A>| changes <A HREF="windows.html#buffers">buffers</A> the command will fail.
The <A HREF="autocmd.html#autocommand">autocommand</A> must not change <A HREF="windows.html#buffers">buffers</A>.
The [bufspec] argument above can be a buffer number, a <A HREF="pattern.html#pattern">pattern</A> for a buffer
name or a part of a buffer name. Examples:
<A HREF="#:diffget">:diffget</A> Use the other buffer which is in <A HREF="#diff">diff</A> mode
<A HREF="#:diffget">:diffget</A> 3 Use buffer 3
<A HREF="#:diffget">:diffget</A> v2 Use the buffer which matches "v2" and is in
<A HREF="#diff">diff</A> mode (e.g., "file.c.v2")
==============================================================================
5. Diff <A HREF="options.html#options">options</A> *<A NAME="diff-options"></A><B>diff-options</B>*
Also see |<A HREF="options.html#'diffopt'">'diffopt'</A>| and the "diff" item of |<A HREF="options.html#'fillchars'">'fillchars'</A>|.
*<A NAME="diff-slow"></A><B>diff-slow</B>* *<A NAME="diff_translations"></A><B>diff_translations</B>*
For very long lines, the <A HREF="#diff">diff</A> <A HREF="syntax.html#syntax">syntax</A> highlighting might be slow, especially
since <A HREF="motion.html#it">it</A> tries to match all different kind of localisations. To disable
localisations and speed up the <A HREF="syntax.html#syntax">syntax</A> highlighting, set the global variable
g:diff_translations to zero:
<B> let g:diff_translations = 0</B>
After setting this variable, <A HREF="editing.html#reload">reload</A> the <A HREF="syntax.html#syntax">syntax</A> <A HREF="usr_41.html#script">script</A>:
<B> set syntax=diff</B>
FINDING THE DIFFERENCES *<A NAME="diff-diffexpr"></A><B>diff-diffexpr</B>*
The <A HREF="options.html#'diffexpr'">'diffexpr'</A> option can be set to use something else than the standard
"<A HREF="#diff">diff</A>" program to compare two files and find the differences.
When <A HREF="options.html#'diffexpr'">'diffexpr'</A> is empty, Vim uses this command to find the differences
between file1 and file2:
<B> diff file1 file2 > outfile</B>
The "<A HREF="change.html#>">></A>" is replaced with the value of <A HREF="options.html#'shellredir'">'shellredir'</A>.
The output of "<A HREF="#diff">diff</A>" must be a normal "ed" style <A HREF="#diff">diff</A>. Do NOT use a context
<A HREF="#diff">diff</A>. This example explains the format that Vim expects:
<B> 1a2</B>
<B> > bbb</B>
<B> 4d4</B>
<B> < 111</B>
<B> 7c7</B>
<B> < GGG</B>
<B> ---</B>
<B> > ggg</B>
The "1a2" item appends the line "bbb".
The "4d4" item deletes the line "111".
The "7c7" item replaces the line "GGG" with "ggg".
When <A HREF="options.html#'diffexpr'">'diffexpr'</A> is not empty, Vim evaluates <A HREF="motion.html#it">it</A> to obtain a <A HREF="#diff">diff</A> file in the
format mentioned. These <A HREF="eval.html#variables">variables</A> are set to the file names used:
<A HREF="eval.html#v:fname_in">v:fname_in</A> original file
<A HREF="eval.html#v:fname_new">v:fname_new</A> new version of the same file
<A HREF="eval.html#v:fname_out">v:fname_out</A> resulting <A HREF="#diff">diff</A> file
Additionally, <A HREF="options.html#'diffexpr'">'diffexpr'</A> should take care of "icase" and "iwhite" in the
<A HREF="options.html#'diffopt'">'diffopt'</A> option. <A HREF="options.html#'diffexpr'">'diffexpr'</A> cannot change the value of <A HREF="options.html#'lines'">'lines'</A> and
<A HREF="options.html#'columns'">'columns'</A>.
Example (this does almost the same <A HREF="motion.html#as">as</A> <A HREF="options.html#'diffexpr'">'diffexpr'</A> being empty):
<B> set diffexpr=MyDiff()</B>
<B> function MyDiff()</B>
<B> let opt = ""</B>
<B> if &diffopt =~ "icase"</B>
<B> let opt = opt . "-i "</B>
<B> endif</B>
<B> if &diffopt =~ "iwhite"</B>
<B> let opt = opt . "-b "</B>
<B> endif</B>
<B> silent execute "!diff -a --binary " . opt . v:fname_in . " " . v:fname_new .</B>
<B> \ " > " . v:fname_out</B>
<B> endfunction</B>
The "-a" argument is used to force comparing the files <A HREF="motion.html#as">as</A> text, comparing <A HREF="motion.html#as">as</A>
binaries isn't useful. The "--binary" argument makes the files read in binary
mode, so that a <A HREF="starting.html#CTRL-Z">CTRL-Z</A> doesn't end the text on <A HREF="os_dos.html#DOS">DOS</A>.
*<A NAME="E810"></A><B>E810</B>* *<A NAME="E97"></A><B>E97</B>*
Vim will <A HREF="#do">do</A> a test if the <A HREF="#diff">diff</A> output looks alright. If <A HREF="motion.html#it">it</A> doesn't, you will
get an error message. Possible causes:
- The "<A HREF="#diff">diff</A>" program cannot be executed.
- The "<A HREF="#diff">diff</A>" program doesn't produce normal "ed" style diffs (see above).
- The <A HREF="options.html#'shell'">'shell'</A> and associated <A HREF="options.html#options">options</A> are not set correctly. Try if filtering
works with a command like ":!sort".
- You are using <A HREF="options.html#'diffexpr'">'diffexpr'</A> and <A HREF="motion.html#it">it</A> doesn't work.
If it's not clear what the problem is set the <A HREF="options.html#'verbose'">'verbose'</A> option to one or more
to see more <A HREF="message.html#messages">messages</A>.
The self-installing Vim for <A HREF="os_win32.html#MS-Windows">MS-Windows</A> includes a <A HREF="#diff">diff</A> program. If you don't
have <A HREF="motion.html#it">it</A> you might want to <A HREF="intro.html#download">download</A> a diff.exe. For example from
<A HREF="http://gnuwin32.sourceforge.net/packages/diffutils.htm">http://gnuwin32.sourceforge.net/packages/diffutils.htm</A>.
USING PATCHES *<A NAME="diff-patchexpr"></A><B>diff-patchexpr</B>*
The <A HREF="options.html#'patchexpr'">'patchexpr'</A> option can be set to use something else than the standard
"patch" program.
When <A HREF="options.html#'patchexpr'">'patchexpr'</A> is empty, Vim will call the "patch" program like this:
<B> patch -o outfile origfile < patchfile</B>
This should work fine with most versions of the "patch" program. Note that a
CR in the middle of a line may cause problems, <A HREF="motion.html#it">it</A> is seen <A HREF="motion.html#as">as</A> a line break.
If the default doesn't work for you, set the <A HREF="options.html#'patchexpr'">'patchexpr'</A> to an <A HREF="eval.html#expression">expression</A> that
will have the same effect. These <A HREF="eval.html#variables">variables</A> are set to the file names used:
<A HREF="eval.html#v:fname_in">v:fname_in</A> original file
<A HREF="eval.html#v:fname_diff">v:fname_diff</A> patch file
<A HREF="eval.html#v:fname_out">v:fname_out</A> resulting patched file
Example (this does the same <A HREF="motion.html#as">as</A> <A HREF="options.html#'patchexpr'">'patchexpr'</A> being empty):
<B> set patchexpr=MyPatch()</B>
<B> function MyPatch()</B>
<B> :call system("patch -o " . v:fname_out . " " . v:fname_in .</B>
<B> \ " < " . v:fname_diff)</B>
<B> endfunction</B>
Make sure that using the "patch" program doesn't have unwanted side effects.
For example, watch out for additionally generated files, which should be
deleted. It should just patch the file and nothing else.
Vim will change directory to "/tmp" or another temp directory before
evaluating <A HREF="options.html#'patchexpr'">'patchexpr'</A>. This hopefully avoids that files in the current
directory are accidentally patched. Vim will also delete files starting with
<A HREF="eval.html#v:fname_in">v:fname_in</A> and ending in ".rej" and ".orig".
<A HREF="#top">top</A> - <A HREF="index.html">main help file</A>
</PRE>
</BODY>
</HTML>
|