Replies: 2 comments 1 reply
-
vim.keymap.set({ "x" }, "gy", "y`>", { noremap = true, silent = true }) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ZhaoYouYa
-
Using autocommands: local autocmd = vim.api.nvim_create_autocmd
local user_cmd = vim.api.nvim_create_user_command
-- @returns a "clear = true" augroup
local function augroup(name)
return vim.api.nvim_create_augroup('sergio-lazyvim_' .. name, { clear = true })
end
autocmd({ 'VimEnter', 'CursorMoved' }, {
group = augroup('yankpost'),
pattern = '*',
callback = function()
cursor_pos = vim.fn.getpos('.')
end,
desc = 'Stores cursor position',
})
autocmd('TextYankPost', {
pattern = '*',
group = augroup('yankrestoreposition'),
callback = function()
if vim.v.event.operator == 'y' then
vim.fn.setpos('.', cursor_pos)
end
end,
desc = 'Restores cursor position',
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
For example:
I'm a rookie, thanks for your help!
Beta Was this translation helpful? Give feedback.
All reactions