diff --git a/ftdetect/fish.vim b/ftdetect/fish.vim new file mode 100644 index 0000000..2c04f58 --- /dev/null +++ b/ftdetect/fish.vim @@ -0,0 +1,6 @@ +au BufNewFile,BufRead *.fish set ft=fish + +autocmd BufNewFile,BufRead,StdinReadPost * + \ if getline(1) =~ '^#!.*\Wfish\s*$' | + \ set ft=fish | + \ endif diff --git a/ftplugin/fish.vim b/ftplugin/fish.vim new file mode 100644 index 0000000..bf643b6 --- /dev/null +++ b/ftplugin/fish.vim @@ -0,0 +1,40 @@ +setlocal comments=:# +setlocal commentstring=#%s +setlocal define=\\v^\\s*function> +setlocal foldexpr=fish#Fold() +setlocal formatoptions+=ron1 +setlocal formatoptions-=t +setlocal include=\\v^\\s*\\.> +setlocal suffixesadd^=.fish + +" Use the 'j' format option when available. +if v:version ># 703 || v:version ==# 703 && has('patch541') + setlocal formatoptions+=j +endif + +if executable('fish_indent') + setlocal formatexpr=fish#Format() +endif + +if executable('fish') + setlocal omnifunc=fish#Complete + for s:path in split(system("fish -c 'echo $fish_function_path'")) + execute 'setlocal path+='.s:path + endfor +else + setlocal omnifunc=syntaxcomplete#Complete +endif + +" Use the 'man' wrapper function in fish to include fish's man pages. +" Have to use a script for this; 'fish -c man' would make the the man page an +" argument to fish instead of man. +execute 'setlocal keywordprg=fish\ '.fnameescape(expand(':p:h:h').'/bin/man.fish') + +let b:match_words = + \ escape('<%(begin|function|if|switch|while|for)>:', '<>%|)') + +let b:endwise_addition = 'end' +let b:endwise_words = 'begin,function,if,switch,while,for' +let b:endwise_syngroups = 'fishKeyword,fishConditional,fishRepeat' + +endif \ No newline at end of file diff --git a/syntax/fish.vim b/syntax/fish.vim new file mode 100644 index 0000000..852d9ac --- /dev/null +++ b/syntax/fish.vim @@ -0,0 +1,39 @@ +if exists('b:current_syntax') + finish +endif + +syntax case match + +syntax keyword fishKeyword begin function end +syntax keyword fishConditional if else switch +syntax keyword fishRepeat while for in +syntax keyword fishLabel case + +syntax match fishComment /#.*/ +syntax match fishSpecial /\\$/ +syntax match fishIdentifier /\$[[:alnum:]_]\+/ +syntax region fishString start=/'/ skip=/\\'/ end=/'/ +syntax region fishString start=/"/ skip=/\\"/ end=/"/ contains=fishIdentifier +syntax match fishCharacter /\v\\[abefnrtv *?~%#(){}\[\]<>&;"']|\\[xX][0-9a-f]{1,2}|\\o[0-7]{1,2}|\\u[0-9a-f]{1,4}|\\U[0-9a-f]{1,8}|\\c[a-z]/ +syntax match fishStatement /\v;\s*\zs\k+>/ +syntax match fishCommandSub /\v\(\s*\zs\k+>/ + +syntax region fishLineContinuation matchgroup=fishStatement + \ start='\v^\s*\zs\k+>' skip='\\$' end='$' + \ contains=fishSpecial,fishIdentifier,fishString,fishCharacter,fishStatement,fishCommandSub,fishComment + +highlight default link fishKeyword Keyword +highlight default link fishConditional Conditional +highlight default link fishRepeat Repeat +highlight default link fishLabel Label +highlight default link fishComment Comment +highlight default link fishSpecial Special +highlight default link fishIdentifier Identifier +highlight default link fishString String +highlight default link fishCharacter Character +highlight default link fishStatement Statement +highlight default link fishCommandSub fishStatement + +let b:current_syntax = 'fish' + +endif