0

我在使用 Vim 的 MacBook 上,为了简单起见,我说我有文件~/some_file.py~/some_other_file.py~/user.py打开。在 macOS 上,~ 扩展为/Users/<username>.

因此,如果我:b user在 Vim 命令行中键入,然后按 tab 键展开,它会遍历每个文件,而不是直接转到~/user.py.

有什么办法可以防止这种行为?

4

2 回答 2

0

I can't reproduce your problem under linux (tildes are not resolved in my vim's completion list, so :b home gives me ~/home.py before ~/some_file.py), but...

Try typing :b user then complete with Shift+Tab. In that case, my vim (7.2.442 if that matters) completes with the last match, which is what you want.

于 2010-10-12T20:30:28.767 回答
0

无法更改 Vim 内置缓冲区完成。我唯一可以建议的(除了已经从主目录打开这些文件)是定义您自己的:b 命令版本并具有所需的完成。它可能是这样的:

function! CustomBufferComplete(a, l, p)
    let buf_out = ''
    redir => buf_out
    silent buffers
    redir END

    let buf_list = map(split(buf_out, "\n"), 'substitute(v:val, ' .
    \   '''^.*"\%(\~[/\\]\)\?\([^"]\+\)".*$'', "\\1", "g")')
    return join(buf_list, "\n")
endfunction

command! -nargs=1 -complete=custom,CustomBufferComplete B b <args>

(请注意,它会在返回完成列表之前切断~/ 路径的一部分。)

于 2010-10-13T05:13:13.077 回答