a plugin for neovim adding a "replaste" operator

gwen 4a98d69d6a Update 'README.md' 1 年之前
lua 70a5491bd1 rename folder it works now 1 年之前
.gitignore ec9bb696fb Initial commit 1 年之前
LICENSE ec9bb696fb Initial commit 1 年之前
README.md 4a98d69d6a Update 'README.md' 1 年之前

README.md

nvim-replaste

a plugin for neovim adding a "replaste" operator

what the hell does "replaste" mean? Imagine this is your buffer:

{
	'thing1': 'value_A',
	'thing2': 'another_thing_entirely'
}

and you realize that another_thing_entirely should actually also read value_A to produce this:

{
	'thing1': 'value_A',
	'thing2': 'value_A'
}

That operation is a "replaste"

To execute a replaste in stock vim you have several choices:

  • the nano way (why are you even here?)
    • enter insert mode
    • backspace or delete another_thing_entirely
    • type out value_A
  • the vim way
    • do yi' on value_A to put it into the unnamed register
    • use di' on another_thing_entirely to get rid of it
    • realize you just clobbered the unnamed register and repeat step 1
    • p to paste
      • optionally use the wrong one between p or P and then need to undo and correct that.
  • the vim way for smarties
    • do yi' on value_A to put it into your register
    • use "_di' on another_thing_entirely to get rid of it without clobbering the register
    • p to paste
  • there are a few more vim ways but they are all about the same level of annoying

The nvim-replaste plugin lets you bind a hotkey to the replaste operator. so if I mapped it to .p then the opertation becomes:

  • do yi' on value_A to put it into your register
  • do .pi' on another_thing_entirely

Much better! The i' motion can be swapped with any motion you might need.

nvim-replaste also has an operator called "swapaste" which swaps the content of the register with the content of your motion. So if the buffer reads:

{
	'thing1': 'value_A',
	'thing2': 'another_thing_entirely'
}

But you want the buffer to read

{
	'thing1': 'another_thing_entirely',
	'thing2': 'value_A'
}

Then if swapaste is mapped to .y then the steps are

  • do di' with your cursor on value_A
  • do .yi' on another_thing_entirely
  • go back and do p in the hanging quotes where value_A used to be

Thats it! install and start replasting :)

Installation

If you are using lazy.nvim then add this:

{
    'https://mygit.link/gwen/nvim-replaste.git',
        lazy = false,
        opts = {
            replasteKey = '<Leader>p',
            swapasteKey = '<Leader>y',
        },
}

replasteKey and swapasteKey are the first argument to a nmap (or more accurately the second argument of a vim.keymap.set call)

Shame Clause

This software was written by a real person. She made it for fun and to be useful for herself. It is licensed as Creative Commons 0. Legally speaking anyone can use it for anything. I truly defy you to turn a profit with this one.

However if you are a capitalist doing capitalist things or a fascist doing fascism:

Get Bent!

You are explicitly unwelcome here. The author thinks that you are a bad person, shame on you.

This software was written for artists, students, hackers, and laborers.

If you are on our side, and are selling your labor then I would ask you to consider: will using this software will help you or will help your boss? If the software is helping you survive the hellscape, then please take it and go on with my blessing. But if it's only going to help your boss, make them pay you to write it instead.

A better world is possible and we are going to build it together <3