Git Product home page Git Product logo

Comments (7)

AndrewRadev avatar AndrewRadev commented on August 27, 2024

This plugin is useful for limited changes on the current line. The transformation you're talking about is already implemented in a different plugin of mine, splitjoin.

from switch.vim.

firedev avatar firedev commented on August 27, 2024

I want to do that on separate lines. Splitjoin changes these, but also the code inside.

Like this:

map { |m|
...
}

:Switch

map ▐do |m|
...
end

from switch.vim.

firedev avatar firedev commented on August 27, 2024

Can we please re-open this? I am bumping into that again and again when refactoring long lines. Yes, splitjoin does that if you do that upfront, but if you already have lines separated you can't simply change {}. Or if you have lines joined you can't change do end easily.

from switch.vim.

firedev avatar firedev commented on August 27, 2024

Okay, maybe I am using it wrong. How one would go about changing ->{} to lambda do end here?

-> {
  post '/api/v1/inquiries', data
  post '/api/v1/inquiries', data_body
  expect(response.status).to eq 201
}

from switch.vim.

AndrewRadev avatar AndrewRadev commented on August 27, 2024

Sorry for taking a while, I've been a bit busy these days.

Right now, it's impossible to do this with switch.vim, since it only works within the limits of a single line. I can't really imagine how it would be possible to fit this into the plugin, simply in terms of interface. Finding the matching } would be perfectly possible, but it's not really something that I can describe with the existing switch.vim machinery.

However, you could get this example done with Tim Pope's surround.vim. You'd need to add something like this to your ftplugin/ruby.vim file:

let b:surround_{char2nr('d')} = "do\n \r end"

This defines a do/end surrounding bound to the d key, which means you can wrap lines in do-end "brackets", but it also means you can change an existing pair of brackets to it. In your lambda example, simply typing cs{d would "change the surrounding { to do-end", effectively doing what you want to do, except for changing the -> to a lambda. For that one, you could use switch.vim, or maybe just record a macro with the combination. I've been planning to implement macros in switch.vim for a while now (instead of performing a regex substitution, just run a series of vim keys), but let's see.

from switch.vim.

firedev avatar firedev commented on August 27, 2024

Thank you for taking time to explain things.

I am actively using surround, switch and splitjoin. Just wanted to have some streamlined code refactoring workflow. But it didn't occured to me previously that switch is a single-line plugin.

Maybe it is time to look into compiling some sort of 'refactor-ruby.vim' or something. But my knowledge of Vim innards is pretty basic at the moment.

from switch.vim.

AndrewRadev avatar AndrewRadev commented on August 27, 2024

Well, I think the best way to get to know Vimscript is to try to solve your own problem :). That's how I did it, anyway. Vim has a pretty extensive help system, and as long as you follow the tracks, you'll be able to figure out how to use it in no time. Something like LVSTHW would definitely help as well.

from switch.vim.

Related Issues (20)

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.