3

Is there a quick way to delete brackets ( some string ) and then select "some string"?

ds( deletes them (using the surround plugin). vi( selects but only when they exist.

looking for normal mode.

  • If the expression ( some string ) is in a single line, then the markers `[ and `] will mark the start and end of the expression, so you could use `[v`] to select it. Unfortunately, that doesn't work when the expression spawns multiple lines... – filbranden Feb 23 at 2:09
2
vi(<Esc>ds(gvhoh

Breakdown:

  1. vi( selects visual region within the brackets using the surround plugin.
  2. <Esc> stops the visual selection mode.
  3. ds( deletes the surrounding brackets using the surround plugin.
  4. gv restarts 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 (.
  5. h begins correcting the original position of the visual selection by moving the right edge of visual selection leftwards by one character.
  6. o transports cursor to the other end of the visual selection.
  7. h moves 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 <strong></strong> etc.

| improve this answer | |
  • 1
    Yeh, I knew something like this would work, but not fund of it. See if anyone got something better. – eyal karni Mar 2 at 19:11
  • You can also save marks. I would do ma%mbx`axv`b – eyal karni Mar 3 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.