Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev AndrewRadev/dsf.vim
Last active Nov 5, 2018

What would you like to do?
Delete surrounding function call
" Delete surrounding function call
" Relies on surround.vim
" function_call(cursor_here) => dsf => cursor_here
" Try `dsf` with more complicated structures:
" nested(function_call(cursor_here))
" nested(cursor_here(chewy_center))
nnoremap <silent> dsf :call <SID>DeleteSurroundingFunctionCall()<cr>
function! s:DeleteSurroundingFunctionCall()
if search('\k\+\zs[([]', 'b', line('.')) <= 0
" what's the opening bracket?
let opener = getline('.')[col('.') - 1]
" go back one word to get to the beginning of the function call
normal! b
" now we're on the function's name, see if we should move back some more
" e.g.,
let prefix = strpart(getline('.'), 0, col('.') - 1)
while prefix =~ '\(\.\|::\)$'
if search('\k\+', 'b', line('.')) <= 0
let prefix = strpart(getline('.'), 0, col('.') - 1)
exe 'normal! dt'.opener
exe 'normal ds'.opener
silent! call repeat#set('dsf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.