aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2021-11-03 22:55:40 +0800
committerjdhao <jdhao@hotmail.com>2021-11-03 22:55:40 +0800
commit49fc7f3dbc6e2a601ab525fb267ee93f98765071 (patch)
tree900923747bc3b4fcc6a0684e3cd010d832f69a62
parent573f9277cb1045bd247d18fbc793865d232801ff (diff)
add mapping: keep cursor position after yanking
-rw-r--r--core/mappings.vim13
1 files changed, 13 insertions, 0 deletions
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 <A-;> <ESC>miA;<ESC>`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