sponsor Vim development Vim logo Vim Book Ad

dsf.vim : Delete surrounding function call

 script karma  Rating 0/0, Downloaded by 134  Comments, bugs, improvements  Vim wiki

created by
Andrew Radev
script type
The plugin defines a mapping to delete a surrounding function call (or something similar to one), even if it happens to be namespaced. Some examples:

    nested(function_call(cursor_here))   -> nested(cursor_here)
    nested(cursor_here(chewy_center))    -> cursor_here(chewy_center)
    One::Two.new([cursor_here])          -> [cursor_here]
    One::Two.new(Hash[cursor_here])      -> One::Two.new(cursor_here)
    SomeStruct{cursor_here: "Something"} -> cursor_here: "Something"

By pressing `dsf` (which stands for "delete surrounding function call") with the cursor on `cursor_here`, you get the result on the right.

The plugin also defines `csf` to "change surrounding function call", which deletes only the function itself and leaves the cursor waiting to enter a new name.

The plugin also defines text objects for `if` and `af` to manipulate function calls with their contents. Given this example:

    var result = function_call(one, two);

Typing `daf` ("a function call") with the cursor anywhere on `function_call(one, two)` would result in:

    var result = ;

Typing `dif` ("inner function call") with the cursor anywhere on `function_call(one, two)` would result in:

    var result = function_call();

To learn more about how text objects work, try `:help text-objects`.

If you'd like to set your own mappings, instead of using the built-ins, simply set the variable `g:dsf_no_mappings` to `1` and use the <Plug> mappings provided by the plugin:

    let g:dsf_no_mappings = 1

    nmap dsf <Plug>DsfDelete
    nmap csf <Plug>DsfChange

    omap af <Plug>DsfTextObjectA
    xmap af <Plug>DsfTextObjectA
    omap if <Plug>DsfTextObjectI
    xmap if <Plug>DsfTextObjectI

Change any of the left-hand sides of the `map` calls to whatever you'd like.
install details
The easiest way to install the plugin is with a plugin manager:

- vim-plug: https://github.com/junegunn/vim-plug
- Vundle:   https://github.com/VundleVim/Vundle.vim

If you use one, just follow the instructions in its documentation.

You can install the plugin yourself using Vim's "packages" functionality by cloning the project (or adding it as a submodule) under `~/.vim/pack/<any-name>/start/`. For example:

    git clone https://github.com/AndrewRadev/dsf.vim ~/.vim/pack/_/start/dsf

This should automatically load the plugin for you on Vim start. Alternatively, you can add it to `~/.vim/pack/<any-name>/opt/` instead and load it in your .vimrc manually with:

    packadd dsf

If you'd rather not use git, you can download the files from the "releases" tab and unzip them in the relevant directory: https://github.com/AndrewRadev/dsf.vim/releases.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
dsf.zip 0.1.0 2019-06-07 7.4 Andrew Radev Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
OSDN.net Logo