This commit is contained in:
Khaveesh N (MBP) 2022-08-05 07:32:59 +05:30
parent bd6b832f33
commit f3744201a1
No known key found for this signature in database
GPG key ID: CB82DEC6404CD52E
5 changed files with 86 additions and 85 deletions

View file

@ -5,7 +5,7 @@ shell](https://github.com/fish-shell/fish-shell) scripts
## Installation
I recommend the native packages support built into Vim8 and NeoVim, but
I recommend the native packages support built into Vim8 and Neovim, but
you can use any plugin manager you like.
## Features aplenty
@ -18,28 +18,28 @@ you can use any plugin manager you like.
For everything above to work you need to have fish installed in `$PATH`
and some Vim features turned on. First, tell Vim to use the syntax and
filetype functionality, normally in your `~/.vimrc`:
filetype functionality, in your `vimrc`:
``` {.vim}
``` vim
syntax enable
filetype plugin indent on
```
The above commands are required only for Vim and not for NeoVim.
**The above commands are required only for Vim and not for Neovim (which
I personally use and recommend over vanilla Vim).**
## Teach a Vim to fish...
Vim needs a more POSIX compatible shell than fish for certain
functionality to work, such as `:%!`, compressed help pages and many
third-party addons. If you use fish as your login shell or launch Vim
from fish, you need to set `shell` to something else in your `vimrc`,
for example:
third-party plugins. If you use fish as your login shell, you need to
set `shell` to something else in your `vimrc`, for example:
``` {.vim}
``` vim
if &shell =~# 'fish$'
set shell=sh
endif
```
Best do it somewhere at the top, before any addon code is loaded and
Best do it somewhere at the top, before any plugin code is loaded and
executed.

View file

@ -1,44 +1,44 @@
function! fish#Fold()
let l:line = getline(v:lnum)
if l:line =~# '\v^\s*%(begin|if|while|for|function|switch)>'
return 'a1'
elseif l:line =~# '\v^\s*end>'
return 's1'
else
return '='
let l:line = getline(v:lnum)
if l:line =~# '\v^\s*%(begin|if|while|for|function|switch)>'
return 'a1'
elseif l:line =~# '\v^\s*end>'
return 's1'
else
return '='
end
endfunction
function! fish#Complete(findstart, base) abort
if a:findstart
return getline('.') =~# '\v^\s*$' ? -1 : 0
else
if empty(a:base)
return []
endif
let l:results = []
let l:completions =
\ system('fish -c "complete -C'.shellescape(a:base).'"')
let l:sufpos = match(a:base, '\v\S+$')
if l:sufpos >= 0
let l:cmd = a:base[:l:sufpos-1]
let l:arg = a:base[l:sufpos:]
else
let l:cmd = a:base
let l:arg = ''
endif
for l:line in filter(split(l:completions, '\n'), '!empty(v:val)')
let l:tokens = split(l:line, '\t')
let l:term = l:tokens[0]
if l:term =~? '^\V'.l:arg
call add(l:results, {
\ 'word': l:cmd.l:term,
\ 'abbr': l:term,
\ 'menu': get(l:tokens, 1, ''),
\ 'dup': 1
\ })
endif
endfor
return l:results
if a:findstart
return getline('.') =~# '\v^\s*$' ? -1 : 0
else
if empty(a:base)
return []
endif
let l:results = []
let l:completions =
\ system('fish -c "complete -C'.shellescape(a:base).'"')
let l:sufpos = match(a:base, '\v\S+$')
if l:sufpos >= 0
let l:cmd = a:base[:l:sufpos-1]
let l:arg = a:base[l:sufpos:]
else
let l:cmd = a:base
let l:arg = ''
endif
for l:line in filter(split(l:completions, '\n'), '!empty(v:val)')
let l:tokens = split(l:line, '\t')
let l:term = l:tokens[0]
if l:term =~? '^\V'.l:arg
call add(l:results, {
\ 'word': l:cmd.l:term,
\ 'abbr': l:term,
\ 'menu': get(l:tokens, 1, ''),
\ 'dup': 1
\ })
endif
endfor
return l:results
endif
endfunction

View file

@ -2,6 +2,6 @@ autocmd BufNewFile,BufRead *.fish setfiletype fish
" Detect fish scripts by the shebang line.
autocmd BufNewFile,BufRead,StdinReadPost *
\ if getline(1) =~ '^#!.*\Wfish\s*$' |
\ setfiletype fish |
\ endif
\ if getline(1) =~ '^#!.*\Wfish\s*$' |
\ setfiletype fish |
\ endif

View file

@ -1,11 +1,12 @@
if exists('b:did_ftplugin')
finish
end
finish
endif
let b:did_ftplugin = 1
let s:save_cpo = &cpo
set cpo&vim
setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4
setlocal comments=:#
setlocal commentstring=#%s
setlocal define=\\v^\\s*function>
@ -17,23 +18,23 @@ setlocal iskeyword=@,48-57,+,-,_,.
setlocal suffixesadd^=.fish
if executable('fish')
setlocal omnifunc=fish#Complete
setlocal formatprg=fish_indent
let b:formatprg = [ 'fish_indent' ]
setlocal omnifunc=fish#Complete
setlocal formatprg=fish_indent
let b:formatprg = [ 'fish_indent' ]
endif
let b:match_ignorecase = 0
let b:match_words = escape(
\ '<%(begin|function|%(else\s\+)\@15<!if|switch|while|for)>'
\ . ':<else\s\+if|case>:<else>:<end>',
\ '<>%|)')
\ '<%(begin|function|%(else\s\+)\@15<!if|switch|while|for)>'
\ . ':<else\s\+if|case>:<else>:<end>',
\ '<>%|)')
let b:match_skip = 's:comment\|string\|deref'
let b:undo_ftplugin = "
\ setlocal comments< commentstring< define< foldexpr< formatoptions<
\ | setlocal include< iskeyword< suffixesadd< omnifunc< formatprg<
\ | unlet! b:match_words b:match_skip b:match_ignorecase
\"
\ setlocal comments< commentstring< define< foldexpr< formatoptions<
\ | setlocal include< iskeyword< suffixesadd< omnifunc< formatprg<
\ | unlet! b:match_words b:match_skip b:match_ignorecase
\"
let &cpo = s:save_cpo
unlet s:save_cpo

