Skip to content

Commit a93c82a

Browse files
committed
Small improvements.
- funded and fish_indent always uses tabs for indentation, use fish#Indent() to fix it. Works better with the improved fish#Indent(). - ftdetect should contain filetype detection code. Move autocmds to plugin/fish.vim. - Match new funced temp file name. - Add "else", "else if" and "case" to b:match_words to follow what's used by Vim's ftplugins. - Use "syn sync fromstart" for a more accurate highlighting.
1 parent 825853f commit a93c82a

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

autoload/fish.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function! fish#Format()
2626
let l:command = v:lnum.','.(v:lnum+v:count-1).'!fish_indent'
2727
echo l:command
2828
execute l:command
29+
" Fix indentation and replace tabs with spaces if necessary.
30+
normal! '[=']
2931
endif
3032
endfunction
3133

ftdetect/fish.vim

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
autocmd BufRead,BufNewFile *.fish setfiletype fish
22

3+
" Set filetype when using funced.
4+
autocmd BufRead fish_funced.* setfiletype fish
5+
6+
" Fish histories are YAML documents.
7+
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
8+
39
" Detect fish scripts by the shebang line.
410
autocmd BufRead *
511
\ if getline(1) =~# '\v^#!%(\f*/|/usr/bin/env\s*<)fish>' |
612
\ setlocal filetype=fish |
713
\ endif
8-
9-
" Move cursor to first empty line when using funced.
10-
autocmd BufRead fish_funced_*_*.fish call search('^$')
11-
12-
" Fish histories are YAML documents.
13-
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
14-
15-
" Universal variable storages should not be hand edited.
16-
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
17-
18-
" Mimic `funced` when manually creating functions.
19-
autocmd BufNewFile ~/.config/fish/functions/*.fish
20-
\ call append(0, ['function '.expand('%:t:r'),
21-
\'',
22-
\'end']) |
23-
\ 2

ftplugin/fish.vim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ endif
3131
" argument to fish instead of man.
3232
execute 'setlocal keywordprg=fish\ '.expand('<sfile>:p:h:h').'/bin/man.fish'
3333

34+
let b:match_ignorecase = 0
35+
if has('patch-7.3.1037')
36+
let s:if = '\%(else\s\+\)\@15<!if'
37+
else
38+
let s:if = '\%(else\s\+\)\@<!if'
39+
endif
40+
3441
let b:match_words =
35-
\ escape('<%(begin|function|if|switch|while|for)>:<end>', '<>%|)')
42+
\ '\<\%(begin\|function\|'.s:if.'\|switch\|while\|for\)\>'
43+
\.':\<\%(else\%(\s*if\)\?\|case\)\>:\<end\>'
3644

3745
let b:endwise_addition = 'end'
3846
let b:endwise_words = 'begin,function,if,switch,while,for'

plugin/fish.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
if get(g:, 'loaded_fish', 0)
2+
finish
3+
endif
4+
let loaded_fish = 1
5+
6+
" Universal variable storages should not be hand edited.
7+
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
8+
"
9+
" Move cursor to first empty line when using funced.
10+
autocmd BufRead fish_funced.* exec "normal! gg=G" | call search('^\s*\zs$')
11+
12+
" Mimic `funced` when manually creating functions.
13+
autocmd BufNewFile ~/.config/fish/functions/*.fish
14+
\ call setline(1, ['function '.expand('%:t:r'),
15+
\'',
16+
\'end']) |
17+
\ 2

syntax/fish.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ if exists('b:current_syntax')
22
finish
33
endif
44

5+
syntax sync clear
6+
syntax sync fromstart
7+
58
syntax case match
69

710
syntax keyword fishKeyword begin function end

0 commit comments

Comments
 (0)