8

If I type cat ~/.bashr<TAB> then it completes to cat ~/.bashrc.

If I type vim ~/.bashr<TAB> then it completes to vim /home/neil/.bashrc...

(It does the same with vi, which is aliased to "vim".)

Can I turn that off?

Neil
  • 889

2 Answers2

6

this is controlled by /etc/bash_completion

you can comment out the expansion code in _expand() if you don't like it.

here is my version in fedora 17, but yours should be similar:

# This function expands tildes in pathnames
#
_expand()
{
    # FIXME: Why was this here?
    #[ "$cur" != "${cur%\\}" ] && cur="$cur\\"

    # Expand ~username type directory specifications.  We want to expand
    # ~foo/... to /home/foo/... to avoid problems when $cur starting with
    # a tilde is fed to commands and ending up quoted instead of expanded.

    if [[ "$cur" == \~*/* ]]; then
        eval cur=$cur
    elif [[ "$cur" == \~* ]]; then
        cur=${cur#\~}
        COMPREPLY=( $( compgen -P '~' -u "$cur" ) )
        [ ${#COMPREPLY[@]} -eq 1 ] && eval COMPREPLY[0]=${COMPREPLY[0]}
        return ${#COMPREPLY[@]}
    fi
}
johnshen64
  • 4,701
6

bash can provide more sophisticated autocompletion for certain commands (e.g. autocompleting program arguments other than file names). There is such a Programmable Completion function defined for the vim command on your system.

Typing complete at the command prompt will show you what functions are used to provide autocompletion for bash.

$ complete
complete -o default -F _complete_open open

Type type function_name to learn about their definition.

$ type _complete_open
_complete_open is a function
_complete_open () 
{ 
   # function definition
}

To find out where the function was defined. use the following:

$ shopt -s extdebug
$ declare -F _complete_open
_complete_open 70 /Users/danielbeck/.bash_profile
Daniel Beck
  • 111,893