refresh changed content of file opened in vi(m)

  • I have a config-file that I keep open in vim, but that sometimes gets changed on disk, without these changes being reflected on the terminal. Can I refresh the content on the screen without closing and re-opening the file? If so, how?

    Wrap up: all the answers so far are of "Poll" instead of "Push" style. That is, instead of receiving an external file change event like it was done by other software's similar features, these answers rely on vim actively polling the file change, either manually or triggered by a user action or a timer. The end result is you won't see change refreshed on screen instantaneously.

  • Thushi

    Thushi Correct answer

    6 years ago

    You can use the :edit command, without specifying a file name, to reload the current file. If you have made modifications to the file, you can use :edit! to force the reload of the current file (you will lose your modifications).

    The command :edit can be abbreviated by :e. The force-edit can thus be done by :e!

    The "!" was tripping me, but now it's clear.

    Note: that's typically abbreviated to `:e!`.

    @StephaneChazelas: Yeah,That's correct :) @twan163: Instead of `:edit` and `:edit!` you can use `:e` and `:e!` respectively.

    Lose modifications, yes and no. Crucially, you can still `u`ndo the `:e!`.

    Also, if you want to reload all your buffers, run: `:bufdo e`

    @gerrit: Lose modifications, Definitely yes :) But you can recover the lost modifications by `u`ndoing. :)

    `:w|e` **w**rite *and* **e**dit (reload) :)

    `|` is for chaining commands, and can be interpreted as *then* executing commands in sequential order.

License under CC-BY-SA with attribution


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