代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>diff - Vim Documentation</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim8.0">
<meta name="syntax" content="help">
<meta name="settings" content="no_pre,use_css,expand_tabs">
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="mark-current-page.js" type="text/javascript"></script>
</head>
<body>
<header>
<div class="header">
<a href="http://vim-jp.org/">vim-jp</a>
/ <a href="http://vim-jp.org/vimdoc-en/">vimdoc-en</a>
/ diff<br />
<a name="top"></a><h1>diff - Vim Documentation</h1>
<a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
</div>
</header>
<nav>
<dl>
<dt>BASIC</dt>
<dd><ul>
<li><a href="quickref.html">quickref</a></li>
<li><a href="sponsor.html">sponsor</a></li>
</ul></dd>
<dt>USER MANUAL</dt>
<dd><ul>
<li><a href="usr_toc.html">usr_toc</a></li>
</ul></dd>
<dt>Getting Started</dt>
<dd><ul>
<li><a href="usr_01.html">usr_01</a></li>
<li><a href="usr_02.html">usr_02</a></li>
<li><a href="usr_03.html">usr_03</a></li>
<li><a href="usr_04.html">usr_04</a></li>
<li><a href="usr_05.html">usr_05</a></li>
<li><a href="usr_06.html">usr_06</a></li>
<li><a href="usr_07.html">usr_07</a></li>
<li><a href="usr_08.html">usr_08</a></li>
<li><a href="usr_09.html">usr_09</a></li>
<li><a href="usr_10.html">usr_10</a></li>
<li><a href="usr_11.html">usr_11</a></li>
<li><a href="usr_12.html">usr_12</a></li>
</ul></dd>
<dt>Editing Effectively</dt>
<dd><ul>
<li><a href="usr_20.html">usr_20</a></li>
<li><a href="usr_21.html">usr_21</a></li>
<li><a href="usr_22.html">usr_22</a></li>
<li><a href="usr_23.html">usr_23</a></li>
<li><a href="usr_24.html">usr_24</a></li>
<li><a href="usr_25.html">usr_25</a></li>
<li><a href="usr_26.html">usr_26</a></li>
<li><a href="usr_27.html">usr_27</a></li>
<li><a href="usr_28.html">usr_28</a></li>
<li><a href="usr_29.html">usr_29</a></li>
<li><a href="usr_30.html">usr_30</a></li>
<li><a href="usr_31.html">usr_31</a></li>
<li><a href="usr_32.html">usr_32</a></li>
</ul></dd>
<dt>Tuning Vim</dt>
<dd><ul>
<li><a href="usr_40.html">usr_40</a></li>
<li><a href="usr_41.html">usr_41</a></li>
<li><a href="usr_42.html">usr_42</a></li>
<li><a href="usr_43.html">usr_43</a></li>
<li><a href="usr_44.html">usr_44</a></li>
<li><a href="usr_45.html">usr_45</a></li>
</ul></dd>
<dt>Making Vim Run</dt>
<dd><ul>
<li><a href="usr_90.html">usr_90</a></li>
</ul></dd>
<dt>General subjects</dt>
<dd><ul>
<li><a href="intro.html">intro</a></li>
<li><a href="index.html">help</a></li>
<li><a href="helphelp.html">helphelp</a></li>
<li><a href="vimindex.html">index</a></li>
<li><a href="tags.html">tags</a></li>
<li><a href="howto.html">howto</a></li>
<li><a href="tips.html">tips</a></li>
<li><a href="message.html">message</a></li>
<li><a href="quotes.html">quotes</a></li>
<li><a href="todo.html">todo</a></li>
<li><a href="debug.html">debug</a></li>
<li><a href="develop.html">develop</a></li>
<li><a href="uganda.html">uganda</a></li>
</ul></dd>
<dt>Basic editing</dt>
<dd><ul>
<li><a href="starting.html">starting</a></li>
<li><a href="editing.html">editing</a></li>
<li><a href="motion.html">motion</a></li>
<li><a href="scroll.html">scroll</a></li>
<li><a href="insert.html">insert</a></li>
<li><a href="change.html">change</a></li>
<li><a href="indent.html">indent</a></li>
<li><a href="undo.html">undo</a></li>
<li><a href="repeat.html">repeat</a></li>
<li><a href="visual.html">visual</a></li>
<li><a href="various.html">various</a></li>
<li><a href="recover.html">recover</a></li>
</ul></dd>
<dt>Advanced editing</dt>
<dd><ul>
<li><a href="cmdline.html">cmdline</a></li>
<li><a href="options.html">options</a></li>
<li><a href="pattern.html">pattern</a></li>
<li><a href="map.html">map</a></li>
<li><a href="tagsrch.html">tagsrch</a></li>
<li><a href="quickfix.html">quickfix</a></li>
<li><a href="windows.html">windows</a></li>
<li><a href="tabpage.html">tabpage</a></li>
<li><a href="syntax.html">syntax</a></li>
<li><a href="spell.html">spell</a></li>
<li><a href="diff.html">diff</a></li>
<li><a href="autocmd.html">autocmd</a></li>
<li><a href="filetype.html">filetype</a></li>
<li><a href="eval.html">eval</a></li>
<li><a href="channel.html">channel</a></li>
<li><a href="fold.html">fold</a></li>
</ul></dd>
<dt>Special issues</dt>
<dd><ul>
<li><a href="print.html">print</a></li>
<li><a href="remote.html">remote</a></li>
<li><a href="term.html">term</a></li>
<li><a href="digraph.html">digraph</a></li>
<li><a href="mbyte.html">mbyte</a></li>
<li><a href="mlang.html">mlang</a></li>
<li><a href="arabic.html">arabic</a></li>
<li><a href="farsi.html">farsi</a></li>
<li><a href="hebrew.html">hebrew</a></li>
<li><a href="russian.html">russian</a></li>
<li><a href="ft_ada.html">ft_ada</a></li>
<li><a href="ft_sql.html">ft_sql</a></li>
<li><a href="hangulin.html">hangulin</a></li>
<li><a href="rileft.html">rileft</a></li>
</ul></dd>
<dt>GUI</dt>
<dd><ul>
<li><a href="gui.html">gui</a></li>
<li><a href="gui_w32.html">gui_w32</a></li>
<li><a href="gui_x11.html">gui_x11</a></li>
</ul></dd>
<dt>Interfaces</dt>
<dd><ul>
<li><a href="if_cscop.html">if_cscop</a></li>
<li><a href="if_lua.html">if_lua</a></li>
<li><a href="if_mzsch.html">if_mzsch</a></li>
<li><a href="if_perl.html">if_perl</a></li>
<li><a href="if_pyth.html">if_pyth</a></li>
<li><a href="if_tcl.html">if_tcl</a></li>
<li><a href="if_ole.html">if_ole</a></li>
<li><a href="if_ruby.html">if_ruby</a></li>
<li><a href="debugger.html">debugger</a></li>
<li><a href="workshop.html">workshop</a></li>
<li><a href="netbeans.html">netbeans</a></li>
<li><a href="sign.html">sign</a></li>
</ul></dd>
<dt>Versions</dt>
<dd><ul>
<li><a href="vi_diff.html">vi_diff</a></li>
<li><a href="version4.html">version4</a></li>
<li><a href="version5.html">version5</a></li>
<li><a href="version6.html">version6</a></li>
<li><a href="version7.html">version7</a></li>
<li><a href="version8.html">version8</a></li>
</ul></dd>
<dt>Remarks about specific systems</dt>
<dd><ul>
<li><a href="os_390.html">os_390</a></li>
<li><a href="os_amiga.html">os_amiga</a></li>
<li><a href="os_beos.html">os_beos</a></li>
<li><a href="os_dos.html">os_dos</a></li>
<li><a href="os_mac.html">os_mac</a></li>
<li><a href="os_mint.html">os_mint</a></li>
<li><a href="os_msdos.html">os_msdos</a></li>
<li><a href="os_os2.html">os_os2</a></li>
<li><a href="os_qnx.html">os_qnx</a></li>
<li><a href="os_risc.html">os_risc</a></li>
<li><a href="os_unix.html">os_unix</a></li>
<li><a href="os_vms.html">os_vms</a></li>
<li><a href="os_win32.html">os_win32</a></li>
</ul></dd>
<dt>Standard plugins</dt>
<dd><ul>
<li><a href="pi_getscript.html">pi_getscript</a></li>
<li><a href="pi_gzip.html">pi_gzip</a></li>
<li><a href="pi_logipat.html">pi_logipat</a></li>
<li><a href="pi_netrw.html">pi_netrw</a></li>
<li><a href="pi_paren.html">pi_paren</a></li>
<li><a href="pi_tar.html">pi_tar</a></li>
<li><a href="pi_vimball.html">pi_vimball</a></li>
<li><a href="pi_zip.html">pi_zip</a></li>
</ul></dd>
<dt>Filetype plugins</dt>
<dd><ul>
<li><a href="pi_spec.html">pi_spec</a></li>
</ul></dd>
<dt>Others</dt>
<dd><ul>
<li><a href="vim_faq.html">vim_faq</a></li>
</ul></dd>
</dl>
</nav>
<article class="Vimdoc VimdocJa">
<div id='vimCodeElement'>
<a class="Constant" href="diff.html" name="diff.txt">diff.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2017 Feb 03<br>
<br>
<br>
<span class="Identifier">VIM REFERENCE MANUAL by Bram Moolenaar</span><br>
<br>
<br>
<a class="Constant" href="diff.html#diff" name="diff">diff</a> <a class="Constant" href="diff.html#vimdiff" name="vimdiff">vimdiff</a> <a class="Constant" href="diff.html#gvimdiff" name="gvimdiff">gvimdiff</a> <a class="Constant" href="diff.html#diff-mode" name="diff-mode">diff-mode</a><br>
This file describes the <a class="Identifier" href="various.html#+diff">+diff</a> feature: Showing differences between two to<br>
eight versions of the same file.<br>
<br>
The basics are explained in section <a class="Identifier" href="usr_08.html#08.7">08.7</a> of the user manual.<br>
<br>
1. Starting diff mode <a class="Identifier" href="diff.html#vimdiff">vimdiff</a><br>
2. Viewing diffs <a class="Identifier" href="diff.html#view-diffs">view-diffs</a><br>
3. Jumping to diffs <a class="Identifier" href="diff.html#jumpto-diffs">jumpto-diffs</a><br>
4. Copying diffs <a class="Identifier" href="diff.html#copy-diffs">copy-diffs</a><br>
5. Diff options <a class="Identifier" href="diff.html#diff-options">diff-options</a><br>
<br>
<span class="Special">{not in Vi}</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Starting diff mode<br>
<br>
The easiest way to start editing in diff mode is with the "vimdiff" command.<br>
This starts Vim as usual, and additionally sets up for viewing the differences<br>
between the arguments.<br>
<br>
<div class="helpExample"> vimdiff file1 file2 [file3 [file4]]</div>
<br>
This is equivalent to:<br>
<br>
<div class="helpExample"> vim -d file1 file2 [file3 [file4]]</div>
<br>
You may also use "gvimdiff" or "vim -d -g". The GUI is started then.<br>
You may also use "viewdiff" or "gviewdiff". Vim starts in readonly mode then.<br>
"r" may be prepended for restricted mode (see <a class="Identifier" href="starting.html#-Z">-Z</a>).<br>
<br>
The second and following arguments may also be a directory name. Vim will<br>
then append the file name of the first argument to the directory name to find<br>
the file.<br>
<br>
This only works when a standard "diff" command is available. See <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a>.<br>
<br>
Diffs are local to the current tab page <a class="Identifier" href="tabpage.html#tab-page">tab-page</a>. You can't see diffs with<br>
a window in another tab page. This does make it possible to have several<br>
diffs at the same time, each in their own tab page.<br>
<br>
What happens is that Vim opens a window for each of the files. This is like<br>
using the <a class="Identifier" href="starting.html#-O">-O</a> argument. This uses vertical splits. If you prefer horizontal<br>
splits add the <a class="Identifier" href="starting.html#-o">-o</a> argument:<br>
<br>
<div class="helpExample"> vimdiff -o file1 file2 [file3 [file4]]</div>
<br>
If you always prefer horizontal splits include "horizontal" in <a class="Type" href="options.html#'diffopt'">'diffopt'</a>.<br>
<br>
In each of the edited files these options are set:<br>
<br>
<a class="Type" href="options.html#'diff'">'diff'</a> on<br>
<a class="Type" href="options.html#'scrollbind'">'scrollbind'</a> on<br>
<a class="Type" href="options.html#'cursorbind'">'cursorbind'</a> on<br>
<a class="Type" href="options.html#'scrollopt'">'scrollopt'</a> includes "hor"<br>
<a class="Type" href="options.html#'wrap'">'wrap'</a> off<br>
<a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> "diff"<br>
<a class="Type" href="options.html#'foldcolumn'">'foldcolumn'</a> value from <a class="Type" href="options.html#'diffopt'">'diffopt'</a>, default is 2<br>
<br>
These options are set local to the window. When editing another file they are<br>
reset to the global value.<br>
The options can still be overruled from a modeline when re-editing the file.<br>
However, <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> and <a class="Type" href="options.html#'wrap'">'wrap'</a> won't be set from a modeline when <a class="Type" href="options.html#'diff'">'diff'</a> is<br>
set.<br>
<br>
The differences shown are actually the differences in the buffer. Thus if you<br>
make changes after loading a file, these will be included in the displayed<br>
diffs. You might have to do ":diffupdate" now and then, not all changes are<br>
immediately taken into account.<br>
<br>
In your .vimrc file you could do something special when Vim was started in<br>
diff mode. You could use a construct like this:<br>
<br>
<div class="helpExample"> if &diff<br>
setup for diff mode<br>
else<br>
setup for non-diff mode<br>
endif</div>
<br>
While already in Vim you can start diff mode in three ways.<br>
<br>
<a class="Constant" href="diff.html#E98" name="E98">E98</a><br>
:diffs[plit] <span class="Special">{filename}</span> <a class="Constant" href="diff.html#:diffs" name=":diffs">:diffs</a> <a class="Constant" href="diff.html#:diffsplit" name=":diffsplit">:diffsplit</a><br>
Open a new window on the file <span class="Special">{filename}</span>. The options are set<br>
as for "vimdiff" for the current and the newly opened window.<br>
Also see <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a>.<br>
<br>
<a class="Constant" href="diff.html#:difft" name=":difft">:difft</a> <a class="Constant" href="diff.html#:diffthis" name=":diffthis">:diffthis</a><br>
:difft[his] Make the current window part of the diff windows. This sets<br>
the options like for "vimdiff".<br>
<br>
:diffp[atch] <span class="Special">{patchfile}</span> <a class="Constant" href="diff.html#E816" name="E816">E816</a> <a class="Constant" href="diff.html#:diffp" name=":diffp">:diffp</a> <a class="Constant" href="diff.html#:diffpatch" name=":diffpatch">:diffpatch</a><br>
Use the current buffer, patch it with the diff found in<br>
<span class="Special">{patchfile}</span> and open a buffer on the result. The options are<br>
set as for "vimdiff".<br>
<span class="Special">{patchfile}</span> can be in any format that the "patch" program<br>
understands or <a class="Type" href="options.html#'patchexpr'">'patchexpr'</a> can handle.<br>
<span class="Todo">Note</span> that <span class="Special">{patchfile}</span> should only contain a diff for one file,<br>
the current file. If <span class="Special">{patchfile}</span> contains diffs for other<br>
files as well, the results are unpredictable. Vim changes<br>
directory to /tmp to avoid files in the current directory<br>
accidentally being patched. But it may still result in<br>
various ".rej" files to be created. And when absolute path<br>
names are present these files may get patched anyway.<br>
<br>
To make these commands use a vertical split, prepend <a class="Identifier" href="windows.html#:vertical">:vertical</a>. Examples:<br>
<br>
<div class="helpExample"> :vert diffsplit main.c~<br>
:vert diffpatch /tmp/diff</div>
<br>
If you always prefer a vertical split include "vertical" in <a class="Type" href="options.html#'diffopt'">'diffopt'</a>.<br>
<br>
<a class="Constant" href="diff.html#E96" name="E96">E96</a><br>
There can be up to eight buffers with <a class="Type" href="options.html#'diff'">'diff'</a> set.<br>
<br>
Since the option values are remembered with the buffer, you can edit another<br>
file for a moment and come back to the same file and be in diff mode again.<br>
<br>
<a class="Constant" href="diff.html#:diffo" name=":diffo">:diffo</a> <a class="Constant" href="diff.html#:diffoff" name=":diffoff">:diffoff</a><br>
:diffo[ff] Switch off diff mode for the current window. Resets related<br>
options also when <a class="Type" href="options.html#'diff'">'diff'</a> was not set.<br>
<br>
:diffo[ff]! Switch off diff mode for the current window and in all windows<br>
in the current tab page where <a class="Type" href="options.html#'diff'">'diff'</a> is set. Resetting<br>
related options only happens in a window that has <a class="Type" href="options.html#'diff'">'diff'</a> set,<br>
if the current window does not have <a class="Type" href="options.html#'diff'">'diff'</a> set then no options<br>
in it are changed.<br>
Hidden buffers are also removed from the list of diff'ed<br>
buffers.<br>
<br>
The <a class="Comment" href="diff.html#:diffoff">:diffoff</a> command resets the relevant options to the values they had when<br>
using <a class="Comment" href="diff.html#:diffsplit">:diffsplit</a>, <a class="Comment" href="diff.html#:diffpatch">:diffpatch</a> , <a class="Comment" href="diff.html#:diffthis">:diffthis</a>. or starting Vim in diff mode.<br>
When using <a class="Comment" href="diff.html#:diffoff">:diffoff</a> twice the last saved values are restored.<br>
Otherwise they are set to their default value:<br>
<br>
<a class="Type" href="options.html#'diff'">'diff'</a> off<br>
<a class="Type" href="options.html#'scrollbind'">'scrollbind'</a> off<br>
<a class="Type" href="options.html#'cursorbind'">'cursorbind'</a> off<br>
<a class="Type" href="options.html#'scrollopt'">'scrollopt'</a> without "hor"<br>
<a class="Type" href="options.html#'wrap'">'wrap'</a> on<br>
<a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> "manual"<br>
<a class="Type" href="options.html#'foldcolumn'">'foldcolumn'</a> 0<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. Viewing diffs <a class="Constant" href="diff.html#view-diffs" name="view-diffs">view-diffs</a><br>
<br>
The effect is that the diff windows show the same text, with the differences<br>
highlighted. When scrolling the text, the <a class="Type" href="options.html#'scrollbind'">'scrollbind'</a> option will make the<br>
text in other windows to be scrolled as well. With vertical splits the text<br>
should be aligned properly.<br>
<br>
The alignment of text will go wrong when:<br>
- <a class="Type" href="options.html#'wrap'">'wrap'</a> is on, some lines will be wrapped and occupy two or more screen<br>
lines<br>
- folds are open in one window but not another<br>
- <a class="Type" href="options.html#'scrollbind'">'scrollbind'</a> is off<br>
- changes have been made to the text<br>
- "filler" is not present in <a class="Type" href="options.html#'diffopt'">'diffopt'</a>, deleted/inserted lines makes the<br>
alignment go wrong<br>
<br>
All the buffers edited in a window where the <a class="Type" href="options.html#'diff'">'diff'</a> option is set will join in<br>
the diff. This is also possible for hidden buffers. They must have been<br>
edited in a window first for this to be possible. To get rid of the hidden<br>
buffers use <span class="Comment">:diffoff!</span>.<br>
<br>
<a class="Constant" href="diff.html#:DiffOrig" name=":DiffOrig">:DiffOrig</a> <a class="Constant" href="diff.html#diff-original-file" name="diff-original-file">diff-original-file</a><br>
Since <a class="Type" href="options.html#'diff'">'diff'</a> is a window-local option, it's possible to view the same buffer<br>
in diff mode in one window and "normal" in another window. It is also<br>
possible to view the changes you have made to a buffer since the file was<br>
loaded. Since Vim doesn't allow having two buffers for the same file, you<br>
need another buffer. This command is useful:<br>
<div class="helpExample"> command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_<br>
\ | diffthis | wincmd p | diffthis</div>
(this is in <a class="Identifier" href="usr_05.html#vimrc_example.vim">vimrc_example.vim</a>). Use ":DiffOrig" to see the differences<br>
between the current buffer and the file it was loaded from.<br>
<br>
A buffer that is unloaded cannot be used for the diff. But it does work for<br>
hidden buffers. You can use ":hide" to close a window without unloading the<br>
buffer. If you don't want a buffer to remain used for the diff do ":set<br>
nodiff" before hiding it.<br>
<br>
<a class="Constant" href="diff.html#:dif" name=":dif">:dif</a> <a class="Constant" href="diff.html#:diffupdate" name=":diffupdate">:diffupdate</a><br>
:dif[fupdate][!] Update the diff highlighting and folds.<br>
<br>
Vim attempts to keep the differences updated when you make changes to the<br>
text. This mostly takes care of inserted and deleted lines. Changes within a<br>
line and more complicated changes do not cause the differences to be updated.<br>
To force the differences to be updated use:<br>
<br>
<div class="helpExample"> :diffupdate</div>
<br>
If the ! is included Vim will check if the file was changed externally and<br>
needs to be reloaded. It will prompt for each changed file, like <a class="Comment" href="editing.html#:checktime">:checktime</a><br>
was used.<br>
<br>
Vim will show filler lines for lines that are missing in one window but are<br>
present in another. These lines were inserted in another file or deleted in<br>
this file. Removing "filler" from the <a class="Type" href="options.html#'diffopt'">'diffopt'</a> option will make Vim not<br>
display these filler lines.<br>
<br>
<br>
Folds are used to hide the text that wasn't changed. See <a class="Identifier" href="fold.html#folding">folding</a> for all<br>
the commands that can be used with folds.<br>
<br>
The context of lines above a difference that are not included in the fold can<br>
be set with the <a class="Type" href="options.html#'diffopt'">'diffopt'</a> option. For example, to set the context to three<br>
lines:<br>
<br>
<div class="helpExample"> :set diffopt=filler,context:3</div>
<br>
<br>
The diffs are highlighted with these groups:<br>
<br>
<a class="Identifier" href="syntax.html#hl-DiffAdd">hl-DiffAdd</a> DiffAdd Added (inserted) lines. These lines exist in<br>
this buffer but not in another.<br>
<a class="Identifier" href="syntax.html#hl-DiffChange">hl-DiffChange</a> DiffChange Changed lines.<br>
<a class="Identifier" href="syntax.html#hl-DiffText">hl-DiffText</a> DiffText Changed text inside a Changed line. Vim<br>
finds the first character that is different,<br>
and the last character that is different<br>
(searching from the end of the line). The<br>
text in between is highlighted. This means<br>
that parts in the middle that are still the<br>
same are highlighted anyway. Only "iwhite" of<br>
<a class="Type" href="options.html#'diffopt'">'diffopt'</a> is used here.<br>
<a class="Identifier" href="syntax.html#hl-DiffDelete">hl-DiffDelete</a> DiffDelete Deleted lines. Also called filler lines,<br>
because they don't really exist in this<br>
buffer.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. Jumping to diffs <a class="Constant" href="diff.html#jumpto-diffs" name="jumpto-diffs">jumpto-diffs</a><br>
<br>
Two commands can be used to jump to diffs:<br>
<a class="Constant" href="diff.html#[c" name="[c">[c</a><br>
[c Jump backwards to the previous start of a change.<br>
When a count is used, do it that many times.<br>
<a class="Constant" href="diff.html#]c" name="]c">]c</a><br>
]c Jump forwards to the next start of a change.<br>
When a count is used, do it that many times.<br>
<br>
It is an error if there is no change for the cursor to move to.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
4. Diff copying <a class="Constant" href="diff.html#copy-diffs" name="copy-diffs">copy-diffs</a> <a class="Constant" href="diff.html#E99" name="E99">E99</a> <a class="Constant" href="diff.html#E100" name="E100">E100</a> <a class="Constant" href="diff.html#E101" name="E101">E101</a> <a class="Constant" href="diff.html#E102" name="E102">E102</a> <a class="Constant" href="diff.html#E103" name="E103">E103</a><br>
<a class="Constant" href="diff.html#merge" name="merge">merge</a><br>
There are two commands to copy text from one buffer to another. The result is<br>
that the buffers will be equal within the specified range.<br>
<br>
<a class="Constant" href="diff.html#:diffg" name=":diffg">:diffg</a> <a class="Constant" href="diff.html#:diffget" name=":diffget">:diffget</a><br>
:<span class="Special">[range]</span>diffg[et] <span class="Special">[bufspec]</span><br>
Modify the current buffer to undo difference with another<br>
buffer. If <span class="Special">[bufspec]</span> is given, that buffer is used. If<br>
<span class="Special">[bufspec]</span> refers to the current buffer then nothing happens.<br>
Otherwise this only works if there is one other buffer in diff<br>
mode.<br>
See below for <span class="Special">[range]</span>.<br>
<br>
<a class="Constant" href="diff.html#:diffpu" name=":diffpu">:diffpu</a> <a class="Constant" href="diff.html#:diffput" name=":diffput">:diffput</a> <a class="Constant" href="diff.html#E793" name="E793">E793</a><br>
:<span class="Special">[range]</span>diffpu[t] <span class="Special">[bufspec]</span><br>
Modify another buffer to undo difference with the current<br>
buffer. Just like ":diffget" but the other buffer is modified<br>
instead of the current one.<br>
When <span class="Special">[bufspec]</span> is omitted and there is more than one other<br>
buffer in diff mode where <a class="Type" href="options.html#'modifiable'">'modifiable'</a> is set this fails.<br>
See below for <span class="Special">[range]</span>.<br>
<br>
<a class="Constant" href="diff.html#do" name="do">do</a><br>
<span class="Special">[count]</span>do Same as ":diffget" without range. The "o" stands for "obtain"<br>
("dg" can't be used, it could be the start of "dgg"!). <span class="Todo">Note</span>:<br>
this doesn't work in Visual mode.<br>
If you give a <span class="Special">[count]</span>, it is used as the <span class="Special">[bufspec]</span> argument<br>
for ":diffget".<br>
<br>
<a class="Constant" href="diff.html#dp" name="dp">dp</a><br>
<span class="Special">[count]</span>dp Same as ":diffput" without range. <span class="Todo">Note</span>: this doesn't work in<br>
Visual mode.<br>
If you give a <span class="Special">[count]</span>, it is used as the <span class="Special">[bufspec]</span> argument<br>
for ":diffput".<br>
<br>
<br>
When no <span class="Special">[range]</span> is given, the diff at the cursor position or just above it is<br>
affected. When <span class="Special">[range]</span> is used, Vim tries to only put or get the specified<br>
lines. When there are deleted lines, this may not always be possible.<br>
<br>
There can be deleted lines below the last line of the buffer. When the cursor<br>
is on the last line in the buffer and there is no diff above this line, the<br>
":diffget" and "do" commands will obtain lines from the other buffer.<br>
<br>
To be able to get those lines from another buffer in a <span class="Special">[range]</span> it's allowed to<br>
use the last line number plus one. This command gets all diffs from the other<br>
buffer:<br>
<br>
<div class="helpExample"> :1,$+1diffget</div>
<br>
<span class="Todo">Note</span> that deleted lines are displayed, but not counted as text lines. You<br>
can't move the cursor into them. To fill the deleted lines with the lines<br>
from another buffer use ":diffget" on the line below them.<br>
<a class="Constant" href="diff.html#E787" name="E787">E787</a><br>
When the buffer that is about to be modified is read-only and the autocommand<br>
that is triggered by <a class="Identifier" href="autocmd.html#FileChangedRO">FileChangedRO</a> changes buffers the command will fail.<br>
The autocommand must not change buffers.<br>
<br>
The <span class="Special">[bufspec]</span> argument above can be a buffer number, a pattern for a buffer<br>
name or a part of a buffer name. Examples:<br>
<br>
:diffget Use the other buffer which is in diff mode<br>
:diffget 3 Use buffer 3<br>
:diffget v2 Use the buffer which matches "v2" and is in<br>
diff mode (e.g., "file.c.v2")<br>
<br>
<span class="PreProc">==============================================================================</span><br>
5. Diff options <a class="Constant" href="diff.html#diff-options" name="diff-options">diff-options</a><br>
<br>
Also see <a class="Identifier" href="options.html#'diffopt'">'diffopt'</a> and the "diff" item of <a class="Identifier" href="options.html#'fillchars'">'fillchars'</a>.<br>
<br>
<a class="Constant" href="diff.html#diff-slow" name="diff-slow">diff-slow</a> <a class="Constant" href="diff.html#diff_translations" name="diff_translations">diff_translations</a><br>
For very long lines, the diff syntax highlighting might be slow, especially<br>
since it tries to match all different kind of localisations. To disable<br>
localisations and speed up the syntax highlighting, set the global variable<br>
g:diff_translations to zero:<br>
<br>
<div class="helpExample"> let g:diff_translations = 0</div>
<br>
After setting this variable, Reload the syntax script:<br>
<br>
<div class="helpExample"> set syntax=diff</div>
<br>
<br>
<br>
<span class="Statement">FINDING THE DIFFERENCES </span><a class="Constant" href="diff.html#diff-diffexpr" name="diff-diffexpr">diff-diffexpr</a><br>
<br>
The <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a> option can be set to use something else than the standard<br>
"diff" program to compare two files and find the differences.<br>
<br>
When <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a> is empty, Vim uses this command to find the differences<br>
between file1 and file2:<br>
<br>
<div class="helpExample"> diff file1 file2 > outfile</div>
<br>
The ">" is replaced with the value of <a class="Type" href="options.html#'shellredir'">'shellredir'</a>.<br>
<br>
The output of "diff" must be a normal "ed" style diff. Do NOT use a context<br>
diff. This example explains the format that Vim expects:<br>
<br>
<div class="helpExample"> 1a2<br>
> bbb<br>
4d4<br>
< 111<br>
7c7<br>
< GGG<br>
---<br>
> ggg</div>
<br>
The "1a2" item appends the line "bbb".<br>
The "4d4" item deletes the line "111".<br>
The "7c7" item replaces the line "GGG" with "ggg".<br>
<br>
When <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a> is not empty, Vim evaluates it to obtain a diff file in the<br>
format mentioned. These variables are set to the file names used:<br>
<br>
v:fname_in original file<br>
v:fname_new new version of the same file<br>
v:fname_out resulting diff file<br>
<br>
Additionally, <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a> should take care of "icase" and "iwhite" in the<br>
<a class="Type" href="options.html#'diffopt'">'diffopt'</a> option. <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a> cannot change the value of <a class="Type" href="options.html#'lines'">'lines'</a> and<br>
<a class="Type" href="options.html#'columns'">'columns'</a>.<br>
<br>
Example (this does almost the same as <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a> being empty):<br>
<br>
<div class="helpExample"> set diffexpr=MyDiff()<br>
function MyDiff()<br>
let opt = ""<br>
if &diffopt =~ "icase"<br>
let opt = opt . "-i "<br>
endif<br>
if &diffopt =~ "iwhite"<br>
let opt = opt . "-b "<br>
endif<br>
silent execute "!diff -a --binary " . opt . v:fname_in . " " . v:fname_new .<br>
\ " > " . v:fname_out<br>
endfunction</div>
<br>
The "-a" argument is used to force comparing the files as text, comparing as<br>
binaries isn't useful. The "--binary" argument makes the files read in binary<br>
mode, so that a <span class="Special">CTRL-Z</span> doesn't end the text on DOS.<br>
<br>
<a class="Constant" href="diff.html#E810" name="E810">E810</a> <a class="Constant" href="diff.html#E97" name="E97">E97</a><br>
Vim will do a test if the diff output looks alright. If it doesn't, you will<br>
get an error message. Possible causes:<br>
- The "diff" program cannot be executed.<br>
- The "diff" program doesn't produce normal "ed" style diffs (see above).<br>
- The <a class="Type" href="options.html#'shell'">'shell'</a> and associated options are not set correctly. Try if filtering<br>
works with a command like ":!sort".<br>
- You are using <a class="Type" href="options.html#'diffexpr'">'diffexpr'</a> and it doesn't work.<br>
If it's not clear what the problem is set the <a class="Type" href="options.html#'verbose'">'verbose'</a> option to one or more<br>
to see more messages.<br>
<br>
The self-installing Vim for MS-Windows includes a diff program. If you don't<br>
have it you might want to download a diff.exe. For example from<br>
<span class="Constant"><a href="http://gnuwin32.sourceforge.net/packages/diffutils.htm">http://gnuwin32.sourceforge.net/packages/diffutils.htm</a></span>.<br>
<br>
<br>
<span class="Statement">USING PATCHES </span><a class="Constant" href="diff.html#diff-patchexpr" name="diff-patchexpr">diff-patchexpr</a><br>
<br>
The <a class="Type" href="options.html#'patchexpr'">'patchexpr'</a> option can be set to use something else than the standard<br>
"patch" program.<br>
<br>
When <a class="Type" href="options.html#'patchexpr'">'patchexpr'</a> is empty, Vim will call the "patch" program like this:<br>
<br>
<div class="helpExample"> patch -o outfile origfile < patchfile</div>
<br>
This should work fine with most versions of the "patch" program. <span class="Todo">Note</span> that a<br>
CR in the middle of a line may cause problems, it is seen as a line break.<br>
<br>
If the default doesn't work for you, set the <a class="Type" href="options.html#'patchexpr'">'patchexpr'</a> to an expression that<br>
will have the same effect. These variables are set to the file names used:<br>
<br>
v:fname_in original file<br>
v:fname_diff patch file<br>
v:fname_out resulting patched file<br>
<br>
Example (this does the same as <a class="Type" href="options.html#'patchexpr'">'patchexpr'</a> being empty):<br>
<br>
<div class="helpExample"> set patchexpr=MyPatch()<br>
function MyPatch()<br>
:call system("patch -o " . v:fname_out . " " . v:fname_in .<br>
\ " < " . v:fname_diff)<br>
endfunction</div>
<br>
Make sure that using the "patch" program doesn't have unwanted side effects.<br>
For example, watch out for additionally generated files, which should be<br>
deleted. It should just patch the file and nothing else.<br>
Vim will change directory to "/tmp" or another temp directory before<br>
evaluating <a class="Type" href="options.html#'patchexpr'">'patchexpr'</a>. This hopefully avoids that files in the current<br>
directory are accidentally patched. Vim will also delete files starting with<br>
v:fname_in and ending in ".rej" and ".orig".<br>
<br>
vim:tw=78:ts=8:ft=help:norl:<br>
</div>
</article>
<footer>
<a href="#top">Return to the top</a> - <a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
<br />
<div style="text-align:right;">
Hosted by <a href="https://github.com/vim-jp/vimdoc-en">vimdoc-en project</a><br />
If you met any problem, please report it to <a href="https://github.com/vim-jp/vimdoc-en/issues">issue</a>.<br />
</div>
</footer>
<!--<script src="js/check-referrer.js" type="text/javascript"></script>-->
</body>
</html>
<!-- vim:set ts=8 sts=2 sw=2 tw=0 et: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。