How does Vim's autoread work?

how does vim work
vim tutorial
vim editor commands
vim mac
vim linux
how to use vim
vim save and quit
vim modes

:h autoread says:

When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically read it again.

After putting set autoread in my vimrc, I open a file with Vim, switch to another editor, change the file, and wait to see the changes in Vim as well. Nothing happens. I have to use :e to reload the file with the new content.

What did I miss?                                                                I'm using Vim 7.2 on Mac 10.5.8

Autoread does not reload file unless you do something like run external command (like !ls or !sh etc) vim does not do checks periodically you can reload file manually using :e

More details in this thread: Click here

Linux vim command help and examples, " command on the Linux shell followed by the path of the file that you want to edit. [enter] means to press the return or enter key on your keyboard. The word --insert-- will appear at the bottom of the editor window to show that you are in insert mode now. Vim (/ v ɪ m /; a contraction of Vi IMproved) is a clone, with additions, of Bill Joy's vi text editor program for Unix. Vim's author, Bram Moolenaar, based it on the source code for a port of the Stevie editor to the Amiga and released a version to the public in 1991.

I use the following snippet which triggers autoread whenever I switch buffer or when focusing vim again:

au FocusGained,BufEnter * :silent! !

Also, it makes sense to use it in combination with the following snippet so that the files are always saved when leaving a buffer or vim, avoiding conflict situations:

au FocusLost,WinLeave * :silent! w

EDIT: If you want to speed up the write by disabling any hooks that run on save (e.g. linters), you can prefix the w command with noautocmd:

au FocusLost,WinLeave * :silent! noautocmd w

Popular Vim Commands - Comprehensive Vim Cheat Sheet, but it also has code highlighting. Both have these 4 basic modes: write mode. Description. vim is a text editor that is upwards compatible to Vi.There are a lot of enhancements above Vi: multi level undo, multiple windows and buffers, syntax highlighting, command line editing, file name completion, a complete help system, visual selection, and others.

As per my posting on superuser.com

Autoread just doesn't work. Use the following.

http://vim.wikia.com/wiki/Have_Vim_check_automatically_if_the_file_has_changed_externally

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.

What is the difference between Vi and Vim?, Notice how the text is highlighted in Java syntax highlight colors. Because you started the file in Java, Vim will detect the syntax color. Save the  VIM (Vi IMproved) is little different from other conventional and modern IDEs as its key binding and functionalities depends on Modes and States of the editor.

Outside of gvim, autoread doesn't work for me.

To get around this I use this rather ugly hack.

set autoread
augroup checktime
    au!
    if !has("gui_running")
        "silent! necessary otherwise throws errors when using command
        "line window.
        autocmd BufEnter        * silent! checktime
        autocmd CursorHold      * silent! checktime
        autocmd CursorHoldI     * silent! checktime
        "these two _may_ slow things down. Remove if they do.
        autocmd CursorMoved     * silent! checktime
        autocmd CursorMovedI    * silent! checktime
    endif
augroup END

This seems to be what the script irishjava linked to does, but that lets you toggle this for buffers. I just want it to work for everything.

Getting started with Vim: The basics, This will be the first of a four-part (possibly longer) series covering how to use Vim and where to start using the world's best text editor. Note that  VIM allows users to execute shell commands from within VIM without exiting. All you have to do is enter the command…asciinema.org. Left to Right (Execute shell commands from Vim and jump back to editor) Guess what! Prepare to be amazed. Vim also supports make command from within your file!

Trigger when cursor stops moving

Add to your vimrc:

au CursorHold,CursorHoldI * checktime

By default, CursorHold is triggered after the cursor remains still for 4 seconds, and is configurable via updatetime.

Buffer change trigger

To have autoread trigger when changing buffers, add to your vimrc:

au FocusGained,BufEnter * checktime
Terminal window focus trigger

To have FocusGained (see above) work in plain vim, inside a terminal emulator (Xterm, tmux, etc) install the plugin: vim-tmux-focus-events

On tmux versions > 1.9, you'll need to add in .tmux.conf:

set -g focus-events on

Vim (text editor), These modes will allow you to do just about anything you need, including creating your document, saving your document and doing advanced  While Nano is also a good editor, you may still prefer using Vim. If that’s the case, let me show you how to install Vim on Ubuntu. Install Vim on Ubuntu. The good thing is that Ubuntu is available in the main Ubuntu repository. This means that you don’t have to do any extra effort in installing Vim on Ubuntu.

Vim 101: A Beginner's Guide to Vim, VIM (Vi IMproved) is little different from other conventional and modern IDEs as its key binding and functionalities depends on Modes and States of the editor. Vim editor is a tool for creating, editing, merging and performing the operations, as you may used to do in the editors like Wordpad, Notepad, etc. The editor is used more by the programmers as they like to be with their keyboard only, not making much use of a mouse or a touchpad.

How does Vim work?, Learn all the basics you need to start editing text in vi or vim. To delete 5 lines, you do Duration: 8:57 Posted: 4 Oct 2018 H ow do I undo a recent change in the vim text editor? Vim / vi text editor remembers all last changes, such as adding or deleting text or block of code. You can quickly revert all changes in vim using undo mode. This page shows how to undo recent changes and editing in Vim / vi text editor running on Linux or Unix-like systems.

Vim Basics in 8 Minutes, Press Esc to return to command mode. Now you have a few options to exit depending on how you opened vi. If you gave a file name: :w will write  Does not exit when there are changed hidden buffers. :qa[ll]!*, :quita[ll][!]* Quit Vim, all changes to the buffers (including hidden) are lost. Press Return to confirm the command. This answer doesn't reference all Vim write and quit commands and arguments. Indeed, they are referenced in the Vim documentation.

Comments
  • Yeah, I think the problem is that :set autoread only works in a gui vim, not from the terminal. I know this is an old question, but I had a very hard time finding any good help on this. The answer below with the WatchForChanges function is golden.
  • autoread can work in plain vim, inside a terminal emulator see this answer.
  • I really like the simplicity of this solution, so added it to the vim wiki as well.
  • Why not use :checktime to explicitly trigger the check without shelling out? Also Vim should already be doing this on FocusGained, you shouldn't need an autocmd for that!
  • How would I add this to my .vimrc to make this behaviour default?
  • @StevieP Here the relevant lines in my .vimrc.
  • Right on. Thanks @fphilipe!
  • Finally! I have tried quite a few suggestions for getting something like this to work, but none worked in a terminal. This gets the job done! Thanks.
  • Hi, thanks. Your comment reminded me that I posted this. Thought I would update the code as it didn't work well when using the command-line window (q:).
  • This works great! Can I ask though if you know of a way to get it to write a timestamp of when the file was read in (and the buffer reloaded) when checktime does its thing? That would be nice.
  • See the longer, sister answer here.
  • This worked the best for me, and covers all cases, it seems. Thanks!
  • This is the only solution that did the trick: I executed prettier --write * and all my files opened in vim get updated immediately - no need to change mode from normal to insert or do other things to see changes like in other answers.
  • Yay, this worked really well for me in neovim :D Thanks man!