how do I copy/paste in vim ex mode

10

6

I'm increasingly frustrated by typing this

:%s/some_really_long_string/some_other_really_really_long_string_that_may_or_may_not_related_to_the_first_one/gc

Is there any way to copy/paste those strings in ex mode?

iakie

Posted 2010-07-22T07:43:17.973

Reputation: 103

Answers

10

You can use Ctrl-R to insert the value of a register on the Ex command line. If you've yanked some text into the default register, for example, you can recall it with Ctrl-R".

There are shortcuts for some common cases, too. You can insert the current word under the cursor with Ctrl-RCtrl-W, or the current filename with Ctrl-RCtrl-F.

See these topics for more information, including several more examples:

:help c_CTRL-R
:help cmdline.txt

Registers are worth reading about, too:

:help registers

Bill Odom

Posted 2010-07-22T07:43:17.973

Reputation: 596

i thought Ctrl-R meant you needed to do shift to get the capital R. but when i tried it out you just need ctrl-r without shift. – Trevor Boyd Smith – 2018-11-13T12:51:19.357

10

I almost always avoid typing the search string in the substitute command by first executing a search (with /) or a "word under cursor search" (with *) and then executing:

:%s//other_string/gc

When the search pattern is missing, the substitute command will use the last search pattern.

Beside making you type less characters, the first case, searching with /, allow to first test a complex search pattern before executing the substitution. The second case, searching with *, allow to avoid inserting the start/end atoms, i.e. \< and \>.

--

By the way, you can avoid the g flag by adding the line

set gdefault

in your vimrc file.

mrucci

Posted 2010-07-22T07:43:17.973

Reputation: 8 398