Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get notified when file is changed by another application?

Tags:

vim

Before I heard about vim, I used to use gedit. I still try to make vim behave as same as gedit, this is because I have asked many questions related to vim on StackOverflow.

One feature I am missing is when any file was modified while I was working on any file on gedit by another application, a popup use to come which says The file <file_location> changed on disk. Do you want to reload the file? And there were two buttons named Reload and Cancel respectively.


What I want:

(Please note that I am using vim, not gvim) I want similar feature in vim. I want if any file get changed on disk, a warning message come at status bar:

File changed, press F9 to reload.

I will map my F9 to do :e.

like image 625
Santosh Kumar Avatar asked Aug 23 '12 12:08

Santosh Kumar


People also ask

Is there a way to get notified when someone edits a Google Doc?

Notification settings. Under “Edits,” choose when you want to receive notifications: Added or removed content: You'll be notified whenever anyone adds or removes content in that file. None: Never receive emails about edits for that file.

How can I be notified when an Excel file is updated?

Turn notifications on or off for all filesRight-click the OneDrive icon (looks like a white cloud) on the system tray of your task bar and select Settings. On the Settings tab, you'll find a check box to enable or disable notifications.

Can SharePoint notify when document changes?

You can get an alert whenever a file, link, or folder is changed in a SharePoint document library. Depending on the item (file, folder, link), you may see different options when you set an alert.


1 Answers

If autoread is set, vim checks whether the file has been modified after each shell command (:!), on writing the file, and when you issue :checktime. gvim in addition checks when you switch window focus to the application.

You can execute :checktime periodically using the recipe at http://vim.wikia.com/wiki/Timer_to_execute_commands_periodically:

autocmd CursorHold * call Timer()
function! Timer()
    call feedkeys("f\e")
    checktime
endfunction
set updatetime=5000  " milliseconds

To just print a warning, set the autocmd FileChangedShell (Detect file change, offer to reload file):

autocmd FileChangedShell * echo "File changed, press F9 to reload."

For Insert mode, use CursorHoldI (not sure about this feedkeys sequence, but it seems to work):

autocmd CursorHoldI * call TimerI()
function! TimerI()
    call feedkeys("\<C-R>\e")
    checktime
endfunction

You might have to change the FileChangedShell autocmd from echo to echoe, as I don't think echo gets printed in Insert mode.

like image 116
ecatmur Avatar answered Sep 30 '22 18:09

ecatmur