VIM中有没有办法让按键调用下拉菜单(类似于代码完成),但列出文本文件中的文本行可供选择?
我有一个我想要选择的宏列表。例如......
我希望在下拉菜单中看到所有这些内容,我可以选择将其插入到文件中。
答案 0 :(得分:2)
Vim提供行完成(:h compl-whole-line
)
Completing whole lines compl-whole-line
i_CTRL-X_CTRL-L
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.
CTRL-L or
CTRL-P Search backwards for next matching line. This line
replaces the previous matching line.
CTRL-N Search forward for next matching line. This line
replaces the previous matching line.
CTRL-X CTRL-L After expanding a line you can additionally get the
line next to it by typing CTRL-X CTRL-L again, unless
a double CTRL-X is used. Only works for loaded
buffers.
如果您使用<C-X><C-L>
,则可以在任何打开的缓冲区中填写行。因此,只需在后台打开要完成的文件,然后使用<C-X><C-L>
打开一个菜单,选择与当前字符相同的字符匹配的行。
答案 1 :(得分:2)
完整的行完成(由@FDinoff建议)有几个缺点:它考虑所有打开缓冲区,并且仅适用于新行开头的完成。 片段插件可以做到这一点,但具有不同的语法和额外的,不必要的复杂性。
解决方案是自定义完成,例如由我的EntryComplete plugin实现的解决方案。此插件提供了在指定文件或缓冲区中找到的高度可配置的行完成,由光标前面的关键字触发。