Skip to content

Instantly share code, notes, and snippets.

@kuuote
Created October 27, 2020 16:12
Show Gist options
  • Save kuuote/74ac3e4f548b7769cd09a0ecad4484cc to your computer and use it in GitHub Desktop.
Save kuuote/74ac3e4f548b7769cd09a0ecad4484cc to your computer and use it in GitHub Desktop.
yank without trailing spaces
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