Skip to content
jacobsandlundPublic

About

Version control for copy+paste

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

170 Commits

Folders and files

Repository files navigation

copyv

Version control for copy paste! copyv will keep copy-pasted code up to date with a single command, even merging updates with your changes.

Installation

git clone git@github.com:jacobsandlund/copyv.git # or use https
cd copyv
zig build -Doptimize=ReleaseFast
cp zig-out/bin/copyv ~/.local/bin # or somewhere on your PATH

Usage

Instead of copying code from GitHub, copy the URL for a file, then add a copyv: <URL> comment in your code. If you want only certain lines, that works too (click the first line number, then shift-click the final--for markdown files, first switch to the Code tab instead of the Preview).

For example, in your ~/.config/nvim/init.lua, add:

-- copyv: https://github.com/nvim-telescope/telescope.nvim/blob/master/README.md?plain=1#L141-L145

Then run copyv <file> to copy the code.

Note

If you actually want to try running this example, use this URL instead, since this is an example of running copyv in the past: https://github.com/nvim-telescope/telescope.nvim/blob/63e279049652b514b7c3cbe5f6b248db53d77516/README.md?plain=1#L138-L142

$ copyv ~/.config/nvim/init.lua

Your file now contains:

-- copyv: https://github.com/nvim-telescope/telescope.nvim/blob/63e279049652b514b7c3cbe5f6b248db53d77516/README.md?plain=1#L157-L161 begin
local builtin = require('telescope.builtin')
vim.keymap.set('n', 'ff', builtin.find_files, {})
vim.keymap.set('n', 'fg', builtin.live_grep, {})
vim.keymap.set('n', 'fb', builtin.buffers, {})
vim.keymap.set('n', 'fh', builtin.help_tags, {})
-- copyv: end

The begin/end pair delimits a slice: a region of a file that copyv keeps in sync with its source. A slice is whatever the URL selects — part of a function, one whole function, several of them, or the entire file when the URL carries no line numbers.

Later, when the upstream config improves, run copyv . to update every tagged slice under the current directory:

$ copyv .

Directories are searched recursively, so copyv . is the usual way to update everything. Run copyv --help (or copyv with no arguments) to see all options.

Use copyv --changed to rewrite only slices whose source content changed. This leaves a slice completely untouched when only its commit SHA or line numbers changed. Use copyv --changed-or-moved to also rewrite slices whose source moved to different line numbers, while still ignoring SHA-only changes. Options may appear before or after paths; -- ends option parsing, for the rare path that starts with -.

Slices match the line endings of the file they live in: copyv detects whether the destination file predominantly uses LF or CRLF and converts copied code to that ending, so a CRLF source never introduces mixed line endings into an LF file (or vice versa). Diffing and merging ignore line-ending differences. Use copyv --force-lf or copyv --force-crlf to override the detection and write every visited slice with that ending. These cannot be combined with --changed or --changed-or-moved, since those modes leave unchanged slices untouched and would skip rewriting stale line endings.

This merges in all the changes up to the latest, including commit 286628d which adds a missing <leader>, and updates the SHA:

--- copyv: https://github.com/nvim-telescope/telescope.nvim/blob/63e279049652b514b7c3cbe5f6b248db53d77516/README.md?plain=1#L138-L142 begin
+-- copyv: https://github.com/nvim-telescope/telescope.nvim/blob/3a12a853ebf21ec1cce9a92290e3013f8ae75f02/README.md?plain=1#L145-L149 begin
 local builtin = require('telescope.builtin')
-vim.keymap.set('n', 'ff', builtin.find_files, {})
-vim.keymap.set('n', 'fg', builtin.live_grep, {})
-vim.keymap.set('n', 'fb', builtin.buffers, {})
-vim.keymap.set('n', 'fh', builtin.help_tags, {})
+vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope find files' })
+vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Telescope live grep' })
+vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = 'Telescope buffers' })
+vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Telescope help tags' })
 -- copyv: end

About

Version control for copy+paste

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages