tags:

views:

796

answers:

4

Hi all,

I have gvim installed which I use normally, and I also use vim when remotely connecting to the same computer.

When I have a file opened in gvim and it is changed from outside (i.e. new updates from repository), gvim offers to reload it.

However when such thing happens with vim, it does nothing until you try to save the file. It just warns you that file has changed but does not offer to reload it.

It there a setting to make vim do the same thing?

Thanks!

+4  A: 

This is done using an auto command called FileChangedShell. I'm too new to post links, but your best bet would be to read the autocmd part of the vim documentation (Google for that)

but the gist is to set something like the following line in your vimrc

:au FileChangedShell * echo "Warning: File changed on disk"
Matt Simmons
I don't think that's necessary, vim should warn you about the change automatically.
too much php
Though it does not, unfortunately.
Art
Art, did my suggestion work?
Matt Simmons
It didn't Matt, sorry
Art
Sorry Matt, it actually did, was looking at wrong file. It does display warning, but not actual prompt to reload though
Art
Ah, ok. No worries. Hope you can find what you're looking for!
Matt Simmons
+3  A: 

You can manually trigger the checking with :checktime. gvim does this everytime it regains focus, so it is not necessary that often to do the manual checking.

I don't know if there is a different approach (like automatically checking in a certain time interval).

ashcatch
That's right, gvim does that, but not vim
Art
+4  A: 

As ashcatch said, the :checktime command will check for changes on disk and prompt you to reload. So set Vim to run checktime automatically after some event. Which event to use is up to you. One possibility is to use CursorHold, which fires after you move the cursor and then let it sit still for updatetime milliseconds. (Default 4 seconds.)

:au CursorHold * checktime

You could also set it on WinEnter or BufWinEnter so it changes every time you switch between buffers/windows. If you're really paranoid you could set it on CursorMoved so it checks the file on disk every time you move the cursor, but that's probably overkill and may lag a bit.

See :h checktime, :h updatetime, :h autocmd-events-abc.

Brian Carper
I am so bad reading vim help... I am not sure why it just numbs my mind for some reason.
ojblass
Brian, vim says "No such group or event: CurshorHold * checktime "
Art
Sorry, typo. CurshorHold should have been Cursorhold.
Brian Carper
Thanks ^^ I've been wonderning how to do that for quite some time now. This works nice with `set autoread` to, which will re-read the file if its contents did not change.
Romuald Brunet
+1  A: 

If you want to open the updated file use

:e

It should reload the open file.

avadh