Vimr: Reread file when window gains focus

Created on 15 May 2018  ·  3Comments  ·  Source: qvacua/vimr

If a file has been changed on disk, MacVim prompts you when the window gains focus and asks if you want to reload that file from disk. It'd be awesome if VimR did the same! I've been confused a few times when switching back to VimR and seeing outdated content.

Most helpful comment

I was hoping for some kind of dialog allowing me to choose what to do, like MacVim does, but the snippet is better than nothing I guess.

init_vim_____config_nvim__-_vim

All 3 comments

You can set that in your .vimrc or init.nvim or wherever your config lives. I have the following:

set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif
autocmd FileChangedShellPost *
      \ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None

Works nicely, and prints a little message in the statusline when files get reloaded.

@nornagon Does the above snippet by @bowmanmike work for you?

I was hoping for some kind of dialog allowing me to choose what to do, like MacVim does, but the snippet is better than nothing I guess.

init_vim_____config_nvim__-_vim

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hakamadare picture hakamadare  ·  4Comments

romaninsh picture romaninsh  ·  7Comments

qvacua picture qvacua  ·  7Comments

pjg picture pjg  ·  8Comments

risentveber picture risentveber  ·  4Comments