How do I reload the current file?

  • Quite often I am working with files that are version controlled, so it is possible for changes to be made to them outside of Vim.

    What is a quick way to reload the file without having to close and reopen Vim? And is there a way to do this automatically?

    `" Compare buffer with saved version` `nnoremap gd :DiffSaved`

    If you have installed vim-faq, you can get an offline answer there: `:h vim-faq` and search `/reload`. The hard to memorize tag is `:h faq-5.8`.

  • xthrd

    xthrd Correct answer

    6 years ago

    The command you want is :e (short for :edit). If you use :edit! it will discard local changes and reload.

    You can also have vim do this automatically with set autoread in your vimrc.

    See this answer for caveats and solutions regarding `autoread`.

    To do this for all buffers, use `:bufdo :e` or `:bufdo :e!`

    @AaronH. thank you for that! i usually have hundreds of buffers open at a time and when switching branches, I usually just close down vim and restart to refresh all of the buffers with new contents. This will be a major timesaver!

    @AaronH. The second `:` is optional: `:bufdo e` will work the same.

    `nnoremap w :write \| sleep 1000m \| :checktime` 1s is the time taken by the linting tool to operate on the file. If you are using the default , type `\w` to trigger the action.

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM