The following function works for the first occurrence of
Box::new on the current line:
function DeleteBox() abort
let [match, start, _end] = getline('.')->matchstrpos('Box::new')
if empty(match) | return | endif
call setcharpos('.', [0, line('.'), start+1, 0])
execute "normal! %x\<C-o>df("
You can map
dsx to perform the action:
nnoremap dsx <cmd>call DeleteBox()<cr>
Or run it on every line:
If you have multiple
Box::new per line, repeat the
:global command with
@: until it errors (using a high count like
99@: is usually sufficient).
With some tweaks, you could try to make it work anywhere in the current
Box::new expression, but that will be more difficult. Assuming you multiple
Box::new per line almost never occurs, this should be sufficient.
If you don't care for positioning so much, the following will delete just about any parenthesized wrapper starting from the cursor position:
nnoremap dsX %x<C-o>df(
 are of course possible.
This differs from https://github.com/tpope/vim-surround in that it deletes text, too; but with vim-surround I prefer to
/Box::new<cr>dgndsb or similar.