Last active
May 10, 2023 02:36
-
-
Save wellle/8633440 to your computer and use it in GitHub Desktop.
Yank without moving the cursor to the beginning of the yanked text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nnoremap <silent> y :<C-U>call MarkAndSetOpfunc()<CR>g@ | |
vnoremap <silent> y :<C-U>call MarkYankAndJump()<CR> | |
function! MarkAndSetOpfunc() | |
let g:save_cursor = getpos(".") | |
set opfunc=YankAndJumpBack | |
endfunction | |
function! MarkYankAndJump() | |
let g:save_cursor = getpos(".") | |
call YankAndJumpBack(visualmode(), 1) | |
endfunction | |
function! YankAndJumpBack(type, ...) | |
if a:0 | |
silent exe "normal! `<" . a:type . "`>y" | |
elseif a:type == 'line' | |
silent exe "normal! '[V']y" | |
elseif a:type == 'block' | |
silent exe "normal! `[\<C-V>`]y" | |
else | |
silent exe "normal! `[v`]y" | |
endif | |
call setpos('.', g:save_cursor) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nnoremap yy yy
fixedyy
for me.