Refresh all files in buffer from disk in vim

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()

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


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

Tags:

Vim

Git

Buffer