www-gem words

Using the black hole register to upgrade default keybindings

Published on

Bvim y default, each time you delete or change a text, that text is stored in (neo)vim register automatically. This default behavior can sometimes conflict with your workflow but this is the way I choose if a text should be stored in my clipboard when manipulating my text: using the black hole register "_.

╭── Pasting text

Place this code in your lua config (adapt it if using vimrc).

vim.keymap.set('x', 'p', [["_dP]]

Now, if you select a text, pressing p will paste the text from your clipboard as expected but your clipboard will not be automatically updated with the selected text. So you can paste the same text from your clipboard several times in a row and you will have to actually copy a selected text if you want it to replace the one stored in your clipboard.

╭── Deleting text

Place this code in your lua config (adapt it if using vimrc).

vim.keymap.set({'n', 'v'}, 'x', [["_x]])
vim.keymap.set({'n', 'v'}, 'X', [["_d$]])

Both lines will create keybindings for normal and visual modes.

The first line will prevent the character deleted with x to replace the text stored in your clipboard.
The second line will act as D (i.e. delete the text from the cursor position to the end of line) but without replacing the text stored in your clipboard.

If you need it, you can now easily see how to use the black hole register to extend your text manipulation. For example by creating some keybindings to call:


Thanks for your read. Hope it's been useful to you.


Interact with this post using Mastodon or

Comment on wwwgem's post

Copy and paste this URL into the search field of your favourite Fediverse app or the web interface of your Mastodon server.

✄ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈

More food for thoughts? Check other posts about: #Vim