Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Assuming that a file doesn't have unsaved changes in the VIM buffer, I'd like it to reload automatically if the file changes on disk. The most frequent use case for this is when I update the working copy in which the file resides.

How can I achieve this?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

In your ~/.vimrc:

set autoread
share|improve this answer

Autoread does not work correctly. The following works for me:

You need to first install the script from here.

I got the best results by calling the setup function directly, like so.

let autoreadargs={'autoread':1} 
execute WatchForChanges("*",autoreadargs) 

The reason for this, is that I want to run a ipython/screen/vim setup.

You can easily convert this into an enhanced version of view.

script the process..

mkdir -p ~/bin
cat <<`OUT` > ~/bin/vimviewer
#!/usr/bin/env sh
exec vim -n --cmd "source /home/bryan/.vim/.vimrc.watchforchanges | let autoreadargs={'autoread':1} | execute WatchForChanges('*',autoreadargs)" $@
`OUT`

chmod 755 ~/bin/vimviewer
vimview test.txt
share|improve this answer
    
If you're using one of the vim GUIs such as gVim or MacVim then the autoread command integrates fine with the rest of the environment. E.g. editing the file in some other program, another editor or from source control, then switching back to vim will autoread the updated files. The problem seems to be with how the terminal version of vim integrates. The terminal version can't tell when you switch between programs either in the GUI or using terminal multiplexers like tmux, so it fails to autoread at relevant times. It would be nice if vim would just subscribe to relevant file-system events. –  bames53 May 3 at 23:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.