From 982fea1d41f6bcfe23c2ebde908419201052c455 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 9 Jun 2019 15:54:05 +1200 Subject: Refactor filetype reloading with command --- vim/vimrc | 31 ++++++++++++++----------------- 1 file 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 - \|if exists('#filetypedetect#BufRead') - \| doautocmd filetypedetect BufRead - \|endif + \ source | FileTypeReload endif " Keep the viminfo file in a cache subdirectory of $MYVIM, creating that @@ -764,7 +761,7 @@ nnoremap e :setlocal modifiable noreadonly nnoremap f :setlocal formatoptions? " \F reloads filetype plugins -nnoremap F :doautocmd filetypedetect BufRead +nnoremap F :FileTypeReload " \g shows the current file's fully expanded path nnoremap g :echo expand('%:p') -- cgit v1.2.3