Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

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
#
_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
}
share|improve this answer
1  
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
1  
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

This thread explores this issue:

http://www.linuxquestions.org/questions/linux-software-2/how-to-stop-bash-from-replacing-~-with-home-username-643162/

share|improve this answer
    
Same workaround, I see. I tried reading the linked bugs but I failed to see why lack of tab-completion-tilde-expansion would be an issue, since obviously the issue would apply if tab completion hadn't been used. –  Neil Nov 8 '12 at 12:14

Your Answer

 
discard

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.