set complete+=k[file] 不适用于整行完成?

set complete+=k[file] not working for whole line completion?

我有 ~/.bash_history,其中包含 sudo apt-get installaplay foo.wav 等行。我认为如果我可以在编写 [ 时使用这些行来完成整行,那会很方便=46=] 脚本。

:h compl-whole-line 说:

CTRL-X CTRL-L
Search backwards for a line that starts with the same characters as those in the current line before the cursor. Indent is ignored. The matching line is inserted in front of the cursor. ** The 'complete' option is used to decide which buffers are searched for a match. Both loaded and unloaded buffers are used.**

注意我插入的星号。 :h 'complete' 说:

 k      k{dict} scan the file {dict}.  Several "k" flags can be given,
        patterns are valid too.  For example: >
        :set cpt=k/usr/dict/*,k~/spanish

所以我认为 :set complete+=k~/.bash_history 可以胜任。没有。

从vim开始

$ vim -u NONE -N

然后

:set complete+=k~/.bash_history
:set complete?
" complete=.,w,b,u,t,i,k~/.bash_history

,我进入插入模式(i),当我输入

su<C-x><C-l>

、vim 表示 Whole line completion (^L^N^P) Pattern not found。完成是为单词工作的,所以当我输入

su<C-p>
建议

sudo

我错过了什么?在没有 :sp ~/.bash_history 的情况下如何使用我的历史记录来完成整行?

set complete+=k[file] 与行补全无关:您提供给它的任何文件都只会被 字典补全 用作来源(<C-x><C-k> ) 和 关键字补全 (<C-n>/<C-p>).

:help i_ctrl-x_ctrl-l 很清楚:行完成仅适用于在加载和卸载缓冲区中找到的 行。 由于 ~/.bash_history 未作为缓冲区加载,行完成显然永远不会将其用作来源。

所以是的,唯一实用的解决方案是加载该文件。

但是,

:sp ~/.bash_history 并不是最佳选择,因为 a) 它在物理上和缓冲区列表中都占用了太多空间,并且 b) 它需要太多的击键。

问题的"too much room"部分很容易用更合适的命令解决:

:badd ~/.bash_history

问题的 "too many keystrokes" 部分可以通过每次编辑 shell 脚本时运行上述命令的自动命令来解决:

augroup shell
    autocmd!
    autocmd BufNewFile,BufRead *.sh badd ~/.bash_history
augroup END