In visual mode, how do I bind a key so that the selected text generates
%s/<SELECTEDTEXT>/<CURSORHERE>/g
?
Preferably ;
considering I never use it otherwise.
Thanks.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityIn visual mode, how do I bind a key so that the selected text generates
%s/<SELECTEDTEXT>/<CURSORHERE>/g
?
Preferably ;
considering I never use it otherwise.
Thanks.
xnoremap ; y<Esc>:%s/<C-R>"//g<Left><Left>
xnoremap
visual mode mapping, non-recursive
vnoremap
includes select mode as well, see What is the select mode and when is it relevant to use it?;
key to be mappedy
yank the selected text<Esc>
visual mode to normal mode:%s/
substitute command, all lines as range<C-R>"
paste contents of selected text//g
rest of substitute command<Left><Left>
move cursor to the left twice