我喜歡vim中的'.
命令。從:help '.
:防止Vim記住更改
'. `.
[跳轉到]其中最後做出更改的位置。該位置在變化開始的位置或附近。
好的。但這是我的問題:我使用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
完美。謝謝。 – ravron
任何想要實現這個解決方案的人都會注意到:*文本*實際修改發生時需要'keepjumps'命令* - 即':g'命令運行的':s'命令:'execute'沉默!1,「。 6。 「g /文件名:。*/keepjumps s //文件名:」。擴展( 「%」)'。 – ravron
還有一點需要注意:在前面的註釋中寫入的命令確實會阻止設置「。」。但是,它仍然增加了跳轉列表。爲了防止那*,在'silent!'之後再次添加'keepjumps'。 – ravron