Skip to content

Instantly share code, notes, and snippets.

@nilium
Created November 21, 2016 23:03
Show Gist options
  • Save nilium/3e362d75975ede5ea3ee76b7d1538e33 to your computer and use it in GitHub Desktop.
Save nilium/3e362d75975ede5ea3ee76b7d1538e33 to your computer and use it in GitHub Desktop.
Stamp-over-word mapping / command
" Stamp
" Maps S (shift+s) to replace the current word under the cursor with whatever's
" in the given (or default) register.
function! s:Stamp(reg)
if a:reg == ""
let a:reg = v:register
endif
execute "let l:v = @" . a:reg
exec "norm! viw\"" . a:reg . "p"
execute "let @" . a:reg . " = l:v"
endfunction
command! -register -nargs=? Stamp call s:Stamp("<register>")
nnoremap S :execute ":Stamp ".v:register<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment