Is there a quick way to delete brackets
( some string ) and then select "some string"?
ds( deletes them (using the
vi( selects but only when they exist.
looking for normal mode.
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 community
vi(selects visual region within the brackets using the surround plugin.
<Esc>stops the visual selection mode.
ds(deletes the surrounding brackets using the surround plugin.
gvrestarts visual selection mode with the most recent visual selection, however it's tripped by the now missing brackets and the selection is shifted to the right by one character i.e. length of first surrounding character, here the
hbegins correcting the original position of the visual selection by moving the right edge of visual selection leftwards by one character.
otransports cursor to the other end of the visual selection.
hmoves the left edge of visual selection leftwards by one character.
Essentially this solution is based on
gv which reselects the most recent visual selection. You can adapt the rest of the key sequence to take care of any edge cases like if located at the end of line, or length of surrounding characters being more then 1 and uneven lengths, for e.g. html tags like