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
*noremapwrong: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.vnoremapis 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,
vmapcovers 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 usingvmapso you are telling Vim to use whatever"currently does. Because…"to doS","in the RHS of your<C-c>mapping,vmapfor it…pressing
<C-c>doesS"+ygvwhich 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
*noremapwhen you want to use commands with their default meaning.Use
*mapwhen you want to use commands with their remapped meaning.