2

When replacing a word with another in a buffer in command-line mode, :%s/verylongword/newword/g, is there a way to word-complete 'verylongword' somewhow from the contents of the buffer ?

Failing that, is there a way of copy-pasting 'verylongword' from the buffer when typing :%s/verylongword/newword/g ?

user3203476
  • 499
  • 3
  • 12
  • 1
    Yes it does, many thanks. Also, to paste text onto the command line, one can use CTRL-R, as per here: https://stackoverflow.com/questions/3997078/how-to-paste-yanked-text-into-vim-command-line – user3203476 Mar 10 '19 at 00:46

1 Answers1

4

Command-line window

While typing the command press CtrlF to open the command-line window, see :h c_CTRL-f.

In the command-line window you can use all the usual vim commands to edit your command line.


Paste from register

To paste from a buffer in command-line mode press CtrlR followed by the register name.

For example press CtrlR0 to paste from register 0 to paste the last yanked text.

See :h c_CTRL-R for more info.


Object under cursor

CtrlR also allows the following completions (quoted from vim help):

CTRL-R CTRL-F                           c_CTRL-R_CTRL-F c_<C-R>_<C-F>
CTRL-R CTRL-P                           c_CTRL-R_CTRL-P c_<C-R>_<C-P>
CTRL-R CTRL-W                           c_CTRL-R_CTRL-W c_<C-R>_<C-W>
CTRL-R CTRL-A                           c_CTRL-R_CTRL-A c_<C-R>_<C-A>
                Insert the object under the cursor:
                        CTRL-F  the Filename under the cursor
                        CTRL-P  the Filename under the cursor, expanded with
                                'path' as in gf
                        CTRL-W  the Word under the cursor
                        CTRL-A  the WORD under the cursor; see WORD
rkta
  • 3,959
  • 7
  • 25
  • 37