I wrote a small bash function to provide completion for vim. The function is the following:
# completion for vim
_vim()
{
local cur prev
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in
-h|--help|-v|--version)
return 0
;;
esac
if [[ "$cur" == -* ]] ; then
local _vopts='-v -e -E -s -d -y -R -Z -m -M -b -l -C'
_vopts="${_vopts} -N -V -D -n -r -r -L -A -H -F -T -u"
_vopts="${_vopts} --noplugin -p -o -O --cmd -c -S -s -w -W"
_vopts="${_vopts} -x -X --remote --remote-silent --remote-wait"
_vopts="${_vopts} --remote-wait-silent --remote-tab --remote-send"
_vopts="${_vopts} --remote-expr --serverlist --servername"
_vopts="${_vopts} --startuptime -i -h --help --version"
COMPREPLY=( $( compgen -W "${_vopts}" \
-- "$cur" ) )
return 0
fi
local _VIM_IGNORE=".pdf:.dvi:.jpg:.pyc:.exe:.tar:.zip:.ps"
FIGNORE="${_VIM_IGNORE}" _filedir
} &&
complete -F _vim vim vi v gv vd
I was trying to have it ignore files with extensions pdf, dvi, etc by defining the _VIM_IGNORE variable and setting FIGNORE to that but that does not work.
Any idea how to accomplish this?
Thanks.
I haven’t found any documentation, but based on my experiments, it seems that
FIGNOREdoes not affect thecompgen()/_filedir()(which is just a wrapper around the former) processing itself. It only affects completions when it is set in the shell from which the completion is triggered (but then globally, which is not what you want).I guess you cannot use
FIGNOREin this clever way, and have to explicitly implement a filter of theCOMPREPLYarray yourself.