Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force vim to overwrite external changes

Tags:

vim

vi

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.

The key map in .vimrc:

map V :w!<CR> :!python "$HOME/tools/client/concli.py" --lua %<CR>

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.

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.

Thank you, Laurent

like image 750
Laurent Zubiaur Avatar asked Feb 19 '26 06:02

Laurent Zubiaur


2 Answers

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
like image 124
Ingo Karkat Avatar answered Feb 20 '26 18:02

Ingo Karkat


I believe

set autoread

should do it. It tells Vim to automatically re-reads the file changed outside Vim.

like image 20
Rook Avatar answered Feb 20 '26 19:02

Rook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!