5

'.私はvimのコマンドが好きです。から:help '.:

'.   `.

[ジャンプ先] 最後の変更が行われた位置。位置は、変更が開始された場所またはその近くです。

Ok。しかし、ここに私の問題があります。autocmd関数を使用して、ファイルヘッダーに「最終変更」行を追加します。したがって、すべての書き込みの後'.、「実際の」最後の変更ではなく、ファイルヘッダーに移動します。私の現在の解決策は、現在の編集ポイントを でマークすることを忘れないようにして、そこに戻るmaことができるようにすることです。'a私はときどき忘れますが、覚えていても、あと数回のキーストロークです。

私の理想的な解決策は、vimに動きを覚えないように指示するある種のコマンドです。関数がジャンプする前にこのコマンドを送信しautocmdて、最後に変更された行を書き込み、関数が終了した後にキャンセルすることができautocmdます。そうすれば、関連付けられている場所'.は変更されません。ただし、より効率的な他のオプションについてはオープンです。

見たい場合は、 が で行うことを次に示しautocmdます:w

function! UpdateHeader()
    let b:winview = winsaveview()

    " This is where I'd put the command to ignore future movements

    "The periods concatenate all the arguments into one command.
    "Silent! suppresses errors, usually 'pattern not found'
    "The 1,6g means search only lines 1 thru 6
    "Search for File Name: followed by anything
    "'s'ubstitute
    "Substitute in 'File Name: ' and the results of the expand command, on the
    "current filename
    execute "silent! 1," . 6 . "g/File Name:.*/s//File Name: " . expand("%")
    execute "silent! 1," . 6 . "g/Last Modified:.*/s//Last Modified: " . strftime("%d-%m-%Y")

    " This is where I'd put the command to start remembering movements again

    call winrestview(b:winview)
endfunction
4

3 に答える 3

4

で使用でき:keepjumps {command}ますautocmd

を参照してください:help :keepjumps

于 2013-07-02T19:57:26.823 に答える
3

で試してみ:lockmarks <command>てくださいautocmd。これのヘルプは'.、コマンドによって変更されないものの1つであると述べています。

于 2013-07-02T19:42:44.783 に答える
1

これを行うもっときれいな方法があるかもしれませんが、単に別のマークでその場所を保存するのはどうですか? 例えば:

" This is where I'd put the command to ignore future movements
" go to the mark and label it as z
`.mz

" This is where I'd put the command to start remembering movements again
" return to your mark and create a fake edit there to reset the most recent edit mark
`zi <Esc>x
于 2013-07-02T18:30:00.827 に答える