Dylanthepiguy
Dylanthepiguy

Reputation: 1741

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

:%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

Upvotes: 5

Views: 661

Answers (2)

romainl
romainl

Reputation: 196876

I vaguely remembered this old plugin from way back and, well… it still seems to do the job:

compl

Upvotes: 3

filbranden
filbranden

Reputation: 8908

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.

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...)

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.

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.

Upvotes: 1

Related Questions