Search code examples
programming-languagesunix

How to delete text delimited by { and }


I am new to UNIX programming and had the following problem with UNIX vi editor.

Can you please tell me the UNIX command required to delete text delimited by { and } where both characters occur after the current cursor position. Thanks.


Solution

  • If you're on the same line :

    f{d%
    

    f{ moves you to the next { character d% deletes everything to the matching bracket

    If you're on a different line, use /{ to search for that character

    And if you want to delete ALL text delimited like this :

    :%s/{.*}//g
    

    (replaces all instances of anything between brackets with nothing)