Questions tagged [register]
Registers store snippets of text for yank (copy), delete (cut), put (paste). In Vim, registers are also used for macro playback and some registers are special and can reference the OS clipboard or evaluate expressions.
209
questions
1
vote
0
answers
31
views
How to use register contents with bang?
I am having trouble in using registers with bang. I am trying to make the following snippet to work:
vim9script
def WslYank()
var text = shellescape(getreg('"'))
exe $'!echo "{text}&...
0
votes
2
answers
56
views
Any default command to swap the selection text
I’m quite noob in Neovim, not sure if it has builtin feature of key command to swap the selection text with its " (clipboard) register.
So anyone kind enough to clarify or laborate ?
2
votes
2
answers
114
views
Vim macro to mapping
My macros are getting a bit out of control and I would like to organize them into mappings.
Let's say I have a Vim macro stored in the register e. I open my .vimrc find the content of the macro by ...
0
votes
0
answers
35
views
How can I use the primary clipboard in a terminal emulator under Wayland?
When running vim in a terminal emulator under X11, any text selected in visual mode would be added to the primary clipboard, as expected. In addition, manually using the * register would also work.
In ...
0
votes
1
answer
37
views
How to yank only to specified register and do not touch (change) default " register?
I have mapping for duplicating current line in insert mode:
inoremap <C-d> <Esc>`^mzYp`zi<Down>
I want to set up it in a way it does not change default " register by specifying ...
0
votes
2
answers
36
views
How can I save the full filename in a register
It's often convenient to print the full filename in Vim. Sometimes, I want to save this into a register. Here's what I do:
1 ^g (1, then control-g)
Then I can select the filename with my mouse and ...
0
votes
4
answers
103
views
How do I duplicate a word?
How do I duplicate a word in my buffer?
Answers should take care to point out side effects such as modified registers and discuss tradeoffs of avoiding such effects vs simplicity.
0
votes
0
answers
22
views
WSL: Value of v:event.regname for non-alpha-numeric registers
I have a rather slow autocmd TextYankPost command that I'm trying to limit to the quoteplus (+) register. I've tried the following to get this to work:
autocmd TextYankPost * if v:event.regname is '+' ...
1
vote
4
answers
43
views
Rotate list of lines
Assume you have the following block of text (yes: I am using vim-latex, but this is not relevant):
\begin{itemize}
\item 1
% [[[
\item 2
\item 3
\item 4
\item 5
% ]]]
\item 6
\end{itemize}
My ...
1
vote
1
answer
60
views
Is there any way to "capture" the output of `g<`? (i.e. like how :redir works for other cmds)
I have some functions and mappings that echo paragraphs of summary output for me to "take a pulse" on some things I'm working on.
I know that if it disappears before I finish perusing, I can ...
0
votes
1
answer
26
views
Vim register becomes random values in gvim
Given the php code at the end, I add it to my gVim register with "ky.
Everything is fine. After some time, when I use it, the vim register looks like this:
jjjjjjjjjjjjj/^...
0
votes
0
answers
42
views
First attempt to paste from a register requires pause after <C-R>
When I yank text into any register, the first attempt to paste the content in insert mode using <C-R> doesn't do anything if I follow it too quickly with the name of the register. It works fine ...
0
votes
0
answers
73
views
Behavior of copy/paste with system register + has suddenly changed
(Vim version and system info follows at bottom)
Never had any problems copying to the system register with "+y before, nor pasting from that register into another application or into a terminal. ...
2
votes
1
answer
317
views
Neovim paste without overwriting register w/ Lua
So I know with vimscript you could make paste not overwrite your register with this:
vnoremap p pgvy
And I've tried a few ways to get this to with with Lua such as:
vim.api.nvim_set_keymap('n', 'p', '...
0
votes
1
answer
93
views
Change the clipboard register's name
To use Neovim with my system clipboard I have to use the + register which I find inconvenient. When I type something like "+p I have to bounce my pinky all around. Is there a way to change the ...
1
vote
1
answer
70
views
Search for ^@ in register '+'
After yanking into register + from Visual Block mode, the lines break are marked with ^@.
I would like to detect this character, but I can't..
For example, if register + contains ^@ as shown below
...
1
vote
1
answer
150
views
Syncing x clipboard with yanks and put only?
I have discovered the joy of having :set clipboard^=unnamedplus.
One issue I often face however is having whatever was last copied or yanked be overwritten by what I just deleted.
I don't think ...
2
votes
3
answers
113
views
How to get floating result in expression register?
I want to write a macro to set line height in fraction.
font-size: 18px;
line-height: 22px;
The problem is with expression register.
I set 2 variables
@f = font-size
@h = line-height
And
=@h/@f - ...
0
votes
2
answers
143
views
How can copy the matched string into register +?
For the below data:
-150000 2023-03-30
421.67 2023-04-20
575 2023-05-20
I can substitute the whole line with the first string
:%s/\v.{-1,}\s+(.+)/\1
Then the content was changed into:
-...
1
vote
1
answer
200
views
Remap p if no register is specified
To stop pasting over a selection from yanking that selection, I would like to remap p so that it doesn't yank the just-rewritten selection:
vim.keymap.set("x", "p", [["_dP]])
...
3
votes
1
answer
492
views
How to clear the uppercase registers?
The uppercase register has this nice characteristic of allowing appends to them.
However, every time I use them to yank a series of text, when it's time to paste them, I can see the old text from when ...
1
vote
2
answers
48
views
Why my visual selection buffer contains ^@
I am writing a function to reformat a visual selection:
function! FormatText() range
" Calling this function has ended visual mode, so it must be started
" again before the selection can ...
1
vote
2
answers
312
views
Yank non-consecutive lines into the register?
I'm surprised this hasn't been asked yet, but how do I copy non-consecutive lines into the buffer at once?
For example, let's say my file looks like this:
1
2
3
4
5
6
7
8
9
10
What commands can I use ...
0
votes
2
answers
55
views
Report more than 200 lines cut/pasted -- Vividly?
I have a text document where I frequently move/cut large blocks of text.
Every 2-3 months I inadvertently cut or paste a huge number of lines (60,000 today) and discover the error hours, or even days, ...
0
votes
1
answer
265
views
Expression Register - Power, Root & Mod
Foreword
In case you don't know, you can evaluate math expressions in vim/neovim with this command:
While in INSERT mode, press CTRL+R, then =. Example: =2+2 inserts 4 into your buffer.
Question
Is ...
0
votes
1
answer
28
views
Replace with fixed character (e.g. spaces) and add replaced text to register
I would like to have a selection that whose contents I replace with a command like r, but the replaced text is added to a register.
The use case is editing a Markdown table in Vim, where I want to ...
0
votes
4
answers
278
views
Replace every character on a visual selection with a register's character
I'll try to illustrate as clear as I can.
Suppose I have the following text open in vim/nvim
_________
| |
| 9999 |
| |
---------
If select 9999 visually and then hit r8, this ...
3
votes
1
answer
75
views
What does ^= mean in set command?
I had seen a set command in .vimrc:
set clipboard^=unnamed,unnamedplus
What does ^= mean in set command?What is the difference between
set clipboard^=unnamed,unnamedplus
and
set clipboard=unnamed,...
0
votes
2
answers
50
views
Copy text from all folds, excluding titles
How do I copy all lines from all folds, excluding the fold titles?
1
vote
1
answer
30
views
Is there any easy way to undo put if I selected the wrong register?
Sometimes I accidently put from the wrong register and end up hitting u to undo, but then I have to reselect the text that I was trying to replace. Is there an easy way to either reapply the put from ...
0
votes
1
answer
160
views
Yank list of lines into a register in vimscript
I am writing a function and I wish to yank a range of lines into a register.
The line that I cannot fix is the following:
let @" = getline(l:line_in,l:line_out)
where l:line_in and l:line out ...
2
votes
1
answer
45
views
How do the * and + registrers behave in the virtual console?
My Vim is installed with +clipboard support, and all works just fine.
I know that the clipboard comes with X, so there isn't such a thing in a virtual console (or, at least, this is what I've ...
1
vote
2
answers
691
views
What is @q doing?
I accidentally typed @q instead of :q and the file closed. I checked if I have a macro defined by using :reg q. It shows a long string of jibberish.
Is it possible to find out exactly what function @q ...
1
vote
1
answer
46
views
How does recording a macro differ from defining a macro directly?
In my Vim configuration, I have mapped the <C-j> key to <cmd>bn<CR>, but because the C-j key corresponds to the null character in Vim, this causes some strange issues when defining ...
0
votes
1
answer
52
views
Paste register contents from :reg screen
:reg displays the contents of the numbered and special registers. Is there a way to then paste a register but retain the output of :reg on the screen? This avoids the need to store the register name ...
2
votes
2
answers
110
views
Is there a plugin for saving/loading registers' contents to/from files in a convenient way?
tl;dr
Is there a Vim plugin that allows me to save/load registers to/from files with minimal typing, preview of registers, and other amenities?
Long version
Vim has a lot of registers. However, the &...
7
votes
3
answers
2k
views
How do I search the contents of registers?
I have a bad habit of deleting some text a, heading off to another section of the document to paste it, and finding something else along the way that I need to delete. When I get to my final ...
3
votes
0
answers
202
views
Store the current filename in a given register
When I exchange with colleagues about the code, when I refer to given functions, I like to also mention the file.
Since this exchange does not usually take place within vim, I usually copy them out ...
0
votes
0
answers
649
views
(Code review) Copying file path relative to cwd with the line number appended
I am replicating what PHPStorm and VSCode do by allowing me to copy the file path and line number (plus column) to clipboard. I have written a function in lua to do this, but, I wanted to ask about ...
3
votes
1
answer
198
views
How to save a macro (for quickly printing a variable)?
I'm trying to create a macro for an action that I very frequently use in Python: printing a variable in a bright color so it can easily be found in the traces while debugging.
So lets say there's ...
3
votes
1
answer
223
views
Inserting the content of a register where a macro is recorded results in control characters becoming unicode characters
If I hit Ctrl+V and then Escape while in insert or ex mode, I get ^[ as a single character.
If I hit qqEscapeq and then go see :registers, I see that q contains ^[<80><fd>a, which are ...
4
votes
1
answer
355
views
How to reference a register in an ex command
I'm trying to write what I thought would be a simple macro to take some values that have been yanked into some registers (a & b) and use bc to do some addition with those values.
Here is the ...
1
vote
1
answer
320
views
How to copy contents of wl-clipboard into a Vim register?
I would like to swap content between my system clipboard and a Vim register.
I am missing one last piece of the puzzle, indicated below. Any thoughts?
map <Leader>" :call SwapBuffer()<CR&...
3
votes
1
answer
381
views
Execute Ex command inside expression register
Executing :echo 'hello' prints "hello". Executing "=echo 'hello'<cr>p however, results in multiple errors.
Is there a way to execute Ex commands inside of the expression register?
0
votes
2
answers
83
views
How to execute a shell script from a line in a file with `%` in it
I have a shell script on a line alone in a file which I would like to be able to easily execute from vim. Normally I could simply use Y:!^R", but this particular script has % in it, which is ...
5
votes
1
answer
223
views
Register for your last action (.)
Vim has a lot of useful registers from which you can access the contents of various actions. There's ": for the last command in the command line, "/ for the last search, ". for the last ...
0
votes
0
answers
43
views
How do I show the jumps list permanently in a window?
As the title says, is there a way to view the jumps list opened in a permanent window? The question is also valid for registers list.
3
votes
2
answers
172
views
Manipulate the dot command without editing text in insert mode
I need to manipulate the dot command without directly editing the buffer for a plugin I'm developing.
The plugin needs to manually append text to the dot command that will be executed while in insert ...
5
votes
1
answer
523
views
Escape key adds extra bytes into the register when recording a macro [duplicate]
When I try to record a macro that involves hitting Esc the following bytes are added to the register <80><fd>a for example if I type qq<Esc>q when I :echo @q I get back ^[<80>&...
0
votes
1
answer
63
views
Why does cw followed by ctrl-r register consist of two edits?
I did cwCtrl-Ra at the beginning of a word to paste the content of register a in its place. And this, I thought, is done entering insert mode only once; or at least, never going back to normal mode.
...