Snippets

Sergio Luiz Araújo Silva keep cursor on yank nvim

Created by Sergio Araújo last modified
local augroup = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd


augroup('yankpost', { clear = true })
autocmd({ "VimEnter", "CursorMoved" }, {
     group = 'yankpost',
     pattern = "*",
     callback = function()
        cursor_pos = vim.fn.getpos('.')
     end,
})

autocmd("TextYankPost", {
    pattern = "*",
    group = 'yankpost',
    callback = function()
        local cursor = vim.fn.getpos('.')
        if vim.v.event.operator == 'y' then
            vim.fn.setpos('.', cursor_pos)
        end
    end,
})

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.