Many useful mappings need to temporarily save text.
Some practical examples are:
" Move line up/down nnoremap <c-j> ddp nnoremap <c-k> ddkP " Substitute word under cursor (use `cc` instead of default `S`) nnoremap SS yiw:s/<c-r>"/ nnoremap S% yiw:%s/<c-r>"/ " Substitute selection vnoremap SS y:s/<c-r>"/ vnoremap S% y:%s/<c-r>"/
These mappings has to yank a piece of text for later use. I have always used the default register for this but there is a problem with this approach.
By using the default register in the mapping I am overwriting it's previous content.
If the user has yanked some text and then executes one of the mappings the yanked text will be overwritten. This is something very minor but it has started to annoy me lately.
There has to be a better way to do this.
Is there a way to make mappings like these but do not affect the global Vim environment? If not then what is your solution to this problem?