vim

How to quickly remove a pair of parentheses, brackets, or braces in Vim?


In Vim, if I have code (in Ruby) like so:

anArray << [anElement]

and my cursor is on the first [, I can hop to ] with the % key, and I can delete all the content between the [] pair with d%.

But what if I just want to delete the [ and ] leaving all the remaining content between the two? In other words, what is the quickest way to get to:

anArray << anElement

Solution

  • Using the Surround plugin for Vim, you can eliminate surrounding delimiters with ds<delimeter>.

    To install it via Vundle plugin, add

    Plugin 'tpope/vim-surround' 
    

    to your .vimrc file and run :PluginInstall.