
ファイルを編集するときは、通常、UNDOを連続して複数回(たとえば20回)実行します。 VIMでは通常、u
20回を押して実行されます。これにより、VIMは履歴スタック内のステップ20に「移動」します。その後、1つを実行すると、change
最後の20個の書き込みコマンドがすべて失われて交換されますchange
。change
その20桁を失うことなく終わりたいです。だからこれを行う前に、VIMに記録の記録を停止して記録を再開するように言いたいと思いますchange
(記録に含まれたくありませんchange
)。
編集する
より明確に説明すると、FF
バッファへの書き込み中にファイルの最後の数行を更新する機能があります。したがって、を実行すると、20 undos + write
最後の実行でwrite
新しい元に戻すブランチが開きます。undojoin
内部的に追加しようとしましたがFF
(下のjlmgのアドバイスに従って試みました)、書き込み - 元に戻す - 書き込みシーケンスでエラーが発生しました。元に戻した後は、Unionの元に戻すことはできません。。sed ....
それを残した後に何かをすることができますが、vim
それを使用しているSSH
のでvim専用のソリューションを好みます(バッファをアンロードした後にコマンドを実行するとファイルは作成されません)。
編集2VIMでこれを行います。空のファイルを開き、次の操作を行います。
i1<ESC>:wa2<ESC>:wa3<ESC>:wa4<ESC>uu:w
nowを実行すると、<CTRL>R
VIMは「3」を書き換えて次の結果を<CTRL>R
得ます。4
でもただし、aが実行されるたびに実行関数を渡しても、書き戻されません:w
。それが私がやりたいことなので、「記録を一時停止」と書いたのですが、たぶんそれは全体です。<CTRL>R
:w
BufWritePre
<CTRL>R
3
undotree()
答え1
答え2
私が正しく理解したなら、あなたが望むのは、後で元に戻す操作を実行したら、その元に戻す操作だけchange
でなく、20回の元に戻す操作も取り消す必要があるということです。
vimが関数またはコマンドを実行すると、実行されたすべての操作が一緒にキャンセルされます。これらの操作に元に戻すことができるかどうかはわかりません。おそらく文書のこの部分が役に立つかもしれません。
3. Undo blocks *undo-blocks*
One undo command normally undoes a typed command, no matter how many changes
that command makes. This sequence of undo-able changes forms an undo block.
Thus if the typed key(s) call a function, all the commands in the function are
undone together.
If you want to write a function or script that doesn't create a new undoable
change but joins in with the previous change use this command:
*:undoj* *:undojoin* *E790*
:undoj[oin] Join further changes with the previous undo block.
Warning: Use with care, it may prevent the user from
properly undoing changes. Don't use this after undo
or redo.
{not in Vi}
This is most useful when you need to prompt the user halfway through a change.
For example in a function that calls |getchar()|. Do make sure that there was
a related change before this that you must join with.
This doesn't work by itself, because the next key press will start a new
change again. But you can do something like this: >
:undojoin | delete
After this an "u" command will undo the delete command and the previous
change.
To do the opposite, break a change into two undo blocks, in Insert mode use
CTRL-G u. This is useful if you want an insert command to be undoable in
parts. E.g., for each sentence. |i_CTRL-G_u|
Setting the value of 'undolevels' also breaks undo. Even when the new value
is equal to the old value.
残念ながら、私は試してみました:undo 2 | undojoin | normal ohi
が、エラーメッセージが表示されましたE790: undojoin is not allowed after undo
。
ただし、次の関数で操作が実行される場合:
function F()
undo 2
normal ohi
endfunction
次に呼び出すと、その操作と元に戻すブロックの他の:call F()
操作が実行されます。undo
元に戻すを使用しているので、新しい元に戻すブランチを作成することに注意してください。完了したら、通常モードコマンドを使用して、最初に行ったように元に戻すことg-
ができます。F()
u
:undo 3