简体   繁体   English

Vim - 如何在命令行模式下自动完成缓冲区内容

[英]Vim - how to auto complete buffer contents in command-line mode

Use case: I have a buffer用例:我有一个缓冲区

variable1
variable2
variable3

i want to replace variable1 with variable3 using我想用variable3替换variable1

:%s/vari<TAB>/vari<TAB><TAB><TAB>

can this be done somehow?这可以以某种方式完成吗? I don't want to have to type out or manually copy words我不想输入或手动复制单词

I vaguely remembered this old plugin from way back and, well… it still seems to do the job:我隐约记得很久以前的这个旧插件,嗯……它似乎仍然可以完成工作:

编译

You can use the command-line window (see :help cmdline-window ) to use regular Insert mode to write an Ex command-line such as :s .您可以使用命令行 window (请参阅:help cmdline-window )使用常规插入模式来编写 Ex 命令行,例如:s

You can either use q: from Normal mode to access the command-line window, or use Control + F from the Ex command-line (after typing : and even starting to write a command such as :%s/vari ...)您可以在普通模式下使用q:访问命令行 window,或者在 Ex 命令行中使用Control + F (在键入:甚至开始编写诸如:%s/vari vari 之类的命令之后)

Once in the command-line window, you can use i (or a , A , etc.) to enter Insert mode, and then you can use the usual completion keystrokes such as Control + N or Control + P to complete from contents of other visible buffers.进入命令行 window 后,您可以使用i (或aA等)进入插入模式,然后您可以使用通常的完成键击Control + NControl + P从其他内容完成可见缓冲区。

Once the :%s command is complete, you can simply press Return to have the command from the command-line window executed as a regular Ex command. :%s命令完成后,您只需按Return即可将命令行 window 中的命令作为常规 Ex 命令执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM