Refresh all files in buffer from disk in vim

GitVimBuffer

Git Problem Overview


The command to refresh a file from version on disk is :e!

How can I do the same for all files in the buffer?

Background: I need that because I am using git with multiple branches with one vim open that contains a buffer. When I checkout a branch, I would like to have vim refresh.

Git Solutions


Solution 1 - Git

The :checkt[ime] command is designed for this very purpose.

It will prompt you to reload any buffers that have changed; if you wish to skip the prompt, you can do :set autoread beforehand (you'll still get a prompt on buffers with local unsaved changes).

It also avoids the syntax highlighting issue mentioned by Steven Lu on the accepted answer; :bufdo turns off syntax highlighting by design.

Found via: http://vim.1045645.n5.nabble.com/Bug-report-bufdo-e-breaking-syntax-highlighting-on-displayed-buffers-tp1209995p1209998.html

Solution 2 - Git

Read the documentation for bufdo, it should do what you want.

Solution 3 - Git

Here's what I ended up putting in my .vimrc:

fun! PullAndRefresh()
  set noconfirm
  !git pull
  bufdo e!
  set confirm
endfun

nmap <leader>gr call PullAndRefresh()

Solution 4 - Git

From :help autoread:

> 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. When the file has been deleted this is not done.

If, like me, you just want to always passively reload stale-but-unmodified buffers, then this seems like it should get the job done.

However the final detail is when vim notices the stale buffer. That can be forced with checktime. If you have focus events set up, then we can run checktime whenever we gain focus like so:

set autoread
autocmd FocusGained * checktime

This answer also has some interesting details.

Solution 5 - Git

As @Matthew S Mentioned here https://vi.stackexchange.com/a/462, you can use:

:set noconfirm
:bufdo !e
:set confirm

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionodwlView Question on Stackoverflow
Solution 1 - GitPaul FenneyView Answer on Stackoverflow
Solution 2 - GitpmfView Answer on Stackoverflow
Solution 3 - GitIvanView Answer on Stackoverflow
Solution 4 - GitphsView Answer on Stackoverflow
Solution 5 - GitMOHREView Answer on Stackoverflow