aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-09 15:54:05 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-09 16:17:33 +1200
commit982fea1d41f6bcfe23c2ebde908419201052c455 (patch)
tree5d9130c87862be673f2b38077b884078aa0ea0ff
parentAdjust comment on vimrc reload hook (diff)
downloaddotfiles-982fea1d41f6bcfe23c2ebde908419201052c455.tar.gz
dotfiles-982fea1d41f6bcfe23c2ebde908419201052c455.zip
Refactor filetype reloading with command
-rw-r--r--vim/vimrc31
1 files changed, 14 insertions, 17 deletions
diff --git a/vim/vimrc b/vim/vimrc
index cdd48eed..dbf2e5da 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -152,29 +152,26 @@ autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc
" 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
+" they've been loaded.
+"
+command! FileTypeReload
+ \ if exists('did_load_filetypes')
+ \| doautocmd filetypedetect BufRead
+ \|endif
+
+" Note that the SourceCmd event wasn't added until Vim 7.0.187, so we need to
+" check it exists first.
+"
" If there's stuff in any of your ftplugins that doesn't cope well with being
" reloaded, and just assumes a single BufRead event, it might be necessary to
" rewrite those parts to be idempotent, or to add load guards around them so
" that they only run once.
"
-" Note that the SourceCmd event wasn't added until Vim 7.0.187, so we need to
-" check it exists first.
-"
if exists('##SourceCmd')
-
- " We can't wrap this in a script-local function like I normally would,
- " because without a load guard around it, Vim will get upset that we're
- " trying to redefine that function the next time this script loads.
- "
- " So, we just inline the whole thing into the hook. It's only four
- " commands, anyway, and I'd rather most if not all of the vimrc was reloaded
- " when we source it.
- "
autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc
- \ source <afile>
- \|if exists('#filetypedetect#BufRead')
- \| doautocmd filetypedetect BufRead
- \|endif
+ \ source <afile> | FileTypeReload
endif
" Keep the viminfo file in a cache subdirectory of $MYVIM, creating that
@@ -764,7 +761,7 @@ nnoremap <Leader>e :<C-U>setlocal modifiable noreadonly<CR>
nnoremap <Leader>f :<C-U>setlocal formatoptions?<CR>
" \F reloads filetype plugins
-nnoremap <Leader>F :<C-U>doautocmd filetypedetect BufRead<CR>
+nnoremap <Leader>F :<C-U>FileTypeReload<CR>
" \g shows the current file's fully expanded path
nnoremap <Leader>g :<C-U>echo expand('%:p')<CR>