aboutsummaryrefslogtreecommitdiff
path: root/vim/ftdetect
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-03 00:28:53 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-03 00:58:31 +1200
commit4b16fc4ecc4fdb002ad9c833af148918767ed806 (patch)
tree628fce5b093f12d55824c1dc72c9577afd98ed54 /vim/ftdetect
parente48591105d20a4ebe7abfc89acb9f881476b62b3 (diff)
downloaddotfiles-4b16fc4ecc4fdb002ad9c833af148918767ed806.tar.gz
dotfiles-4b16fc4ecc4fdb002ad9c833af148918767ed806.zip
Implement personal filetype.vim
This implements only the syntax highlighting for file types I regularly use and care about, implemented in the way I want them to work, with files named per type in ftdetect/*.vim. I have chosen only file types with which I regularly deal and for which syntax highlighting and filetype/indent plugins are actually useful. Most other files, e.g. system config files I edit infrequently and only with sudoedit(8), don't really benefit from that. Much of this is just copied from the distribution filetype.vim file, but some of it I do specifically in a way I want, such as the shell decision logic. We'll see how well this works.
Diffstat (limited to 'vim/ftdetect')
-rw-r--r--vim/ftdetect/awk.vim9
-rw-r--r--vim/ftdetect/c.vim4
-rw-r--r--vim/ftdetect/cpp.vim4
-rw-r--r--vim/ftdetect/css.vim4
-rw-r--r--vim/ftdetect/csv.vim2
-rw-r--r--vim/ftdetect/diff.vim4
-rw-r--r--vim/ftdetect/gitcommit.vim4
-rw-r--r--vim/ftdetect/gitconfig.vim4
-rw-r--r--vim/ftdetect/gpg.vim4
-rw-r--r--vim/ftdetect/html.vim4
-rw-r--r--vim/ftdetect/java.vim4
-rw-r--r--vim/ftdetect/javascript.vim4
-rw-r--r--vim/ftdetect/json.vim4
-rw-r--r--vim/ftdetect/lex.vim4
-rw-r--r--vim/ftdetect/lua.vim4
-rw-r--r--vim/ftdetect/m4.vim4
-rw-r--r--vim/ftdetect/make.vim4
-rw-r--r--vim/ftdetect/markdown.vim4
-rw-r--r--vim/ftdetect/muttrc.vim4
-rw-r--r--vim/ftdetect/perl.vim9
-rw-r--r--vim/ftdetect/perl6.vim9
-rw-r--r--vim/ftdetect/php.vim4
-rw-r--r--vim/ftdetect/pod.vim4
-rw-r--r--vim/ftdetect/pod6.vim4
-rw-r--r--vim/ftdetect/python.vim9
-rw-r--r--vim/ftdetect/readline.vim4
-rw-r--r--vim/ftdetect/remind.vim4
-rw-r--r--vim/ftdetect/sh.vim50
-rw-r--r--vim/ftdetect/tmux.vim4
-rw-r--r--vim/ftdetect/troff.vim4
-rw-r--r--vim/ftdetect/tsv.vim2
-rw-r--r--vim/ftdetect/vim.vim4
-rw-r--r--vim/ftdetect/viminfo.vim4
-rw-r--r--vim/ftdetect/xdefaults.vim2
-rw-r--r--vim/ftdetect/xhtml.vim4
-rw-r--r--vim/ftdetect/xml.vim4
-rw-r--r--vim/ftdetect/yacc.vim4
-rw-r--r--vim/ftdetect/yaml.vim4
-rw-r--r--vim/ftdetect/zsh.vim9
39 files changed, 209 insertions, 12 deletions
diff --git a/vim/ftdetect/awk.vim b/vim/ftdetect/awk.vim
new file mode 100644
index 00000000..ce845c52
--- /dev/null
+++ b/vim/ftdetect/awk.vim
@@ -0,0 +1,9 @@
+" AWK files
+autocmd BufNewFile,BufRead
+ \ *.awk
+ \ setfiletype awk
+autocmd BufNewFile,BufRead
+ \ *
+ \ if getline(1) =~ '^#!.*awk$'
+ \ | setfiletype awk
+ \ | endif
diff --git a/vim/ftdetect/c.vim b/vim/ftdetect/c.vim
new file mode 100644
index 00000000..77a73cb6
--- /dev/null
+++ b/vim/ftdetect/c.vim
@@ -0,0 +1,4 @@
+" C files
+autocmd BufNewFile,BufRead
+ \ *.c,*.h
+ \ setfiletype c
diff --git a/vim/ftdetect/cpp.vim b/vim/ftdetect/cpp.vim
new file mode 100644
index 00000000..71dc59e5
--- /dev/null
+++ b/vim/ftdetect/cpp.vim
@@ -0,0 +1,4 @@
+" C++ files
+autocmd BufNewFile,BufRead
+ \ *.c++,*.cpp,*.cxx,*.hh
+ \ setfiletype cpp
diff --git a/vim/ftdetect/css.vim b/vim/ftdetect/css.vim
new file mode 100644
index 00000000..bd98aa8e
--- /dev/null
+++ b/vim/ftdetect/css.vim
@@ -0,0 +1,4 @@
+" CSS files
+autocmd BufNewFile,BufRead
+ \ *.css
+ \ setfiletype css
diff --git a/vim/ftdetect/csv.vim b/vim/ftdetect/csv.vim
index a234c093..33468496 100644
--- a/vim/ftdetect/csv.vim
+++ b/vim/ftdetect/csv.vim
@@ -1,4 +1,4 @@
-" Add automatic commands to detect CSV files
+" CSV files
autocmd BufNewFile,BufRead
\ *.csv
\ setfiletype csv
diff --git a/vim/ftdetect/diff.vim b/vim/ftdetect/diff.vim
new file mode 100644
index 00000000..d19fc450
--- /dev/null
+++ b/vim/ftdetect/diff.vim
@@ -0,0 +1,4 @@
+" Diff and patch files
+autocmd BufNewFile,BufRead
+ \ *.diff,*.patch,*.rej
+ \ setfiletype diff
diff --git a/vim/ftdetect/gitcommit.vim b/vim/ftdetect/gitcommit.vim
new file mode 100644
index 00000000..1c21544a
--- /dev/null
+++ b/vim/ftdetect/gitcommit.vim
@@ -0,0 +1,4 @@
+" Git commit messages
+autocmd BufNewFile,BufRead
+ \ COMMIT_EDITMSG,MERGE_MSG,TAG_EDITMSG
+ \ setfiletype gitcommit
diff --git a/vim/ftdetect/gitconfig.vim b/vim/ftdetect/gitconfig.vim
new file mode 100644
index 00000000..780e89b0
--- /dev/null
+++ b/vim/ftdetect/gitconfig.vim
@@ -0,0 +1,4 @@
+" Git config files
+autocmd BufNewFile,BufRead
+ \ *.git*/config,.gitconfig,.gitmodules
+ \ setfiletype gitconfig
diff --git a/vim/ftdetect/gpg.vim b/vim/ftdetect/gpg.vim
new file mode 100644
index 00000000..ea6ec2f6
--- /dev/null
+++ b/vim/ftdetect/gpg.vim
@@ -0,0 +1,4 @@
+" GnuPG configuration files
+autocmd BufNewFile,BufRead
+ \ *gnupg/options,*gnupg/gpg.conf
+ \ setfiletype gpg
diff --git a/vim/ftdetect/html.vim b/vim/ftdetect/html.vim
new file mode 100644
index 00000000..f8ab7ac5
--- /dev/null
+++ b/vim/ftdetect/html.vim
@@ -0,0 +1,4 @@
+" HTML files
+autocmd BufNewFile,BufRead
+ \ *.html,*.htm
+ \ setfiletype html
diff --git a/vim/ftdetect/java.vim b/vim/ftdetect/java.vim
new file mode 100644
index 00000000..101816ea
--- /dev/null
+++ b/vim/ftdetect/java.vim
@@ -0,0 +1,4 @@
+" Java files
+autocmd BufNewFile,BufRead
+ \ *.java,*.jav
+ \ setfiletype java
diff --git a/vim/ftdetect/javascript.vim b/vim/ftdetect/javascript.vim
new file mode 100644
index 00000000..6f129960
--- /dev/null
+++ b/vim/ftdetect/javascript.vim
@@ -0,0 +1,4 @@
+" JSON files
+autocmd BufNewFile,BufRead
+ \ *.js
+ \ setfiletype javascript
diff --git a/vim/ftdetect/json.vim b/vim/ftdetect/json.vim
new file mode 100644
index 00000000..fd27c845
--- /dev/null
+++ b/vim/ftdetect/json.vim
@@ -0,0 +1,4 @@
+" JSON files
+autocmd BufNewFile,BufRead
+ \ *.json
+ \ setfiletype json
diff --git a/vim/ftdetect/lex.vim b/vim/ftdetect/lex.vim
new file mode 100644
index 00000000..23118468
--- /dev/null
+++ b/vim/ftdetect/lex.vim
@@ -0,0 +1,4 @@
+" Lex files
+autocmd BufNewFile,BufRead
+ \ *.l,*.lex
+ \ setfiletype lex
diff --git a/vim/ftdetect/lua.vim b/vim/ftdetect/lua.vim
new file mode 100644
index 00000000..d6c635a0
--- /dev/null
+++ b/vim/ftdetect/lua.vim
@@ -0,0 +1,4 @@
+" Lua files
+autocmd BufNewFile,BufRead
+ \ *.lua
+ \ setfiletype lua
diff --git a/vim/ftdetect/m4.vim b/vim/ftdetect/m4.vim
new file mode 100644
index 00000000..c7d97e80
--- /dev/null
+++ b/vim/ftdetect/m4.vim
@@ -0,0 +1,4 @@
+" m4 files
+autocmd BufNewFile,BufRead
+ \ *.m4
+ \ setfiletype m4
diff --git a/vim/ftdetect/make.vim b/vim/ftdetect/make.vim
new file mode 100644
index 00000000..0ce0514b
--- /dev/null
+++ b/vim/ftdetect/make.vim
@@ -0,0 +1,4 @@
+" Makefiles
+autocmd BufNewFile,BufRead
+ \ Makefile,makefile
+ \ setfiletype make
diff --git a/vim/ftdetect/markdown.vim b/vim/ftdetect/markdown.vim
new file mode 100644
index 00000000..21ff2dcb
--- /dev/null
+++ b/vim/ftdetect/markdown.vim
@@ -0,0 +1,4 @@
+" Markdown files
+autocmd BufNewFile,BufRead
+ \ *.markdown,*.md
+ \ setfiletype markdown
diff --git a/vim/ftdetect/muttrc.vim b/vim/ftdetect/muttrc.vim
index 60d31575..48468b30 100644
--- a/vim/ftdetect/muttrc.vim
+++ b/vim/ftdetect/muttrc.vim
@@ -1,4 +1,4 @@
" Add automatic commands to detect .muttrc files
autocmd BufNewFile,BufRead
- \ **/.dotfiles/mutt/muttrc.d/*.rc,**/.muttrc.d/*.rc
- \ setlocal filetype=muttrc
+ \ Muttrc,.muttrc,*muttrc.d/*.rc
+ \ setfiletype muttrc
diff --git a/vim/ftdetect/perl.vim b/vim/ftdetect/perl.vim
new file mode 100644
index 00000000..3e8ec3b9
--- /dev/null
+++ b/vim/ftdetect/perl.vim
@@ -0,0 +1,9 @@
+" Perl 5 files
+autocmd BufNewFile,BufRead
+ \ *.pl,*.pm,*.t,Makefile.PL
+ \ setfiletype perl
+autocmd BufNewFile,BufRead
+ \ *
+ \ if getline(1) =~ '^#!.*perl$'
+ \ | setfiletype perl
+ \ | endif
diff --git a/vim/ftdetect/perl6.vim b/vim/ftdetect/perl6.vim
new file mode 100644
index 00000000..2f7fce00
--- /dev/null
+++ b/vim/ftdetect/perl6.vim
@@ -0,0 +1,9 @@
+" Perl 6 files
+autocmd BufNewFile,BufRead
+ \ *.p6,*.pl6,*.pm6
+ \ setfiletype perl6
+autocmd BufNewFile,BufRead
+ \ *
+ \ if getline(1) =~ '^#!.*perl6$'
+ \ | setfiletype perl6
+ \ | endif
diff --git a/vim/ftdetect/php.vim b/vim/ftdetect/php.vim
new file mode 100644
index 00000000..f28c7ab4
--- /dev/null
+++ b/vim/ftdetect/php.vim
@@ -0,0 +1,4 @@
+" PHP files
+autocmd BufNewFile,BufRead
+ \ *.php
+ \ setfiletype php
diff --git a/vim/ftdetect/pod.vim b/vim/ftdetect/pod.vim
new file mode 100644
index 00000000..6817b3b4
--- /dev/null
+++ b/vim/ftdetect/pod.vim
@@ -0,0 +1,4 @@
+" Perl 5 POD files
+autocmd BufNewFile,BufRead
+ \ *.pod
+ \ setfiletype pod
diff --git a/vim/ftdetect/pod6.vim b/vim/ftdetect/pod6.vim
new file mode 100644
index 00000000..4ae980a1
--- /dev/null
+++ b/vim/ftdetect/pod6.vim
@@ -0,0 +1,4 @@
+" Perl 6 POD files
+autocmd BufNewFile,BufRead
+ \ *.pod6
+ \ setfiletype pod6
diff --git a/vim/ftdetect/python.vim b/vim/ftdetect/python.vim
new file mode 100644
index 00000000..50055005
--- /dev/null
+++ b/vim/ftdetect/python.vim
@@ -0,0 +1,9 @@
+" Python files
+autocmd BufNewFile,BufRead
+ \ *.py
+ \ setfiletype python
+autocmd BufNewFile,BufRead
+ \ *
+ \ if getline(1) =~ '^#!.*python[23]\?$'
+ \ | setfiletype python
+ \ | endif
diff --git a/vim/ftdetect/readline.vim b/vim/ftdetect/readline.vim
new file mode 100644
index 00000000..be2565c3
--- /dev/null
+++ b/vim/ftdetect/readline.vim
@@ -0,0 +1,4 @@
+" Readline configuration file
+autocmd BufNewFile,BufRead
+ \ .inputrc,inputrc
+ \ setfiletype readline
diff --git a/vim/ftdetect/remind.vim b/vim/ftdetect/remind.vim
new file mode 100644
index 00000000..f153ad25
--- /dev/null
+++ b/vim/ftdetect/remind.vim
@@ -0,0 +1,4 @@
+" Remind files
+autocmd BufNewFile,BufRead
+ \ *.rem,*.remind,.reminders
+ \ setfiletype remind
diff --git a/vim/ftdetect/sh.vim b/vim/ftdetect/sh.vim
index 880f08e9..1169b744 100644
--- a/vim/ftdetect/sh.vim
+++ b/vim/ftdetect/sh.vim
@@ -1,19 +1,55 @@
-" Add automatic commands to choose shell flavours based on filename pattern
+" Shell script files; these are hard to detect accurately
-" Names/paths of things that are Bash shell script
+" Bash filename patterns
autocmd BufNewFile,BufRead
- \ **/.dotfiles/bash/**,bash-fc-*
+ \ *.bash,
+ \.bash_aliases,
+ \.bash_logout,
+ \.bash_profile,
+ \.bashrc,
+ \bash-fc-*,
+ \bash_profile,
+ \bashrc
\ let b:is_bash = 1
\ | setfiletype sh
-" Names/paths of things that are Korn shell script
+" Korn shell filename patterns
autocmd BufNewFile,BufRead
- \ **/.dotfiles/ksh/**,.kshrc,*.ksh
+ \ *.ksh,
+ \.kshrc,
+ \kshrc
\ let b:is_kornshell = 1
\ | setfiletype sh
-" Names/paths of things that are POSIX shell script
+" POSIX/Bourne shell filename patterns
autocmd BufNewFile,BufRead
- \ **/.dotfiles/sh/**,.shinit,.shrc,.xinitrc,/etc/default/*
+ \ *.sh,
+ \.profile,
+ \.shinit,
+ \.shrc,
+ \.xinitrc,
+ \/etc/default/*,
+ \configure,
+ \profile,
+ \shinit,
+ \shrc,
+ \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
+autocmd BufNewFile,BufRead
+ \ *
+ \ if !exists('b:is_bash') && !exists('b:is_kornshell')
+ \ | if getline(1) =~ '^#!.*bash$'
+ \ | let b:is_bash = 1
+ \ | setfiletype sh
+ \ | elseif getline(1) =~ '^#!.*ksh$'
+ \ | let b:is_ksh = 1
+ \ | setfiletype sh
+ \ | elseif getline(1) =~ '^#!.*sh$'
+ \ | let b:is_posix = 1
+ \ | setfiletype sh
+ \ | endif
+ \ | endif
diff --git a/vim/ftdetect/tmux.vim b/vim/ftdetect/tmux.vim
new file mode 100644
index 00000000..4a245586
--- /dev/null
+++ b/vim/ftdetect/tmux.vim
@@ -0,0 +1,4 @@
+" tmux configuration files
+autocmd BufNewFile,BufRead
+ \ .tmux.conf,tmux.conf
+ \ setfiletype tmux
diff --git a/vim/ftdetect/troff.vim b/vim/ftdetect/troff.vim
new file mode 100644
index 00000000..4bd27f6a
--- /dev/null
+++ b/vim/ftdetect/troff.vim
@@ -0,0 +1,4 @@
+" roff files
+autocmd BufNewFile,BufRead
+ \ *.[1-9],*.[1-9]df
+ \ setfiletype nroff
diff --git a/vim/ftdetect/tsv.vim b/vim/ftdetect/tsv.vim
index a345ac65..d6a0a71d 100644
--- a/vim/ftdetect/tsv.vim
+++ b/vim/ftdetect/tsv.vim
@@ -1,4 +1,4 @@
-" Add automatic commands to detect TSV files
+" Tab-separated (TSV) files
autocmd BufNewFile,BufRead
\ *.tsv
\ setfiletype tsv
diff --git a/vim/ftdetect/vim.vim b/vim/ftdetect/vim.vim
new file mode 100644
index 00000000..ca1c26c4
--- /dev/null
+++ b/vim/ftdetect/vim.vim
@@ -0,0 +1,4 @@
+" VimL files
+autocmd BufNewFile,BufRead
+ \ *.vim,vimrc,*[._]vimrc,exrc,*[._]exrc
+ \ setfiletype vim
diff --git a/vim/ftdetect/viminfo.vim b/vim/ftdetect/viminfo.vim
new file mode 100644
index 00000000..31a8c704
--- /dev/null
+++ b/vim/ftdetect/viminfo.vim
@@ -0,0 +1,4 @@
+" .viminfo files
+autocmd BufNewFile,BufRead
+ \ .viminfo
+ \ setfiletype viminfo
diff --git a/vim/ftdetect/xdefaults.vim b/vim/ftdetect/xdefaults.vim
index f45a22a7..896b2e32 100644
--- a/vim/ftdetect/xdefaults.vim
+++ b/vim/ftdetect/xdefaults.vim
@@ -1,4 +1,4 @@
" Add automatic commands to find Xresources subfiles
autocmd BufNewFile,BufRead
- \ **/.Xresources.d/*
+ \ .Xresources,*/.Xresources.d/*
\ setfiletype xdefaults
diff --git a/vim/ftdetect/xhtml.vim b/vim/ftdetect/xhtml.vim
new file mode 100644
index 00000000..adfb1cb5
--- /dev/null
+++ b/vim/ftdetect/xhtml.vim
@@ -0,0 +1,4 @@
+" XHTML files
+autocmd BufNewFile,BufRead
+ \ *.xhtml,*.xht
+ \ setfiletype xhtml
diff --git a/vim/ftdetect/xml.vim b/vim/ftdetect/xml.vim
new file mode 100644
index 00000000..7228e0f3
--- /dev/null
+++ b/vim/ftdetect/xml.vim
@@ -0,0 +1,4 @@
+" XML files
+autocmd BufNewFile,BufRead
+ \ *.xml
+ \ setfiletype xml
diff --git a/vim/ftdetect/yacc.vim b/vim/ftdetect/yacc.vim
new file mode 100644
index 00000000..e3cb5ee8
--- /dev/null
+++ b/vim/ftdetect/yacc.vim
@@ -0,0 +1,4 @@
+" Yacc files
+autocmd BufNewFile,BufRead
+ \ *.y,*.yy
+ \ setfiletype yacc
diff --git a/vim/ftdetect/yaml.vim b/vim/ftdetect/yaml.vim
new file mode 100644
index 00000000..3bf32b53
--- /dev/null
+++ b/vim/ftdetect/yaml.vim
@@ -0,0 +1,4 @@
+" YAML files
+autocmd BufNewFile,BufRead
+ \ *.yaml
+ \ setfiletype yaml
diff --git a/vim/ftdetect/zsh.vim b/vim/ftdetect/zsh.vim
new file mode 100644
index 00000000..1bcde981
--- /dev/null
+++ b/vim/ftdetect/zsh.vim
@@ -0,0 +1,9 @@
+" Z shell files
+autocmd BufNewFile,BufRead
+ \ *.zsh,.zprofile,zprofile,.zshrc,zshrc
+ \ setfiletype zsh
+autocmd BufNewFile,BufRead
+ \ *
+ \ if getline(1) =~ '^#!.*zsh$'
+ \ | setfiletype zsh
+ \ | endif