tags:

views:

186

answers:

3

In Vim, if I have code such as (in Ruby):

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's the quickest way to get to:

anArray << anElement
+11  A: 

http://www.vim.org/scripts/script.php?script_id=1697

bahodir
An explanation: This is a vimscript by Tim Pope which adds a "ds[" command that does what I was looking for.
Josh
+4  A: 

ma%x`ax (mark position in register a, go to matching paren, delete char, go to mark a, delete char).

EDIT:

%x``x does the same thing (thanks to alok for the tip)

Justin Smith
As I said in my main comment, you don't need a manual mark: you can go to the last position by two backticks. So %x``x is faster.
Alok
This is similar to what I've been doing, but it's an awful lot of key-presses for an editor that's supposed to be very key-press-efficient.
Josh
A: 

The other answers work fine if you want to delete delimiters one line at a time. If on the other hand you want to remove a function and it's delimiters from the entire file use
:%s/function(\(.*\))/\1/g
which takes
function(arguments)
to
arguments
everywhere in the file.

vimmer