为什么当我完成 vim 文件名时 bash 选项卡扩展波浪号?

Nei*_*eil 8 bash vim tab-completion

如果我输入cat ~/.bashr<TAB>然后它完成到cat ~/.bashrc.

如果我输入vim ~/.bashr<TAB>然后它完成vim /home/neil/.bashrc...

(它与 相同vi,别名为"vim"。)

我可以关掉它吗?

Dan*_*eck 6

bash可以为某些命令提供更复杂的自动完成(例如自动完成除文件名之外的程序参数)。系统上为命令定义了这样一个可编程完成功能vim

打字complete在命令提示符将显示使用您哪些功能为提供自动完成bash

$ complete
complete -o default -F _complete_open open
Run Code Online (Sandbox Code Playgroud)

键入type function_name以了解其定义。

$ type _complete_open
_complete_open is a function
_complete_open () 
{ 
   # function definition
}
Run Code Online (Sandbox Code Playgroud)

找出函数的定义位置。使用以下内容:

$ shopt -s extdebug
$ declare -F _complete_open
_complete_open 70 /Users/danielbeck/.bash_profile
Run Code Online (Sandbox Code Playgroud)


joh*_*n64 5

这是由 /etc/bash_completion 控制的

如果你不喜欢它,你可以在 _expand() 中注释掉扩展代码。

这是我在 Fedora 17 中的版本,但你的应该是类似的:

# 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
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,我通过在我的 `~/.bashrc` 中定义一个 `function _expand() { :;}` 来“修复”我的问题。 (4认同)