View file

@ -1,5 +1,5 @@
if exists('b:current_syntax')
finish
finish
endif
syntax case match
@ -7,21 +7,21 @@ syntax iskeyword @,48-57,-,_,.,/
" https://en.wikipedia.org/wiki/List_of_Unix_commands
syntax keyword fishUnixCommand admin alias ar asa at awk basename batch bc bg
\ cc c99 cal cat cd cflow chgrp chmod chown cksum cmp comm command compress
\ cp crontab csplit ctags cut cxref date dd delta df diff dirname du echo
\ ed env ex expand expr false fc fg file find fold fort77 fuser gencat get
\ getconf getopts grep hash head iconv id ipcrm ipcs jobs join kill lex
\ less link ln locale localedef logger logname lp ls m4 mailx make man mesg
\ mkdir mkfifo more mv newgrp nice nl nm nohup od paste patch pathchk pax
\ pr printf prs ps pwd qalter qdel qhold qmove qmsg qrerun qrls qselect
\ qsig qstat qsub read renice rm rmdel rmdir sact sccs sed sh sleep sort
\ split strings strip stty tabs tail talk tee test time touch tput tr true
\ tsort tty type ulimit umask unalias uname uncompress unexpand unget uniq
\ unlink uucp uudecode uuencode uustat uux val vi wait wc what who
\ write xargs yacc zcat
\ cc c99 cal cat cd cflow chgrp chmod chown cksum cmp comm command compress
\ cp crontab csplit ctags cut cxref date dd delta df diff dirname du echo
\ ed env ex expand expr false fc fg file find fold fort77 fuser gencat get
\ getconf getopts grep hash head iconv id ipcrm ipcs jobs join kill lex
\ less link ln locale localedef logger logname lp ls m4 mailx make man mesg
\ mkdir mkfifo more mv newgrp nice nl nm nohup od paste patch pathchk pax
\ pr printf prs ps pwd qalter qdel qhold qmove qmsg qrerun qrls qselect
\ qsig qstat qsub read renice rm rmdel rmdir sact sccs sed sh sleep sort
\ split strings strip stty tabs tail talk tee test time touch tput tr true
\ tsort tty type ulimit umask unalias uname uncompress unexpand unget uniq
\ unlink uucp uudecode uuencode uustat uux val vi wait wc what who
\ write xargs yacc zcat
syntax cluster fishKeyword contains=fishBlock,fishFunction,fishConditional,
\ fishRepeat,fishLabel,fishControl,fishOperator,fishBoolean,fishCommand
\ fishRepeat,fishLabel,fishControl,fishOperator,fishBoolean,fishCommand
syntax keyword fishBlock begin end
syntax keyword fishConditional if else switch
syntax keyword fishRepeat while for in
@ -32,20 +32,20 @@ syntax keyword fishBoolean true false
" http://fishshell.com/docs/current/commands.html
syntax keyword fishCommand abbr alias argparse bg bind block breakpoint
\ builtin cd cdh command commandline complete contains[] count dirh dirs
\ disown echo emit eval exec fg fish fish_breakpoint_prompt fish_config
\ fish_git_prompt fish_hg_prompt fish_indent fish_key_reader
\ fish_mode_prompt fish_opt fish_prompt fish_right_prompt
\ fish_svn_prompt fish_update_completions fish_vcs_prompt funced funcsave
\ functions help history isatty jobs math nextd open popd prevd printf
\ prompt_pwd psub pushd pwd random read realpath set set_color source
\ status suspend test time trap type ulimit umask vared wait
\ builtin cd cdh command commandline complete contains[] count dirh dirs
\ disown echo emit eval exec fg fish fish_breakpoint_prompt fish_config
\ fish_git_prompt fish_hg_prompt fish_indent fish_key_reader
\ fish_mode_prompt fish_opt fish_prompt fish_right_prompt
\ fish_svn_prompt fish_update_completions fish_vcs_prompt funced funcsave
\ functions help history isatty jobs math nextd open popd prevd printf
\ prompt_pwd psub pushd pwd random read realpath set set_color source
\ status suspend test time trap type ulimit umask vared wait
syntax match fishCommand /\v<string(\s+(collect|escape|join|join0|length|lower
\ |match|repeat|replace|split|split0|sub|trim|unescape|upper))=>/
\ |match|repeat|replace|split|split0|sub|trim|unescape|upper))=>/
syntax keyword fishFunction function nextgroup=fishFunctionName skipwhite
syntax match fishFunctionName '[^[:space:]/()-][^[:space:]/()]*' contained
\ contains=fishString,fishDeref
\ contains=fishString,fishDeref
syntax match fishOperator '[\[\]=*~%&|<>!+-]'
syntax match fishOperator '\.\.'