aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-06 17:24:37 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-06 17:31:54 +1200
commitce4527cca3d1aacde321fc3826decb2047df65cc (patch)
treeaec29f5427d0b6b8e65ae7cc39c21bf2f3a03036
parent5611cdf4c76981205f6a39c5179041c3ab45dbd2 (diff)
downloaddotfiles-ce4527cca3d1aacde321fc3826decb2047df65cc.tar.gz
Add custom scripts.vim
Including adding sed support
-rw-r--r--Makefile3
-rw-r--r--vim/filetype.vim69
-rw-r--r--vim/scripts.vim52
3 files changed, 71 insertions, 53 deletions
diff --git a/Makefile b/Makefile
index bb54b280..e5652913 100644
--- a/Makefile
+++ b/Makefile
@@ -494,6 +494,7 @@ install-vim: install-vim-after \
install-vim-bundle \
install-vim-compiler \
install-vim-config \
+ install-vim-filetype \
install-vim-ftplugin \
install-vim-indent
@@ -540,7 +541,7 @@ install-vim-config:
install-vim-filetype:
cp -p -- vim/filetype.vim $(VIMDIR)
- cp -p -- vim/script.vim $(VIMDIR)
+ cp -p -- vim/scripts.vim $(VIMDIR)
install-vim-ftplugin:
mkdir -p -- $(VIMDIR)/ftplugin
diff --git a/vim/filetype.vim b/vim/filetype.vim
index 3e244610..a76321a2 100644
--- a/vim/filetype.vim
+++ b/vim/filetype.vim
@@ -4,7 +4,7 @@ if exists('g:did_load_filetypes')
endif
let g:did_load_filetypes = 1
-" Use only the rules in ftdetect
+" Use our own filetype detection rules
augroup filetypedetect
autocmd!
@@ -12,11 +12,6 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ *.awk
\ setfiletype awk
- autocmd BufNewFile,BufRead
- \ *
- \ if getline(1) =~# '\m^#!.*\<[gm]\?awk\>'
- \ | setfiletype awk
- \ | endif
" C files
autocmd BufNewFile,BufRead
\ *.c,*.h
@@ -97,32 +92,14 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ *.pl,*.pm,*.t,Makefile.PL
\ setfiletype perl
- autocmd BufNewFile,BufRead
- \ *
- \ if getline(1) =~# '\m^#!.*\<perl\>'
- \ | setfiletype perl
- \ | endif
" Perl 6 files
autocmd BufNewFile,BufRead
\ *.p6,*.pl6,*.pm6
\ setfiletype perl6
- autocmd BufNewFile,BufRead
- \ *
- \ if getline(1) =~# '\m^#!.\<perl6\>'
- \ | setfiletype perl6
- \ | endif
" PHP files
autocmd BufNewFile,BufRead
\ *.php
\ setfiletype php
- autocmd BufNewFile,BufRead
- \ *
- \ if getline(1) =~# '\m^#!.\<php\>'
- \ | setfiletype php
- \ | endif
- \ | if getline(1) =~? '\m^<?php\>'
- \ | setfiletype php
- \ | endif
" Perl 5 POD files
autocmd BufNewFile,BufRead
\ *.pod
@@ -135,11 +112,6 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ *.py
\ setfiletype python
- autocmd BufNewFile,BufRead
- \ *
- \ if getline(1) =~# '\m^#!.*\<python[23]\?\>'
- \ | setfiletype python
- \ | endif
" Readline configuration file
autocmd BufNewFile,BufRead
\ .inputrc,inputrc
@@ -148,7 +120,7 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ *.rem,*.remind,.reminders
\ setfiletype remind
- " Bash filename patterns
+ " Bash shell
autocmd BufNewFile,BufRead
\ *.bash,
\.bash_aliases,
@@ -160,14 +132,14 @@ augroup filetypedetect
\bashrc
\ let b:is_bash = 1
\ | setfiletype sh
- " Korn shell filename patterns
+ " Korn shell
autocmd BufNewFile,BufRead
\ *.ksh,
\.kshrc,
\kshrc
\ let b:is_kornshell = 1
\ | setfiletype sh
- " POSIX/Bourne shell filename patterns
+ " POSIX/Bourne shell
autocmd BufNewFile,BufRead
\ *.sh,
\.profile,
@@ -182,22 +154,10 @@ augroup filetypedetect
\xinitrc
\ let b:is_posix = 1
\ | setfiletype sh
- " If this file has a shebang, and we haven't already decided it's Bash or
- " Korn shell, use the shebang to decide
+ " sed files
autocmd BufNewFile,BufRead
- \ *
- \ if !exists('b:is_bash') && !exists('b:is_kornshell')
- \ | if getline(1) =~# '\m^#!.*\<bash\>'
- \ | let b:is_bash = 1
- \ | setfiletype sh
- \ | elseif getline(1) =~# '\m^#!.*\<ksh\>'
- \ | let b:is_ksh = 1
- \ | setfiletype sh
- \ | elseif getline(1) =~# '\m^#!.*\<sh\>'
- \ | let b:is_posix = 1
- \ | setfiletype sh
- \ | endif
- \ | endif
+ \ *.sed
+ \ setfiletype sed
" tmux configuration files
autocmd BufNewFile,BufRead
\ .tmux.conf,tmux.conf
@@ -242,12 +202,17 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ *.zsh,.zprofile,zprofile,.zshrc,zshrc
\ setfiletype zsh
- autocmd BufNewFile,BufRead
+
+ " Load any extra rules in ftdetect directories
+ runtime! ftdetect/*.vim
+
+ " If we still don't have a filetype, run the scripts.vim file that will
+ " examine actual file contents--but only the first one; don't load the
+ " system one at all
+ autocmd BufNewFile,BufRead,StdinReadPost
\ *
- \ if getline(1) =~# '^#!.*\<zsh\>'
- \ | setfiletype zsh
+ \ if !did_filetype()
+ \ | runtime scripts.vim
\ | endif
- runtime! ftdetect/*.vim
augroup END
-
diff --git a/vim/scripts.vim b/vim/scripts.vim
new file mode 100644
index 00000000..1d4e1eb1
--- /dev/null
+++ b/vim/scripts.vim
@@ -0,0 +1,52 @@
+" Try to determine filetype by examining actual file contents; read as little
+" as possible, and try to keep things simple and specific to what I typically
+" work on, and will expect to be syntax-highlighted.
+
+" Read first line
+let s:line = getline(1)
+
+" If it's not a shebang, we're done
+if s:line !~# '\m^#!'
+ finish
+endif
+
+" AWK
+if s:line =~# '\m\<[gm]\?awk\>'
+ setfiletype awk
+
+" Perl 5
+elseif s:line =~# '\m\<perl\>'
+ setfiletype perl
+
+" Perl 6
+elseif s:line =~# '\m\<perl6\>'
+ setfiletype perl6
+
+" PHP
+elseif s:line =~# '\m\<php\>'
+ setfiletype php
+
+" Python
+elseif s:line =~# '\m\<python[23]\>'
+ setfiletype python
+
+" sed
+elseif s:line =~# '\m\<sed\>'
+ setfiletype sed
+
+" Bash
+elseif s:line =~# '\m\<bash\>'
+ let b:is_bash = 1
+ setfiletype sh
+
+" Korn shell
+elseif s:line =~# '\m\<\(m\|pd\)ksh\(93\)\?\>'
+ let b:is_kornshell = 1
+ setfiletype sh
+
+" POSIX/Bourne shell
+elseif s:line =~# '\m\<sh\>'
+ let b:is_posix = 1
+ setfiletype sh
+
+endif