aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vim/autoload/shebang.vim7
-rw-r--r--vim/filetype.vim13
-rw-r--r--vim/plugin/shebang_update.vim20
3 files changed, 13 insertions, 27 deletions
diff --git a/vim/autoload/shebang.vim b/vim/autoload/shebang.vim
deleted file mode 100644
index f39fcf48..00000000
--- a/vim/autoload/shebang.vim
+++ /dev/null
@@ -1,7 +0,0 @@
-" If the first line was changed in the last insert operation, re-run script
-" detection
-function! shebang#Update() abort
- if line("'[") == 1
- runtime scripts.vim
- endif
-endfunction
diff --git a/vim/filetype.vim b/vim/filetype.vim
index ad2545a0..bda01984 100644
--- a/vim/filetype.vim
+++ b/vim/filetype.vim
@@ -42,6 +42,13 @@ function! s:StripRepeat()
endfunction
+" Check if the first line is a shebang
+function! s:CheckShebang()
+ if line('''[') == 1 && stridx(getline(1), '#!') == 0
+ doautocmd filetypedetect BufRead
+ endif
+endfunction
+
" Use our own filetype detection rules
augroup filetypedetect
autocmd!
@@ -508,4 +515,10 @@ augroup filetypedetect
\| runtime scripts.vim
\|endif
+ " If supported, on leaving insert mode, check whether the first line was "
+ " changed and is a shebang format, and if so, re-run filetype detection
+ if v:version > 700
+ autocmd InsertLeave * call s:CheckShebang()
+ endif
+
augroup END
diff --git a/vim/plugin/shebang_update.vim b/vim/plugin/shebang_update.vim
deleted file mode 100644
index 60031e26..00000000
--- a/vim/plugin/shebang_update.vim
+++ /dev/null
@@ -1,20 +0,0 @@
-"
-" shebang_update.vim: If the first line of a file was changed, re-run "
-" scripts.vim to do shebang detection to update the filetype.
-"
-" Author: Tom Ryder <tom@sanctum.geek.nz>
-" License: Same as Vim itself
-"
-if exists('g:loaded_shebang_update') || &compatible
- finish
-endif
-if v:version < 700
- finish
-endif
-let g:loaded_shebang_update = 1
-
-" Call the update function whenever leaving insert mode
-augroup shebang_update
- autocmd!
- autocmd InsertLeave * call shebang#Update()
-augroup END