17
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 ...
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 ...
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 ...
12
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 ...
11
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 ...
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 ...
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 ...
8
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 :...
8
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 ...
8
votes
Accepted
How does Vim knows if register contents were from a linewise selection when pasting?
You can use getregtype() to get a register's type (characterwise, linewise, blockwise).
echo getregtype('a')
This will yield, v, V, or <c-v> for the "a register.
For more help see:
:h ...
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 ...
8
votes
Accepted
Execute Ex command inside expression register
You use a command :echo in place of an expression :help expr.
There is however a function (whose invocation is an expr8 or expr9) that executes commands:
"=execute('echo "hello"')<CR&...
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
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> (...
7
votes
How can I clear a register/multiple registers completely?
Put this in your .vimrc:
command! WipeReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor
and clear every register with :WipeReg
If you would like that to happen every time ...
7
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
...
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! ...
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 ...
7
votes
How to replace string with register content?
I was looking for this same thing today, and thanks to Rich's answer regarding usage of execute in Vimscript, came to this interactive method that does not involve Ctrl-R.
:s/:/\=getreg('0')/g
Thank ...
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 ...
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 ...
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 ...
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. ...
7
votes
Accepted
Expression register and fractions
As none of your numbers contains a decimal point (:help floating-point-format), Vim treats the expression as integer division, and also gives an integer result.
Simply specify one or both numbers as ...
7
votes
Accepted
Write register 0 to file
Have you tried to obtain the register as a list instead? See :h getreg()
:call writefile(getreg('0', 1, 1), ....)
PS: temporary filenames are best obtained with tempname()
Now, let's put this into ...
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 ...
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 ...
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 ...
6
votes
Accepted
In neovim, how can I share registers between editor instances?
LEI is right; and the neovim help instructions give this as a specific use case for that feature:
Two commands can be used to read and write the ShaDa file manually.
This can be used to exchange ...
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:...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
register × 209cut-copy-paste × 56
vimscript × 26
macro × 22
os-clipboard × 19
vimrc × 14
key-bindings × 12
search × 12
visual-mode × 10
command-line × 9
substitute × 9
expression-register × 9
replace × 8
repeated-commands × 7
regular-expression × 6
external-command × 6
ex-mode × 6
neovim × 5
functions × 5
visual-block × 5
normal-mode × 4
buffers × 3
linux × 3
multiple-lines × 3
range × 3