ThePrimeagen / ThePrimeagen/init.lua

all the simple ways of "keep pasting" (without cursor movement, word replace, strcpy, strcpy + truncate until EOL)

Open
#42 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4k
Forks
680
PR merge metrics
No merged PRs in 30d

Description

-- my_utils.lua
local M = {}

-- starting at cursor: overwrite text to right with register content
-- keep_suffix defines, if remaining line suffix should be kept
M.pasteOverwriteFromRegister = function(register, keep_suffix)
  local line_content = vim.api.nvim_get_current_line()
  local reg_content = vim.fn.getreg(register)
  local tup_rowcol = vim.api.nvim_win_get_cursor(0) -- [1],[2] = y,x = row,col
  local col_nr = tup_rowcol[2] -- 0 indexed => use +1
  local col = col_nr + 1
  local reg_len = string.len(reg_content)
  local line_len = string.len(line_content)
  local prefix = string.sub(line_content, 1, col-1) -- until before cursor
  local suffix = string.sub(line_content, col+reg_len, line_len) -- starting at cursor
  if keep_suffix == true then
    vim.api.nvim_set_current_line(prefix .. reg_content .. suffix)
  else
    vim.api.nvim_set_current_line(prefix .. reg_content)
  end
end

return M
-- my_keymaps.lua
-- suggested keymapings
local opts = { noremap = true, silent = true }
local map = vim.api.nvim_set_keymap

map('n', '<leader>p', [[<cmd> lua require("my_utils").pasteOverwriteFromRegister('+', true)<CR>]], opts)
map('n', '<leader>P', [[<cmd> lua require("my_utils").pasteOverwriteFromRegister('+', false)<CR>]], opts) -- replacement for broken [[v$P]]
map('n', '<C-p>', 'p`[', opts) -- ] paste without cursor movement
map('n', ',', [[viwP]], opts) -- keep pasting over the same thing for current word, simple instead of broken for EOL [["_diwP]]

Opinions?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the proposed implementations in my_utils.lua and the mappings in my_keymaps.lua, starting with how each paste variant handles cursor position, word replacement, and the end of the line. The issue asks for opinions rather than defining a specific change or completion criterion, so the desired behavior must be clarified before work can be considered done.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.