VIM履歴を一時停止する方法は?

VIM履歴を一時停止する方法は?

ファイルを編集するときは、通常、UNDOを連続して複数回(たとえば20回)実行します。 VIMでは通常、u20回を押して実行されます。これにより、VIMは履歴スタック内のステップ20に「移動」します。その後、1つを実行すると、change最後の20個の書き込みコマンドがすべて失われて交換されますchangechangeその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>RVIMは「3」を書き換えて次の結果を<CTRL>R得ます。4でもただし、aが実行されるたびに実行関数を渡しても、書き戻されません:w。それが私がやりたいことなので、「記録を一時停止」と書いたのですが、たぶんそれは全体です。<CTRL>R:wBufWritePre<CTRL>R3undotree()

答え1

Vimの履歴を一時停止する必要はありません。実際のデータは、undotree()この関数を使用して検索できるツリーを形成します。もちろん、これをよりユーザーフレンドリーなものに変える多くのプラグインがあります。多くの軍隊モンド元に戻すツリー。元に戻す永続性も有効にすると(参照:h undo-persistence)、ファイルの完全な変更履歴を簡単に参照できます。

答え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

関連情報