4

Is there any console- or window-based text editor that automatically reloads file changed on disk without prompting anything?

2

vim can do that. Just add

set autoread

to your ~/.vimrc. (Also check out the Tail Bundle plugin.)
The autoread setting applies only certain events (which can be determined by checking the help text for timestamp (:h timestamp)). To make vim load files more frequently, there are two decent options:

  1. Define a function which watches for changes.
  2. Set an autocommand such as:

    au FocusGained,BufEnter,BufWinEnter,CursorHold,CursorMoved * :checktime
    

    This will reload whenever vim gains focus, you enter the buffer, move a cursor, idle the cursor. It won't change the current cursor position though.

emacs can also do this, if you add to your .emacs:

(global-auto-revert-mode t)

This doesn't watch for changes either, but the following should:

(global-auto-revert-tail-mode t)

This is supposed to work like tail -f, according to the EmacsWiki.

Even if gedit doesn't support this, I'm sure there are plenty of other GUI editors which do.

Sources:

  1. Can vim monitor realtime changes to a file
  2. How to have Emacs auto-refresh all buffers when files have changed on disk?
  • Dear @muru, I am using Ubuntu 14.04. set autoread did not work. I have installed TailBundle but vim did not autoload the file. I do not know why. Should I write a command in vim? emacs works perfectly but there is an annoying period of waiting for the file to be updated. Is this waiting period related with a parameter (file check interval parameter, etc.)? – Kadir Aug 26 '14 at 4:38
  • I am using vim, not vim-tiny. I have added set nocompatible, but the problem persists. – Kadir Aug 26 '14 at 5:15
  • @Kadir I have updated the answer with a few more options. – muru Aug 26 '14 at 6:53
0

Emacs can do that for you. It is called revert-buffer in Emacs. If you want to enable it for every file that you open in Emacs, add the following to your ~/.emacs or .emacs.d/init.el file:

 (global-auto-revert-mode 1)

See the Emacs Wiki for more information. This Ubuntu Forums post may also be helpful.

0

For those who like something more modern, Sublime Text does this by default.

// Always prompt before reloading a file, even if the file hasn't been
// modified. The default behavior is to automatically reload a file if it
// hasn't been edited. If a file has unsaved changes, a prompt will always
// be shown.
"always_prompt_for_file_reload": false,
0

g/vim can do this when using this command:

:set autoread | au CursorHold * checktime | call feedkeys("lh")

(To scroll down automatically use ...feedkeys("G") instead (but it scrolls down every visible buffer, even when split)

... you can find explanation and additional information in this stackoverflow question/answer https://stackoverflow.com/a/48296697/4940240

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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