代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>undo - 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>
/ undo<br />
<a name="top"></a><h1>undo - 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="undo.html" name="undo.txt">undo.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2014 May 24<br>
<br>
<br>
<span class="Identifier">VIM REFERENCE MANUAL by Bram Moolenaar</span><br>
<br>
<br>
Undo and redo <a class="Constant" href="undo.html#undo-redo" name="undo-redo">undo-redo</a><br>
<br>
The basics are explained in section <a class="Identifier" href="usr_02.html#02.5">02.5</a> of the user manual.<br>
<br>
1. Undo and redo commands <a class="Identifier" href="undo.html#undo-commands">undo-commands</a><br>
2. Two ways of undo <a class="Identifier" href="undo.html#undo-two-ways">undo-two-ways</a><br>
3. Undo blocks <a class="Identifier" href="undo.html#undo-blocks">undo-blocks</a><br>
4. Undo branches <a class="Identifier" href="undo.html#undo-branches">undo-branches</a><br>
5. Undo persistence <a class="Identifier" href="undo.html#undo-persistence">undo-persistence</a><br>
6. Remarks about undo <a class="Identifier" href="undo.html#undo-remarks">undo-remarks</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Undo and redo commands <a class="Constant" href="undo.html#undo-commands" name="undo-commands">undo-commands</a><br>
<br>
<span class="Special"><Undo></span> or <a class="Constant" href="undo.html#undo" name="undo">undo</a> <a class="Constant" href="undo.html#<Undo>" name="<Undo>"><Undo></a> <a class="Constant" href="undo.html#u" name="u">u</a><br>
u Undo <span class="Special">[count]</span> changes. <span class="Special">{Vi: only one level}</span><br>
<br>
<a class="Constant" href="undo.html#:u" name=":u">:u</a> <a class="Constant" href="undo.html#:un" name=":un">:un</a> <a class="Constant" href="undo.html#:undo" name=":undo">:undo</a><br>
:u[ndo] Undo one change. <span class="Special">{Vi: only one level}</span><br>
<a class="Constant" href="undo.html#E830" name="E830">E830</a><br>
:u[ndo] <span class="Special">{N}</span> Jump to after change number <span class="Special">{N}</span>. See <a class="Identifier" href="undo.html#undo-branches">undo-branches</a><br>
for the meaning of <span class="Special">{N}</span>. <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="undo.html#CTRL-R" name="CTRL-R">CTRL-R</a><br>
<span class="Special">CTRL-R</span> Redo <span class="Special">[count]</span> changes which were undone. <span class="Special">{Vi: redraw</span><br>
<span class="Special">screen}</span><br>
<br>
<a class="Constant" href="undo.html#:red" name=":red">:red</a> <a class="Constant" href="undo.html#:redo" name=":redo">:redo</a> <a class="Constant" href="undo.html#redo" name="redo">redo</a><br>
:red[o] Redo one change which was undone. <span class="Special">{Vi: no redo}</span><br>
<br>
<a class="Constant" href="undo.html#U" name="U">U</a><br>
U Undo all latest changes on one line, the line where<br>
the latest change was made. <a class="Identifier" href="undo.html#U">U</a> itself also counts as<br>
a change, and thus <a class="Identifier" href="undo.html#U">U</a> undoes a previous <a class="Identifier" href="undo.html#U">U</a>.<br>
<span class="Special">{Vi: while not moved off of the last modified line}</span><br>
<br>
The last changes are remembered. You can use the undo and redo commands above<br>
to revert the text to how it was before each change. You can also apply the<br>
changes again, getting back the text before the undo.<br>
<br>
The "U" command is treated by undo/redo just like any other command. Thus a<br>
"u" command undoes a "U" command and a '<span class="Special">CTRL-R</span>' command redoes it again. When<br>
mixing "U", "u" and '<span class="Special">CTRL-R</span>' you will notice that the "U" command will<br>
restore the situation of a line to before the previous "U" command. This may<br>
be confusing. Try it out to get used to it.<br>
The "U" command will always mark the buffer as changed. When "U" changes the<br>
buffer back to how it was without changes, it is still considered changed.<br>
Use "u" to undo changes until the buffer becomes unchanged.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. Two ways of undo <a class="Constant" href="undo.html#undo-two-ways" name="undo-two-ways">undo-two-ways</a><br>
<br>
How undo and redo commands work depends on the 'u' flag in <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a>.<br>
There is the Vim way ('u' excluded) and the Vi-compatible way ('u' included).<br>
In the Vim way, "uu" undoes two changes. In the Vi-compatible way, "uu" does<br>
nothing (undoes an undo).<br>
<br>
'u' excluded, the Vim way:<br>
You can go back in time with the undo command. You can then go forward again<br>
with the redo command. If you make a new change after the undo command,<br>
the redo will not be possible anymore.<br>
<br>
'u' included, the Vi-compatible way:<br>
The undo command undoes the previous change, and also the previous undo command.<br>
The redo command repeats the previous undo command. It does NOT repeat a<br>
change command, use "." for that.<br>
<br>
<span class="PreProc">Examples Vim way Vi-compatible way</span><br>
"uu" two times undo no-op<br>
"u <span class="Special">CTRL-R</span>" no-op two times undo<br>
<br>
Rationale: Nvi uses the "." command instead of <span class="Special">CTRL-R</span>. Unfortunately, this<br>
is not Vi compatible. For example "dwdwu." in Vi deletes two<br>
words, in Nvi it does nothing.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. Undo blocks <a class="Constant" href="undo.html#undo-blocks" name="undo-blocks">undo-blocks</a><br>
<br>
One undo command normally undoes a typed command, no matter how many changes<br>
that command makes. This sequence of undo-able changes forms an undo block.<br>
Thus if the typed key(s) call a function, all the commands in the function are<br>
undone together.<br>
<br>
If you want to write a function or script that doesn't create a new undoable<br>
change but joins in with the previous change use this command:<br>
<br>
<a class="Constant" href="undo.html#:undoj" name=":undoj">:undoj</a> <a class="Constant" href="undo.html#:undojoin" name=":undojoin">:undojoin</a> <a class="Constant" href="undo.html#E790" name="E790">E790</a><br>
:undoj[oin] Join further changes with the previous undo block.<br>
Warning: Use with care, it may prevent the user from<br>
properly undoing changes. Don't use this after undo<br>
or redo.<br>
<span class="Special">{not in Vi}</span><br>
<br>
This is most useful when you need to prompt the user halfway through a change.<br>
For example in a function that calls <a class="Identifier" href="eval.html#getchar()">getchar()</a>. Do make sure that there was<br>
a related change before this that you must join with.<br>
<br>
This doesn't work by itself, because the next key press will start a new<br>
change again. But you can do something like this:<br>
<br>
<div class="helpExample"> :undojoin | delete</div>
<br>
After this an "u" command will undo the delete command and the previous<br>
change.<br>
<br>
To do the opposite, break a change into two undo blocks, in Insert mode use<br>
<span class="Special">CTRL-G</span> u. This is useful if you want an insert command to be undoable in<br>
parts. E.g., for each sentence. <a class="Identifier" href="insert.html#i_CTRL-G_u">i_CTRL-G_u</a><br>
Setting the value of <a class="Type" href="options.html#'undolevels'">'undolevels'</a> also breaks undo. Even when the new value<br>
is equal to the old value.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
4. Undo branches <a class="Constant" href="undo.html#undo-branches" name="undo-branches">undo-branches</a> <a class="Constant" href="undo.html#undo-tree" name="undo-tree">undo-tree</a><br>
<br>
Above we only discussed one line of undo/redo. But it is also possible to<br>
branch off. This happens when you undo a few changes and then make a new<br>
change. The undone changes become a branch. You can go to that branch with<br>
the following commands.<br>
<br>
This is explained in the user manual: <a class="Identifier" href="usr_32.html">usr_32.txt</a>.<br>
<br>
<a class="Constant" href="undo.html#:undol" name=":undol">:undol</a> <a class="Constant" href="undo.html#:undolist" name=":undolist">:undolist</a><br>
:undol[ist] List the leafs in the tree of changes. Example:<br>
<span class="PreProc">number changes when saved</span><br>
88 88 2010/01/04 14:25:53<br>
108 107 08/07 12:47:51<br>
136 46 13:33:01 7<br>
166 164 3 seconds ago<br>
<br>
The "number" column is the change number. This number<br>
continuously increases and can be used to identify a<br>
specific undo-able change, see <a class="Identifier" href="undo.html#:undo">:undo</a>.<br>
The "changes" column is the number of changes to this<br>
leaf from the root of the tree.<br>
The "when" column is the date and time when this<br>
change was made. The four possible formats are:<br>
<span class="Special">N</span> seconds ago<br>
HH:MM:SS hour, minute, seconds<br>
MM/DD HH:MM:SS idem, with month and day<br>
YYYY/MM/DD HH:MM:SS idem, with year<br>
The "saved" column specifies, if this change was<br>
written to disk and which file write it was. This can<br>
be used with the <a class="Identifier" href="undo.html#:later">:later</a> and <a class="Identifier" href="undo.html#:earlier">:earlier</a> commands.<br>
For more details use the <a class="Identifier" href="eval.html#undotree()">undotree()</a> function.<br>
<br>
<a class="Constant" href="undo.html#g-" name="g-">g-</a><br>
g- Go to older text state. With a count repeat that many<br>
times. <span class="Special">{not in Vi}</span><br>
<a class="Constant" href="undo.html#:ea" name=":ea">:ea</a> <a class="Constant" href="undo.html#:earlier" name=":earlier">:earlier</a><br>
:earlier <span class="Special">{count}</span> Go to older text state <span class="Special">{count}</span> times.<br>
:earlier <span class="Special">{N}</span>s Go to older text state about <span class="Special">{N}</span> seconds before.<br>
:earlier <span class="Special">{N}</span>m Go to older text state about <span class="Special">{N}</span> minutes before.<br>
:earlier <span class="Special">{N}</span>h Go to older text state about <span class="Special">{N}</span> hours before.<br>
:earlier <span class="Special">{N}</span>d Go to older text state about <span class="Special">{N}</span> days before.<br>
<br>
:earlier <span class="Special">{N}</span>f Go to older text state <span class="Special">{N}</span> file writes before.<br>
When changes were made since the last write<br>
":earlier 1f" will revert the text to the state when<br>
it was written. Otherwise it will go to the write<br>
before that.<br>
When at the state of the first file write, or when<br>
the file was not written, ":earlier 1f" will go to<br>
before the first change.<br>
<br>
<a class="Constant" href="undo.html#g+" name="g+">g+</a><br>
g+ Go to newer text state. With a count repeat that many<br>
times. <span class="Special">{not in Vi}</span><br>
<a class="Constant" href="undo.html#:lat" name=":lat">:lat</a> <a class="Constant" href="undo.html#:later" name=":later">:later</a><br>
:later <span class="Special">{count}</span> Go to newer text state <span class="Special">{count}</span> times.<br>
:later <span class="Special">{N}</span>s Go to newer text state about <span class="Special">{N}</span> seconds later.<br>
:later <span class="Special">{N}</span>m Go to newer text state about <span class="Special">{N}</span> minutes later.<br>
:later <span class="Special">{N}</span>h Go to newer text state about <span class="Special">{N}</span> hours later.<br>
:later <span class="Special">{N}</span>d Go to newer text state about <span class="Special">{N}</span> days later.<br>
<br>
:later <span class="Special">{N}</span>f Go to newer text state <span class="Special">{N}</span> file writes later.<br>
When at the state of the last file write, ":later 1f"<br>
will go to the newest text state.<br>
<br>
<br>
<span class="Todo">Note</span> that text states will become unreachable when undo information is cleared<br>
for <a class="Type" href="options.html#'undolevels'">'undolevels'</a>.<br>
<br>
Don't be surprised when moving through time shows multiple changes to take<br>
place at a time. This happens when moving through the undo tree and then<br>
making a new change.<br>
<br>
EXAMPLE<br>
<br>
Start with this text:<br>
<span class="PreProc">one two three</span><br>
<br>
Delete the first word by pressing "x" three times:<br>
<span class="PreProc">ne two three</span><br>
<span class="PreProc">e two three</span><br>
<span class="PreProc">two three</span><br>
<br>
Now undo that by pressing "u" three times:<br>
<span class="PreProc">e two three</span><br>
<span class="PreProc">ne two three</span><br>
<span class="PreProc">one two three</span><br>
<br>
Delete the second word by pressing "x" three times:<br>
<span class="PreProc">one wo three</span><br>
<span class="PreProc">one o three</span><br>
<span class="PreProc">one three</span><br>
<br>
Now undo that by using "g-" three times:<br>
<span class="PreProc">one o three</span><br>
<span class="PreProc">one wo three</span><br>
<span class="PreProc">two three</span><br>
<br>
You are now back in the first undo branch, after deleting "one". Repeating<br>
"g-" will now bring you back to the original text:<br>
<span class="PreProc">e two three</span><br>
<span class="PreProc">ne two three</span><br>
<span class="PreProc">one two three</span><br>
<br>
Jump to the last change with ":later 1h":<br>
<span class="PreProc">one three</span><br>
<br>
And back to the start again with ":earlier 1h":<br>
<span class="PreProc">one two three</span><br>
<br>
<br>
<span class="Todo">Note</span> that using "u" and <span class="Special">CTRL-R</span> will not get you to all possible text states<br>
while repeating "g-" and "g+" does.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
5. Undo persistence <a class="Constant" href="undo.html#undo-persistence" name="undo-persistence">undo-persistence</a> <a class="Constant" href="undo.html#persistent-undo" name="persistent-undo">persistent-undo</a><br>
<br>
When unloading a buffer Vim normally destroys the tree of undos created for<br>
that buffer. By setting the <a class="Type" href="options.html#'undofile'">'undofile'</a> option, Vim will automatically save<br>
your undo history when you write a file and restore undo history when you edit<br>
the file again.<br>
<br>
The <a class="Type" href="options.html#'undofile'">'undofile'</a> option is checked after writing a file, before the BufWritePost<br>
autocommands. If you want to control what files to write undo information<br>
for, you can use a BufWritePre autocommand:<br>
<div class="helpExample"> au BufWritePre /tmp/* setlocal noundofile</div>
<br>
Vim saves undo trees in a separate undo file, one for each edited file, using<br>
a simple scheme that maps filesystem paths directly to undo files. Vim will<br>
detect if an undo file is no longer synchronized with the file it was written<br>
for (with a hash of the file contents) and ignore it when the file was changed<br>
after the undo file was written, to prevent corruption. An undo file is also<br>
ignored if its owner differs from the owner of the edited file, except when<br>
the owner of the undo file is the current user. Set <a class="Type" href="options.html#'verbose'">'verbose'</a> to get a<br>
message about that when opening a file.<br>
<br>
Undo files are normally saved in the same directory as the file. This can be<br>
changed with the <a class="Type" href="options.html#'undodir'">'undodir'</a> option.<br>
<br>
When the file is encrypted, the text in the undo file is also crypted. The<br>
same key and method is used. <a class="Identifier" href="editing.html#encryption">encryption</a><br>
<br>
You can also save and restore undo histories by using ":wundo" and ":rundo"<br>
respectively:<br>
<a class="Constant" href="undo.html#:wundo" name=":wundo">:wundo</a> <a class="Constant" href="undo.html#:rundo" name=":rundo">:rundo</a><br>
:wundo[!] <span class="Special">{file}</span><br>
Write undo history to <span class="Special">{file}</span>.<br>
When <span class="Special">{file}</span> exists and it does not look like an undo file<br>
(the magic number at the start of the file is wrong), then<br>
this fails, unless the ! was added.<br>
If it exists and does look like an undo file it is<br>
overwritten. If there is no undo-history, nothing will be <br>
written.<br>
Implementation detail: Overwriting happens by first deleting<br>
the existing file and then creating a new file with the same<br>
name. So it is not possible to overwrite an existing undofile<br>
in a write-protected directory.<br>
<span class="Special">{not in Vi}</span><br>
<br>
:rundo <span class="Special">{file}</span> Read undo history from <span class="Special">{file}</span>.<br>
<span class="Special">{not in Vi}</span><br>
<br>
You can use these in autocommands to explicitly specify the name of the<br>
history file. E.g.:<br>
<br>
<div class="helpExample"> au BufReadPost * call ReadUndo()<br>
au BufWritePost * call WriteUndo()<br>
func ReadUndo()<br>
if filereadable(expand('%:h'). '/UNDO/' . expand('%:t'))<br>
rundo %:h/UNDO/%:t<br>
endif<br>
endfunc<br>
func WriteUndo()<br>
let dirname = expand('%:h') . '/UNDO'<br>
if !isdirectory(dirname)<br>
call mkdir(dirname)<br>
endif<br>
wundo %:h/UNDO/%:t<br>
endfunc</div>
<br>
You should keep <a class="Type" href="options.html#'undofile'">'undofile'</a> off, otherwise you end up with two undo files for<br>
every write.<br>
<br>
You can use the <a class="Identifier" href="eval.html#undofile()">undofile()</a> function to find out the file name that Vim would<br>
use.<br>
<br>
<span class="Todo">Note</span> that while reading/writing files and <a class="Type" href="options.html#'undofile'">'undofile'</a> is set most errors will<br>
be silent, unless <a class="Type" href="options.html#'verbose'">'verbose'</a> is set. With :wundo and :rundo you will get more<br>
error messages, e.g., when the file cannot be read or written.<br>
<br>
<span class="Todo">NOTE</span>: undo files are never deleted by Vim. You need to delete them yourself.<br>
<br>
Reading an existing undo file may fail for several reasons:<br>
<a class="Constant" href="undo.html#E822" name="E822">E822</a> It cannot be opened, because the file permissions don't allow it.<br>
<a class="Constant" href="undo.html#E823" name="E823">E823</a> The magic number at the start of the file doesn't match. This usually<br>
means it is not an undo file.<br>
<a class="Constant" href="undo.html#E824" name="E824">E824</a> The version number of the undo file indicates that it's written by a<br>
newer version of Vim. You need that newer version to open it. Don't<br>
write the buffer if you want to keep the undo info in the file.<br>
"File contents changed, cannot use undo info"<br>
The file text differs from when the undo file was written. This means<br>
the undo file cannot be used, it would corrupt the text. This also<br>
happens when <a class="Type" href="options.html#'encoding'">'encoding'</a> differs from when the undo file was written.<br>
<a class="Constant" href="undo.html#E825" name="E825">E825</a> The undo file does not contain valid contents and cannot be used.<br>
<a class="Constant" href="undo.html#E826" name="E826">E826</a> The undo file is encrypted but decryption failed.<br>
<a class="Constant" href="undo.html#E827" name="E827">E827</a> The undo file is encrypted but this version of Vim does not support<br>
encryption. Open the file with another Vim.<br>
<a class="Constant" href="undo.html#E832" name="E832">E832</a> The undo file is encrypted but <a class="Type" href="options.html#'key'">'key'</a> is not set, the text file is not<br>
encrypted. This would happen if the text file was written by Vim<br>
encrypted at first, and later overwritten by not encrypted text.<br>
You probably want to delete this undo file.<br>
"Not reading undo file, owner differs"<br>
The undo file is owned by someone else than the owner of the text<br>
file. For safety the undo file is not used.<br>
<br>
Writing an undo file may fail for these reasons:<br>
<a class="Constant" href="undo.html#E828" name="E828">E828</a> The file to be written cannot be created. Perhaps you do not have<br>
write permissions in the directory.<br>
"Cannot write undo file in any directory in <a class="Type" href="options.html#'undodir'">'undodir'</a>"<br>
None of the directories in <a class="Type" href="options.html#'undodir'">'undodir'</a> can be used.<br>
"Will not overwrite with undo file, cannot read"<br>
A file exists with the name of the undo file to be written, but it<br>
cannot be read. You may want to delete this file or rename it.<br>
"Will not overwrite, this is not an undo file"<br>
A file exists with the name of the undo file to be written, but it<br>
does not start with the right magic number. You may want to delete<br>
this file or rename it.<br>
"Skipping undo file write, nothing to undo"<br>
There is no undo information to be written, nothing has been changed<br>
or <a class="Type" href="options.html#'undolevels'">'undolevels'</a> is negative.<br>
<a class="Constant" href="undo.html#E829" name="E829">E829</a> An error occurred while writing the undo file. You may want to try<br>
again.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
6. Remarks about undo <a class="Constant" href="undo.html#undo-remarks" name="undo-remarks">undo-remarks</a><br>
<br>
The number of changes that are remembered is set with the <a class="Type" href="options.html#'undolevels'">'undolevels'</a> option.<br>
If it is zero, the Vi-compatible way is always used. If it is negative no<br>
undo is possible. Use this if you are running out of memory.<br>
<br>
<a class="Constant" href="undo.html#clear-undo" name="clear-undo">clear-undo</a><br>
When you set <a class="Type" href="options.html#'undolevels'">'undolevels'</a> to -1 the undo information is not immediately<br>
cleared, this happens at the next change. To force clearing the undo<br>
information you can use these commands:<br>
<div class="helpExample"> :let old_undolevels = &undolevels<br>
:set undolevels=-1<br>
:exe "normal a \<BS>\<Esc>"<br>
:let &undolevels = old_undolevels<br>
:unlet old_undolevels</div>
<br>
Marks for the buffer ('a to 'z) are also saved and restored, together with the<br>
text. <span class="Special">{Vi does this a little bit different}</span><br>
<br>
When all changes have been undone, the buffer is not considered to be changed.<br>
It is then possible to exit Vim with ":q" instead of ":q!" <span class="Special">{not in Vi}</span>. <span class="Todo">Note</span><br>
that this is relative to the last write of the file. Typing "u" after ":w"<br>
actually changes the buffer, compared to what was written, so the buffer is<br>
considered changed then.<br>
<br>
When manual <a class="Identifier" href="fold.html#folding">folding</a> is being used, the folds are not saved and restored.<br>
Only changes completely within a fold will keep the fold as it was, because<br>
the first and last line of the fold don't change.<br>
<br>
The numbered registers can also be used for undoing deletes. Each time you<br>
delete text, it is put into register "1. The contents of register "1 are<br>
shifted to "2, etc. The contents of register "9 are lost. You can now get<br>
back the most recent deleted text with the put command: '"1P'. (also, if the<br>
deleted text was the result of the last delete or copy operation, 'P' or 'p'<br>
also works as this puts the contents of the unnamed register). You can get<br>
back the text of three deletes ago with '"3P'.<br>
<br>
<a class="Constant" href="undo.html#redo-register" name="redo-register">redo-register</a><br>
If you want to get back more than one part of deleted text, you can use a<br>
special feature of the repeat command ".". It will increase the number of the<br>
register used. So if you first do ""1P", the following "." will result in a<br>
'"2P'. Repeating this will result in all numbered registers being inserted.<br>
<br>
Example: If you deleted text with 'dd....' it can be restored with<br>
'"1P....'.<br>
<br>
If you don't know in which register the deleted text is, you can use the<br>
:display command. An alternative is to try the first register with '"1P', and<br>
if it is not what you want do 'u.'. This will remove the contents of the<br>
first put, and repeat the put command for the second register. Repeat the<br>
'u.' until you got what you want.<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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。