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.

Filter by
Sorted by
Tagged with
2 votes
1 answer
76 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', '...
Zach B.'s user avatar
  • 123
0 votes
1 answer
42 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 ...
fin444's user avatar
  • 103
1 vote
1 answer
52 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 ...
xyx's user avatar
  • 388
1 vote
1 answer
63 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 ...
dvqc's user avatar
  • 13
1 vote
1 answer
88 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]]) ...
theonlygusti's user avatar
  • 2,229
3 votes
1 answer
370 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 ...
Guilherme Marthe's user avatar
1 vote
2 answers
39 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 ...
Konstantin Glukhov's user avatar
1 vote
2 answers
143 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 ...
qotsa42's user avatar
  • 21
0 votes
2 answers
46 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, ...
cesces's user avatar
  • 25
0 votes
1 answer
117 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 ...
Pixelbog's user avatar
  • 417
0 votes
1 answer
21 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 ...
Jonathan Jeffrey's user avatar
0 votes
4 answers
152 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 ...
Diwas10's user avatar
  • 115
3 votes
1 answer
61 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,...
newview's user avatar
  • 291
0 votes
2 answers
40 views

Copy text from all folds, excluding titles

How do I copy all lines from all folds, excluding the fold titles?
markling's user avatar
  • 319
1 vote
1 answer
28 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 ...
Henry Crans's user avatar
0 votes
1 answer
116 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 ...
Barzi2001's user avatar
  • 481
2 votes
1 answer
43 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 ...
Enlico's user avatar
  • 2,172
1 vote
1 answer
40 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 ...
Andy Wang's user avatar
0 votes
1 answer
37 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 ...
Trent Gm's user avatar
  • 103
2 votes
2 answers
65 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 &...
Enlico's user avatar
  • 2,172
6 votes
3 answers
1k 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 ...
LSpice's user avatar
  • 249
3 votes
0 answers
82 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 ...
clem steredenn's user avatar
0 votes
0 answers
513 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 ...
Marwan Fikrat's user avatar
3 votes
1 answer
154 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 ...
Opifex's user avatar
  • 217
3 votes
1 answer
122 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 ...
Enlico's user avatar
  • 2,172
4 votes
1 answer
279 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 ...
cewood's user avatar
  • 143
0 votes
2 answers
67 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 ...
Iiridayn's user avatar
  • 193
5 votes
1 answer
154 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 ...
Luiz Martins's user avatar
0 votes
0 answers
39 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.
user515933's user avatar
3 votes
2 answers
163 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 ...
tversteeg's user avatar
  • 165
4 votes
1 answer
278 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>&...
Kasper-34's user avatar
0 votes
1 answer
57 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. ...
Enlico's user avatar
  • 2,172
0 votes
1 answer
135 views

What's the easiest way to replace some text with the contents of the clipboard when using clipboard=unnamed?

Assume I've copied some text into the clipboard from another program. I'm on MacOS, so in Vim terms, this means the text is in the + and * registers (I have verified this using :registers). I use ...
Andrew Ferrier's user avatar
0 votes
1 answer
92 views

When searching and replacing can I store a capture group to a register?

This is similar but I am unable to draw the information I need from it: How to store all occurrences of a multiline search in a register? I have these lines ################### trim 8 ...
Kes's user avatar
  • 611
0 votes
2 answers
145 views

Yanking range into register while ignoring blank lines

I’m trying to yank a range into a register while ignoring blank lines. My range is from line 10 to the end of the file. :10,$v/./"*y Looking at my registers in :reg I see that my text is not in ...
BrianWilson's user avatar
0 votes
2 answers
116 views

Can a register's value be checked at startup?

There are probably 20 better ways to do what I'm trying to do. Please direct me to them if so - I haven't found them and not quite sure what to terms to search. I would prefer to set background=dark ...
kdwarn's user avatar
  • 103
3 votes
2 answers
311 views

Is there any way of copying a macro inside a register to a different register?

