From 49fc7f3dbc6e2a601ab525fb267ee93f98765071 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 3 Nov 2021 22:55:40 +0800 Subject: [PATCH] add mapping: keep cursor position after yanking --- core/mappings.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/mappings.vim b/core/mappings.vim index c772ec9..c53d379 100644 --- a/core/mappings.vim +++ b/core/mappings.vim @@ -183,3 +183,16 @@ endfor " insert semicolon in the end inoremap miA;`ii +" Keep cursor position after yanking +nnoremap y myy +xnoremap y myy + +augroup restore_after_yank + autocmd! + autocmd TextYankPost * call s:restore_cursor() +augroup END + +function! s:restore_cursor() abort + silent! normal `y + silent! delmarks y +endfunction