16 votes
Accepted

Copying multiple words (from different lines) and paste them at once

Use an uppercase register when yanking (copying): "Ay "A says to append to the a register, as opposed to "a which would replace the contents of the a register. Once you've copied everything into ...
8bittree's user avatar
  • 1,487
16 votes
Accepted

How to replace string with register content?

N.B. In all the below, I presume that your question is only about the method of accessing the register's contents from an ex command, and that the rest of your :substitute command (which replaces only ...
Rich's user avatar
  • 31.3k
14 votes

How can I easily list the content of the registers before pasting?

This peekaboo plugin is pretty good for for previewing registers. When you press " or @ in normal mode, or ctrl-r in insert mode, a split will open to show you the register contents. Preview from ...
Tommy A's user avatar
  • 6,710
14 votes

How to replace text inside () with previously yanked text?

You can use visual selection to select the text to replace, and then paste over it as follows: vi(p vi( selects Baz (because it is enclosed in parenthesis), p pastes Fnord over it. However, this ...
Alex's user avatar
  • 1,293
11 votes
Accepted

Is there a way to paste text from a buffer into your command using just the keyboard?

Yep, just like in insert mode: Ctrl-R followed by the register name, or " for the default one (i.e. Ctrl-R "). See :h c_CTRL-R.
VanLaser's user avatar
  • 9,620
11 votes
Accepted

Repeat last yank

If you include the flag y in the cpoptions option; set cpoptions+=y then yanks may be repeated using .. See :help cpo-y: *cpo-y* y A yank command can be redone ...
Mass's user avatar
  • 13.9k
11 votes
Accepted

How to source a part of a file

After you've done your Visual selection run this: y:@"<CR> y copies the selection to the unnamed register (") since we didn't explicitly name a register. Then :@" executes the contents of that ...
dedowsdi's user avatar
  • 6,188
10 votes

How to replace text inside () with previously yanked text?

Unless you specify a register, p (or P) will use the last register that was filled. The unnamed register "" contains the most recently yanked or deleted text (unless another register was specified, e....
Steve's user avatar
  • 446
9 votes
Accepted

Get list of lines that begin with a pattern

This can be done pretty easily with the global command. I would try this: :let @a='' :g/^function/y A First we must call :let @a='' to make sure that the 'a' register is empty. Then, the global ...
DJMcMayhem's user avatar
  • 17.4k
8 votes

How can I clear a register/multiple registers completely?

For those wanting to remove the register name (say, a) from the :registers list, there is a way to do it now. Run the command :call setreg('a', []). I found this out from this question on ...
Jason Cemra's user avatar
8 votes
Accepted

How to set manually the alternate file

The alternate file is stored in a register, "#. Change you line to: let @#='/path/to/alternate/file' For more help see: :h registers :h quote# :h :let-@
Peter Rincker's user avatar
8 votes
Accepted

How to use register in a script without side effect?

If your Vim contains the patch 8.2.0924, then try to use getreginfo(): function Foo() let save_cb = &cb let regInfo = getreginfo('"') try norm! y{motion} do ...
user938271's user avatar
  • 5,867
7 votes

How can I easily list the content of the registers before pasting?

I would recommend using :reg It will show the contents of all registers (you can scroll through using j and k). If you just want to show the contents of one register, you can go to command mode ...
DoYouEvenCodeBro's user avatar
7 votes
Accepted

How can I easily list the content of the registers before pasting?

I made up this mapping to display the register list and select the one to be pasted: nnoremap "p :reg <bar> exec 'normal! "'.input('>').'p'<CR> This display the register list with :...
nobe4's user avatar
  • 15.9k
7 votes

Why is a Line Feed converted into a Null character inside the search register and into a Carriage Return on the command line?

First, thank you for this very comprehensive and thoughtful post. After some testing, I have come to this conclusion: Control characters are displayed using the caret notation: ^M for <CR> (...
Géry Ogam's user avatar
7 votes
Accepted

Why is the previously inserted text reset after using an arrow key?

In insert mode, the left arrow key actually exits insert mode, moves the cursor, then re-enters insert mode. That breaks your change into two changes: inserting () and inserting foo. This behavior is ...
garyjohn's user avatar
  • 6,284
7 votes
Accepted

Visually selecting a line and then deleting does not copy to black hole register

nnoremap only affects [n]ormal mode and will not affect [v]isual mode. You need vnoremap for that: vnoremap d "_d
Tumbler41's user avatar
  • 7,706
7 votes

Copying multiple words (from different lines) and paste them at once

You could also define your own custom operator which would yank incrementally any text-object or text covered by a motion: fu! Incremental_yank(type, ...) abort if a:type ==# 'char' norm! ...
user9433424's user avatar
  • 6,118
7 votes
Accepted

How to concatenate two registers?

It is not exactly clear what you would like to happen when e.g. one register contains a linewise selection and the other one contains a block selection. But for the easy case, you can always do (as ...
Christian Brabandt's user avatar
7 votes
Accepted

Registers ” vs @

Note: all of the following information (and much more) can be found using :help @, :help ", :help let-@, and :help expr-register "ap,"ad, &c.: use register a in a put from or ...
Mass's user avatar
  • 13.9k
7 votes
Accepted

Is it possible to run a script on a register content and send its output to another register on Vim?

You could do this: let @b=system("time.bash " . @a) The @a is register a and @b is register b. The system(...) runs a command and returns the output. The result is a line, so when you paste it, you ...
Ralf's user avatar
  • 9,097
7 votes

Yank both sides of equation

This can be done with either regex+substitute or macros Substitute. This is the same as your regex except the important parts are surrounded by \( . \) to create capture groups. These are referred ...
Mass's user avatar
  • 13.9k
7 votes

running external command on contents of register

Not with the ! command. You'll have to use system instead. From :h system(): system({expr} [, {input}]) *system()* *E677* Get the output of the shell command {expr} as a string. ...
DJMcMayhem's user avatar
  • 17.4k
7 votes

Vim not storing numbered registers

Vim automatically stores previously yanked texts into registers from 1 to 9 That's not accurate. Registers 1 through 9 are actually used for the previously delete or change commands. Yank commands ...
filbranden's user avatar
  • 28.4k
7 votes

Recover whole search pattern for substitute command

As B Layer said, Vim interprets the rest of the pattern (namely, foo/bar.../) as an invalid offset, so it throws that bit away. I have found, however, an alternative: q/ opens the complete search ...
Quasímodo's user avatar
  • 2,416
7 votes
Accepted

Recover whole search pattern for substitute command

I wasn't going to post this beyond my comment but then I see it turned into a competition. ;) If you mistakenly enter /%s/foo/bar/ when you actually want to run :%s/foo/bar/ then you just need these ...
B Layer's user avatar
  • 19.5k
6 votes
Accepted

How can I conveniently yank then change small text?

If you don't use a specific register, the text you yank systematically goes into register 0 where it will stay until you yank something else. This means that you can still use what you yanked, even ...
romainl's user avatar
  • 39.2k
6 votes

In neovim, how can I share registers between editor instances?

No idea about the clientserver feature, the simplest way I can think of would be to use the system clipboard by default when yanking or pasting which can be done with: set clipboard=unnamedplus ...
LEI's user avatar
  • 1,606
6 votes
Accepted

How to store all occurrences of a multiline search in a register?

It turns out something along these lines works (although there might well be better ways) -- using a substitute-without-substituting command instead of a global command: Starting with the answer here:...
Jonathan's user avatar
  • 141
6 votes
Accepted

How to delete blocks of text which contain a specific string?

You can use a macro: Once your search register is set to Subject: Bar you can empty a register (q in this example) and record the following macro: qqq qqndap@qq The first line empties the q ...
statox's user avatar
  • 49.4k

Only top scored, non community-wiki answers of a minimum length are eligible