aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-10 16:53:54 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-10 16:58:04 +1200
commitc385dd086df401b8f9bf56e652d14e1e10865b6a (patch)
treed0233a05ddd98b21b3e363c434ae9e7d3c67e7d2
parentBump VERSION (diff)
downloaddotfiles-c385dd086df401b8f9bf56e652d14e1e10865b6a.tar.gz
dotfiles-c385dd086df401b8f9bf56e652d14e1e10865b6a.zip
Refactor vimrc reload and source hooks
-rw-r--r--vim/vimrc43
1 files changed, 20 insertions, 23 deletions
diff --git a/vim/vimrc b/vim/vimrc
index ce3d3d7d..eda0e98b 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -175,23 +175,11 @@ augroup vimrc
autocmd!
augroup END
-" If this file or the vimrc stub that calls it is written to by Vim, we'd like
-" to reload the stub vimrc and thereby the main vimrc, so that our changes
-" apply immediately in the current editing session. This often makes broken
-" changes immediately apparent.
-"
-autocmd vimrc BufWritePost $MYVIMRC
- \ source $MYVIMRC
-if $MYVIMRC !=# ''
- autocmd vimrc BufWritePost $MYVIM/vimrc
- \ doautocmd vimrc BufWritePost $MYVIMRC
-endif
-
-" Similarly, if this file or the vimrc stub that calls it is sourced, whether
-" because of the above hook, or the <Leader>R mapping prescribed later in this
-" file, add a hook that re-runs filetype detection and thereby ftplugin
-" loading. This is chiefly so that any global options set in this file don't
-" trample over needed buffer-local settings.
+" If this file or the vimrc stub that calls it is sourced, whether because of
+" the above hook, or the <Leader>R mapping prescribed later in this file, add
+" a hook that re-runs filetype detection and thereby ftplugin loading. This
+" is chiefly so that any global options set in this file don't trample over
+" needed buffer-local settings.
"
" We'll abstract this away a bit behind a new user command named
" FileTypeReload, which just re-runs BufRead events for filetype detection if
@@ -216,12 +204,21 @@ command! FileTypeReload
" exists first.
"
if exists('##SourceCmd')
- autocmd vimrc SourceCmd $MYVIMRC
- \ source <afile> | FileTypeReload
- if $MYVIM !=# ''
- autocmd vimrc SourceCmd $MYVIM/vimrc
- \ doautocmd vimrc SourceCmd $MYVIMRC
- endif
+ autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc
+ \ source <sfile> | FileTypeReload
+endif
+
+" If this file or the vimrc stub that calls it is written to by Vim, we'd like
+" to reload the stub vimrc and thereby the main vimrc, so that our changes
+" apply immediately in the current editing session. This often makes broken
+" changes immediately apparent. We can lean on the SourceCmd hook we just
+" established to do this; in fact, we'll only establish this hook if we can do
+" so, because otherwise filetype plugins won't reload, and options like
+" 'shiftwidth' might be set incorrectly.
+"
+if exists('#vimrc#SourceCmd')
+ autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc
+ \ doautocmd vimrc SourceCmd
endif
" Keep the viminfo file in a cache subdirectory of the user runtime directory,