aboutsummaryrefslogtreecommitdiff
path: root/plugin/vimrc_reload_filetype.vim
blob: 77675fdf334d4702d5739e771645ac3c514179fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"
" vimrc_reload_filetype.vim: Add hook to reload active buffer's filetype when
" vimrc reloaded, so that we don't end up indenting four spaces in an open
" VimL file, etc.  Requires Vim 7.1 or 7.0 with patch 187 for SourceCmd.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
if exists('g:loaded_vimrc_reload_filetype') || &compatible
  finish
endif
if !has('autocmd') || !exists('##SourceCmd')
  finish
endif
let g:loaded_vimrc_reload_filetype = 1

" Wrapper function reloads .vimrc and filetypes
function! s:Reload() abort
  source <afile>
  if exists('#filetypedetect#BufRead')
    doautocmd filetypedetect BufRead
  endif
  redraw
  echomsg 'Reloaded vimrc: '.expand('<afile>')
endfunction

" This SourceCmd intercepts :source for .vimrc
augroup vimrc_reload_filetype
  autocmd!
  autocmd SourceCmd $MYVIMRC call s:Reload()
augroup END