Code Monkey home page Code Monkey logo

dsf.vim's Introduction

Note: Special thanks to @faceleg, who seems to have extracted this plugin from my vimfiles before I did. If you'd like a simpler version of this plugin for whatever reason, feel free to use this one.

Usage

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.

More mappings

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

For convenience, the dsnf (the "n" standing for "next") mapping will look for a function call after the cursor to delete:

var result = function_call(foo, bar(baz));
// With the cursor on "foo", pressing dsnf results in:
var result = function_call(foo, baz);

Text objects

The text objects for if and af manipulate function calls with their contents. Given this example:

var result = function_call(one, two);

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

var result = ;

Typing dif ("delete 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.

Multiline

The plugin also works on multiline function calls, for example:

foo = one(
  two
)

foo = two

The insides of the function will be automatically indented using the = operator to compensate for any potential changes in indentation level.

Customization

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 mappings provided by the plugin:

let g:dsf_no_mappings = 1

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

nmap dsnf <Plug>DsfNextDelete
nmap csnf <Plug>DsfNextChange

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, or remove lines to leave them unset.

For additional settings, check the full documentation with :help dsf-settings.

Contributing

Pull requests are welcome, but take a look at CONTRIBUTING.md first for some guidelines.

dsf.vim's People

Contributors

andrewradev avatar dependabot[bot] avatar resolritter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

iq-scm

dsf.vim's Issues

Multi-line parameters support

Hi!

It would be great if this plugin could support manipulating functions that are multiple lines long, for example:

a(
  'b',
  'c',
  'd',
  'e',
  'f'
)

Currently, it looks like dsf doesn't recognize the function because it is multiple lines long. Is this something that is possible to change?

Thanks again!

dsf with the cursor outside the function parenthesis

I just started using this plugin and I really love it! However, one thing that I think it's lacking is the ability call dsf when the cursor is outside of, i.e. on the name of, the function to be removed. I'm thinking of functionality like in targets.vim's, which lets you for instance can call di) outside a pair of parentheses, and Vim will then jump to the first pair of parentheses and delete the text inside them.

I'll illustrate the desired functionality with an example. Say that we have the following text:

baz = bar(foo)

And I want to delete the function surrounding foo using dsf to get this:

baz = foo

To do this I currently need to have my cursor inside the parentheses. I think it would be neat if I could use dsf the same way but with my cursor located for instance at the first character of bar, like this (where ^ is the location of my cursor):

baz = bar(foo)
      ^

yielding this:

baz = foo

For the ambiguous case of nested functions, for instance this:

baz = bar(foo(foz))
          ^

A solution would be to add an alternative mapping, for instance dsF, which would then mean the outer function bar(), which would yield this:

baz = foo(foz)

While dsf deletes the nested function foo(), yielding:

baz = bar(foz)

Would this be possible to add, or is there a simple Vim script that I can add to my .vimrc that would add this functionality?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.