3 ms·
Dude! Thank you so much. I was trying to figure out what magic incantation I needed to find the docs for "inner", etc. :help text-objects did the trick and I wo
by snprbob86 17y ago
Dude! Thank you so much. I was trying to figure out what magic incantation I needed to find the docs for "inner", etc. :help text-objects did the trick and I would have never considered remapping the s/S keys, which are agreeably pretty useless.
EDIT: I created slightly different bindings. These are a bit longer, but have the same power, flexibility, and use of the documented text-object motions.
" Remap s/S to surround operations
" :help text-objects
nmap s <Nop>
nmap S <Nop>
" Surround inner (si)
nmap siw viws
nmap siW viWs
nmap siss viss
nmap sip vips
nmap si[ vi[s
nmap si] vi]s
nmap si( vi(s
nmap si) vi)s
nmap si{ vi{s
nmap si} vi}s
nmap si< vi<s
nmap si> vi>s
nmap sit vits
nmap si' vi's
nmap si" vi"s
nmap si` vi`s
" Surround inner on new lines (Si)
nmap Siw viwS
nmap SiW viWS
nmap Siss visS
nmap Sip vipS
nmap Si[ vi[S
nmap Si] vi]S
nmap Si( vi(S
nmap Si) vi)S
nmap Si{ vi{S
nmap Si} vi}S
nmap Si< vi<S
nmap Si> vi>S
nmap Sit vitS
nmap Si' vi'S
nmap Si" vi"S
nmap Si` vi`S
" Surround an object on same lines (sa)
nmap saw vaws
nmap saW vaWs
nmap sas vass
nmap sap vaps
nmap sa[ va[s
nmap sa] va]s
nmap sa( va(s
nmap sa) va)s
nmap sa{ va{s
nmap sa} va}s
nmap sa< va<s
nmap sa> va>s
nmap sat vats
nmap sa' va's
nmap sa" va"s
nmap sa` va`s
" Surround an object on new lines (Sa)
nmap Saw vawS
nmap SaW vaWS
nmap Sas vasS
nmap Sap vapS
nmap Sa[ va[S
nmap Sa] va]S
nmap Sa( va(S
nmap Sa) va)S
nmap Sa{ va{S
nmap Sa} va}S
nmap Sa< va<S
nmap Sa> va>S
nmap Sat vatS
nmap Sa' va'S
nmap Sa" va"S
nmap Sa` va`S
- graywh 17y agoThose mappings aren't doing what you expect, because s and S in visual mode do the same thing. And instead of mapping all the text objects like that and using visual mode, you should just do this instead: nmap s ys nmap S yS
- snprbob86 17y agoI tested a number of the mapping, they seem to be working. I'm using surround.vim [1] which changes the behavior of s/S in visual mode. [1] http://www.vim.org/scripts/script.php?script_id=1697 http://www.vim.org/scripts/script.php?script_id=1697