Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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
    # 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
        COMPREPLY=( $( compgen -P '~' -u "$cur" ) )
        [ ${#COMPREPLY[@]} -eq 1 ] && eval COMPREPLY[0]=${COMPREPLY[0]}
        return ${#COMPREPLY[@]}
share|improve this answer
The location of completion scripts depends entirely on your system. – Daniel Beck Jun 28 '12 at 19:42
hmm, maybe. thanks. i only use ubuntu/fedora/centos these days and it seems that the file is there. yeah, if it is another distro i can imagine that the file/function is located elsewhere, but still it is likely still controlled just by a text file. – johnshen64 Jun 28 '12 at 19:44
Thanks, I "fixed" my problem by defining a function _expand() { :;} in my ~/.bashrc. – Neil Jun 28 '12 at 23:44

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.