I've discovered I can execute vim macros from the command line using the following command: vim myfile -c "argdo norm @aZZ" This command executed from the command line will execute a macro ...
raylight's user avatar
  • 525
0 votes
1 answer
50 views

Is it possible to call a shell command which includes default register contents inside a function?

I want to write a function which opens a vim plugin's Github page, eg calling the function while on this line: Plug 'tpope/vim-rhubarb' ... will do !open https://github.com/tpope/vim-rhubarb. Here's ...
Zubin's user avatar
  • 101
0 votes
2 answers
32 views

search and replace block to a line

I would like to replace a multiline block to one line for example : if (... ){ //comment0 line1 line2 } some code if (... ){ //comment0 line1 line2 } ...
Dor marcus's user avatar
1 vote
2 answers
91 views

search last substitution

After doing :%s/foo/bar/g I can type :<C-r>/ to place foo into the command line. How can I place bar into the command line? I ultimately want to do a series of: :%s/foo/bar/g :%s/bar/baz/g :%s/...
theonlygusti's user avatar
  • 2,229
0 votes
1 answer
43 views

Yanking into register within a script is not working

Given a file like this: Roy Maurice Jen Douglas If I were to type the following commands: ggVj"zy, followed by :reg z, I would see Roy and Maurice. Now I want to yank Jen and Douglas into the z ...
Phil R's user avatar
  • 471
1 vote
0 answers
26 views

How to point the cursor to result when search by 'let @/ = '?

To reproduce this problem: Open a new vim window, input "abc", leave cursor at the end of line set hlsearch let @/ = "abc" The cursor doesn't point to the beginning of "abc&...
aj3423's user avatar
  • 199
0 votes
1 answer
423 views

Delete/yank into multiple registers at the same time?

Is there a way to have y/d/c/x/s output into multiple registers at the same time - for example, "a as well as the system clipboard "+? I can do "aY"+Y obviously, and with Y it's ...
pxeger's user avatar
  • 111
3 votes
2 answers
309 views

Reliably saving and restoring registers across a function call [duplicate]

When writing functions to use in mappings and user-defined commands (for plug-ins), it's often convenient to use a Normal-mode command to yank or delete buffer contents. In those cases, it's also nice ...
filbranden's user avatar
  • 28.4k
5 votes
3 answers
315 views

Recover whole search pattern for substitute command

Sometimes I type a long substitute command /%s/foo/bar.../ and while I am typing it or only after hiting enter I notice that I have mistakenly used a the search key (/) instead of the ex-command key (...
Quasímodo's user avatar
  • 2,416
1 vote
2 answers
1k views

Pass visually-selected text as argument to script

I am trying to write a command that passes selected text to a shell script. The command works fine when there is no \n character in the selected text (using Visual mode). :vmap <Leader>tts 0y:...
Tony Barletta's user avatar
-1 votes
1 answer
1k views

Paste clipboard data in Insert mode

I have learnt to paste clipboard data (something i copied from web browser using ctrl+c) to my current buffer in insert mode. It is much easier than doing that in Normal mode. To paste clipboard data ...
andrew_ysk's user avatar
5 votes
2 answers
905 views

Vim not storing numbered registers

I've read that Vim automatically stores previously yanked texts into registers from 1 to 9, being 1 the previous yank, 2 the second previous, and so on... But this is not working for me. Here is a ...
paulodiovani's user avatar
1 vote
1 answer
42 views

Append single-line register to many lines

I have a file like ... one;line;with;many;data starter another_starter yet_to_end complete;line;providing;information ... and I would like to have: ... one;line;with;many;data starter;default;...
Mat M's user avatar
  • 113
1 vote
0 answers
85 views

Presentation of non-printable characters in messages

Vim has two options to represent non-printable characters - as a single char or using key-notation: ^J or <C-J>. By default, vim uses a single-char representation for :reg command: "q ...
Feedforward's user avatar