Created
October 27, 2020 16:12
-
-
Save kuuote/74ac3e4f548b7769cd09a0ecad4484cc to your computer and use it in GitHub Desktop.
yank without trailing spaces
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
let s:ops = {"line":"V", "char":"v", "block":"\<C-v>"} | |
function! DoNoSpaceYank(wise) abort | |
let from = getpos("'[") | |
let to = getpos("']") | |
let visualop = s:ops[a:wise] | |
call inputsave() | |
keepjumps call setpos(".", from) | |
keepjumps call feedkeys(visualop, "nx") | |
keepjumps call setpos(".", to) | |
keepjumps call feedkeys("y", "nx") | |
call inputrestore() | |
let cmd = "let @%s = substitute(@%s, '[[:space:]]*$', '', '')" | |
let g:hoge = cmd | |
execute printf(cmd, '"', '"') | |
execute printf(cmd, v:register, v:register) | |
endfunction | |
function! NoSpaceYank(op) abort | |
set opfunc=DoNoSpaceYank | |
call feedkeys(a:op, "ni") | |
endfunction | |
nnoremap gy :<C-u>call NoSpaceYank("g@")<CR> | |
xnoremap gy :<C-u>call NoSpaceYank("gvg@")<CR> | |
onoremap gy g@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment