I intend to surround
my visual selection, same as sublime and other editors.
Since I already have surround
plugin installed, therefore viwS"
does surrounds the selected word with "
and similarly for '
, etc
Therefore following is my attempt :
vnoremap ' S'
vnoremap " S"
vnoremap [ S[
vnoremap { S{
vnoremap ( S(
But mysteriously it deletes the entire line and inserts the quote
when I try using them.
Where am I going wrong ? How to correct it ?
You are using
*noremap
wrong:When you use
*noremap
, you ask Vim to use the original meaning ofS
.When you use
*map
, you ask Vim to use whatever is the current meaning ofS
.vnoremap
is OK if the commands executed by your mapping are supposed to be native commands but you are using a command that is already remapped by a plugin. You should use*map
, instead.Additionally,
vmap
covers visual and select mode: you should probably be more precise in your mappings.So…
(edit)
Your problem with
<C-c>
is the exact reverse: you are usingvmap
so you are telling Vim to use whatever"
currently does. Because…"
to doS"
,"
in the RHS of your<C-c>
mapping,vmap
for it…pressing
<C-c>
doesS"+ygv
which is not what you want. The rules above are simple: follow them and all will be good. Here they are again, with a slightly different wording:Use
*noremap
when you want to use commands with their default meaning.Use
*map
when you want to use commands with their remapped meaning.