aboutsummaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorTeddy Wing2014-06-03 08:32:17 -0400
committerTeddy Wing2014-06-03 08:32:17 -0400
commit0d89392cdc386c5dc179386d0e51f82bcf24bf7d (patch)
tree973cc2b4643fbb8da9092cd5f6a0343285d6b5db /plugin
parent29b6982434f0311669043a1a00d2f06bf28b7ab7 (diff)
downloaddotvim-0d89392cdc386c5dc179386d0e51f82bcf24bf7d.tar.bz2
Add custom plugin better_autoread
Make a plugin out of a Stack Overflow post for a better autoread augroup. The `autoread` setting in vim will automatically reload a file if it's been changed outside of vim (if you've made unsaved changes vim will prompt before loading the file). By default, however, vim doesn't automatically detect when a file has changed. It only happens when you do certain things. This sets up an autocmd to force a check a bit more often by tying into the CursorHold events. A bit hackish it seems but it works like a charm. This has been sorely needed especially since yesterday when I was switching git branches in a project several times and editing various files only to be alerted upon saving that the file on disk has changed. Previously I would say it was a minor annoyance to have to type :e! in those situations. Yesterday it was a freaking pain in the glaiven since it happened unexpectedly so many times and after I was ready to commit/save edits.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/better_autoread.vim22
1 files changed, 22 insertions, 0 deletions
diff --git a/plugin/better_autoread.vim b/plugin/better_autoread.vim
new file mode 100644
index 0000000..e8625a1
--- /dev/null
+++ b/plugin/better_autoread.vim
@@ -0,0 +1,22 @@
+" Better autoread
+" Better detection for when files have changed outside of vim. Will
+" automatically reload files if they changed. If you've made modifications to
+" the file, you'll be prompted before the file is loaded.
+"
+" Taken from Greg Sexton:
+" http://stackoverflow.com/a/10962191
+
+set autoread
+augroup checktime
+ autocmd!
+ if !has("gui_running")
+ "silent! necessary otherwise throws errors when using command
+ "line window.
+ autocmd BufEnter * silent! checktime
+ autocmd CursorHold * silent! checktime
+ autocmd CursorHoldI * silent! checktime
+ "these two _may_ slow things down. Remove if they do.
+ " autocmd CursorMoved * silent! checktime
+ " autocmd CursorMovedI * silent! checktime
+ endif
+augroup END