Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
56 votes
Accepted

How can I view and edit my recording (i.e. recorded macro)?

Note: I'm assuming you're using the a register for the entirety of this answer, but you can use any register Note2: <1b> is Esc; you can insert this with Ctrl+v and then Esc. It may also show ...
user avatar
38 votes
Accepted

Performing certain operations without clearing register

Your options are: Use the black hole register _. For example, to delete a line you would type "_dd. This deletes without affecting the clipboard. Explicitly name a register for the original yank. ...
user avatar
24 votes
Accepted

How do I stop recording while in command line?

Another solution is when in command line mode, use Ctrl-f, and press q to stop recording. Ctrl-f allows you to open the command line window, in which you can edit the command in normal mode. To ...
user avatar
  • 356
20 votes

Copy the full path of current buffer to clipboard

You can assign to the clipboard with the special + register: :let @+ = expand('%:p') The :p makes it an absolute path; drop it if you want the relative path. If you want to make this easier, you ...
user avatar
20 votes

How do I stop recording while in command line?

One way to do it: start your macro as usual (e.g. qq ... other chars) when you reach the cmdline-mode, write all the characters you want you want to end the macro here. Hit ESC to get out of cmdline-...
user avatar
  • 9,260
18 votes
Accepted

What is the use of the black hole register ("_)?

The black hole register is used in the same situations as /dev/null: when you do an action that normally outputs something but you have no use for that output. Vim's default behavior is to "cut", not ...
user avatar
  • 32.6k
17 votes
Accepted

How to copy across terminals?

You can check if Vim is built with clipboard support with: :echo has('clipboard') If the output is 1, the following should be enough to achieve your goal: "*y in source Vim "*p in destination ...
user avatar
  • 32.6k
16 votes

How can I view and edit my recording (i.e. recorded macro)?

To get something to work with... qajjjq Will start record a macro into the a register. You can see many of your current registers (used for macros, yanking, deleting, etc.) with the :reg command, ...
user avatar
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 ...
user avatar
  • 1,347
15 votes
Accepted

How can I clear a register/multiple registers completely?

In short, there is not a cleaner way to wipe registers so completely that they disappear from :reg. Rather than murk around with ~/.viminfo, I tend to "softclear" registers when I'm really and truly ...
user avatar
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 ...
user avatar
  • 1,134
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 ...
user avatar
  • 6,320
12 votes

Performing certain operations without clearing register

x doesn't put things on the clipboard, it puts them into a register. If you don't tell it which register to put it into, it puts it into the unnamed register, which of course overwrites the previous ...
user avatar
  • 1,815
11 votes
Accepted

How to use substitution on register?

Ex commands work on the buffer contents; for register (or variable) contents, you need to use a corresponding Vimscript function (if it exists). For :substitute, the equivalent is substitute() (that ...
user avatar
  • 16.6k
11 votes

Can I make Vim also save "small deletions" into register "1?

This used to work in older Vim 7.3 versions when you :set clipboard=unnamed (see this Reddit discussion, as a result of a bug, which I've reported here. That thread contains a patch by Aryeh Leib ...
user avatar
  • 16.6k
11 votes
Accepted

Numbered register doesn't record most deleted text within a line?

It is. To quote from :h quote_number: Numbered register 1 contains the text deleted by the most recent delete or change command, unless the command specified another register or the text is less than ...
user avatar
  • 9,260
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.
user avatar
  • 9,260
11 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 ...
user avatar
  • 27.4k
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 ...
user avatar
  • 12.6k
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 ...
user avatar
  • 5,868
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....
user avatar
  • 436
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 ...
user avatar
  • 16.5k
7 votes
Accepted

How can text be moved from one register to an arbitrary number of registers?

Macros are just text. Open a new empty buffer and put your macro there. You can duplicate the lines, change one thing here and something else elsewhere then yank a line and use it right away with @". ...
user avatar
  • 32.6k
7 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 ...
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 ...
user avatar
  • 5,854
7 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-@
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 :...
user avatar
  • 15k
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
user avatar
  • 7,406
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 ...
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 ...
user avatar
  • 12.6k

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