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
1 vote
2 answers
19 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 &...
user avatar
  • 1,648
6 votes
3 answers
866 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 ...
user avatar
  • 249
2 votes
0 answers
32 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 ...
user avatar
0 votes
0 answers
37 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 ...
user avatar
2 votes
1 answer
55 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 ...
user avatar
  • 137
2 votes
1 answer
31 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 ...
user avatar
  • 1,648
0 votes
0 answers
14 views

Storing Latex Chunks in Registers

Previously I asked about how one could yank both sides of an equality into registers. My use case was writing latex and wanting to be able to take work that I previously just wrote and modify it ...
user avatar
4 votes
1 answer
109 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 ...
user avatar
  • 143
0 votes
2 answers
51 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 ...
user avatar
  • 173
4 votes
1 answer
74 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 ...
user avatar
0 votes
0 answers
31 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.
user avatar
1 vote
2 answers
82 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 ...
user avatar
  • 145
2 votes
1 answer
106 views

Escape key adds extra bytes into the register when recording a macro

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>&...
user avatar
0 votes
1 answer
35 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. ...
user avatar
  • 1,648
0 votes
1 answer
62 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 ...
user avatar
0 votes
1 answer
47 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 ...
user avatar
  • 541
0 votes
2 answers
82 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 ...
user avatar
0 votes
2 answers
55 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 ...
user avatar
  • 103
1 vote
2 answers
95 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 ...
user avatar
  • 375
0 votes
1 answer
40 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 ...
user avatar
  • 101
0 votes
2 answers
23 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 } ...
user avatar
1 vote
2 answers
42 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/...
user avatar
  • 1,697
0 votes
1 answer
40 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 ...
user avatar
  • 326
0 votes
0 answers
24 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&...
user avatar
  • 169
0 votes
1 answer
215 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 ...
user avatar
  • 111
3 votes
2 answers
204 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 ...
user avatar
  • 25.8k
5 votes
3 answers
265 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 (...
user avatar
  • 2,208
1 vote
2 answers
244 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:...
user avatar
-1 votes
1 answer
444 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 ...
user avatar
3 votes
2 answers
478 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 ...
user avatar
1 vote
1 answer
35 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;...
user avatar
  • 113
1 vote
0 answers
40 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 ...
user avatar
1 vote
1 answer
10 views

Odd behavior when trying to perform a substitution on the clipboard register

I have a map that creates a markdown hyperlink for the current url open in the browser: inoremap <Leader>gg [<esc>:silent !~/bin/copy_safari_title.osa <cr>"+pa](<esc>:...
user avatar
  • 1,257
3 votes
1 answer
164 views

Append to current copy buffer

I am copying multiple lines from different parts. I can for example do 3yy to copy the 3 next lines. Then I would like to scroll a bit and add 5 more lines: 5yy and so on. At the end, I want to paste ...
user avatar
1 vote
0 answers
53 views

No + or * register on Linux (accessed via SSH from macOS)? [duplicate]

I am on Ubuntu 14.04.3 and Vim 8.2. I'm trying to figure out how to access either the * or + clipboard on Ubuntu but it seems like it doesn't exist? After doing "*yy and "+yy on lines of ...
user avatar
  • 1,827
0 votes
2 answers
101 views

How to type Enter so that it's considered as Enter command?

I have noticed that I can execute a command by yank, then @". My question is how do I make enter work within the command? For example, when I yank :w<Enter>, I would like this command to be ...
user avatar
  • 101
2 votes
1 answer
375 views

How do I append to the unnamed register?

In particular, I'd like to append to the unnamed register with the :global command.
user avatar
  • 121
1 vote
1 answer
317 views

How to clear a vim register (vi/ex buffer)?

In the ex linage of editors, one can append to a register(vim)/buffer(ex,vi) by specifying the register name in uppercase. As an example g/pat/y A will append every line match pat to register a. But ...
user avatar
  • 133
0 votes
2 answers
86 views

no + or * register when entering vim from ranger

I'm running Ubuntu 18.04 with i3wm. Vim and vim-gtk3 packages are installed. If I'm in a regular terminal and I start editing a file in vim. I can yank text to the + register as expected. However, if ...
user avatar
1 vote
1 answer
46 views

Set up a register backed by a file to fill in for xterm clipboard on a server without a display?

I used to use "+y and "+p in vim for copy pasting across vim instances. This also has the advantage that you can use "+ as a register for any command you know, including deletions etc. Now that I'm ...
user avatar
1 vote
2 answers
163 views

Embed <Return> within register

I want to have predefined register that will jump to the location matched by regular expression, i.e. in vimrc I add: let @a="/=\"" That will be useful for me when I want to navigate to the next ...
user avatar
  • 241
0 votes
0 answers
269 views

How to copy/paste from a local machine to a remote server

I am trying to copy text onto my clipboard on a local mac and paste it onto a remote linux server. I am able to yank the text from my local machine onto my machine's clipboard using: "*yy And I can ...
user avatar
  • 1,827
1 vote
1 answer
93 views

Yank inside quotes of a range of lines to a register and separate them with a new line character

I would like to populate a register with the text inside quotes for a range of lines. The register should contain all yanked text separated with new line characters. Example lines: The "black" cat A "...
user avatar
2 votes
1 answer
101 views

Execute the contents of a register with a delay after each command

So far, I managed to implement a function that adds a delay after "putting" each character contained in a register to the screen: function! AnimateInsertion() abort " split contents of last ...
user avatar
  • 67
1 vote
1 answer
102 views

How do I setup a command to use the "in word" as an argument

I would like to set up vim-fzf to do git grep/rg/ag/whatever on the word my cursor is over. With vim-grepper I was able to do gsiw for this and it was fantastic. With fzf I can't seem to figure out ...
user avatar
  • 125
1 vote
0 answers
47 views

Preview previously yanked text before put

I know that previous yanks are kept in numbered yank registers, a preview available with :registers. However this requires to keep a mental model which yank went where, with these numbers ever ...
user avatar
  • 353
1 vote
1 answer
88 views

How to convert register contents to something readable similar to :register command?

Let's assume there is a macro stored in register 'r' I can obtain the contents of this register by executing getreg('r'), but if I print this then it can often be unreadable. I noticed though that ...
user avatar
2 votes
2 answers
247 views

How not to let text in selection mode go to registers

I am using nvim-qt on Windows and I have set up the clipboard option: set clipboard=unnamedplus I found that text in Select mode will go to the +, * and " register after I start to type the ...
user avatar
  • 830
2 votes
1 answer
58 views

How do you read the contents of a macro into your buffer?

I know that you can use let @x = @w to copy the contents of a macro from one register to another, but how do you read the contents of your macro register into the buffer?
user avatar
  • 3,101
2 votes
1 answer
120 views

Why do I lose what I copied with "+y after exiting vim, and how to change that? [duplicate]

The + register always worked weird for me but only now I noticed a regularity in the weirdness: after I quit vim I can't paste anymore, it's as if the clipboard was replaced with a blank. Why, and can ...
user avatar
  • 121