强制 vim 覆盖外部更改 [英] force vim to overwrite external changes
问题描述
我使用 Vim 7.4 (Mac OS) 来编辑和运行 Lua 脚本.我已经在我的 .vimrc 中映射了一个键来保存当前缓冲区并运行一个外部脚本.
I use Vim 7.4 (Mac OS) to edit and run Lua scripts. I've mapped a key in my .vimrc to save the current buffer and run an external script.
.vimrc 中的按键映射:
The key map in .vimrc:
map V :w!<CR> :!python "$HOME/tools/client/concli.py" --lua %<CR>
它工作正常,但每隔一段时间,Xcode(触摸外壳命令)就会触摸"文件.然后当我点击映射键时,vim 警告我文件已在外部更改,我必须确认写入.
It works fine but every once in a while the files are 'touched' by Xcode (touch shell command). Then when I hit the mapped key vim warns me that the file has been changed externally and I have to confirm to write to it.
这很烦人,因为文件经常被触及.如何强制 vim 在没有提示的情况下覆盖外部更改?我试过'w!'没有成功.
This is quite annoying since the files are often touched. How could I force vim to overwrite external changes without prompting? I tried 'w!' without success.
谢谢你,劳伦特
推荐答案
确实,:w!
无法关闭覆盖确认,而 :set autoread
不会在这种情况下也无济于事.有效的是指示 Vim 在写入之前显式检查更改:
Indeed, the overwrite confirmation cannot be turned off with :w!
, and :set autoread
doesn't help in this case, neither. What does work is instructing Vim to explicitly check for changes before the write:
:checktime | w
这篇关于强制 vim 覆盖外部更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!