Comments (7)
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.
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.
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.
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.
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.
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.
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)
- Switch.vim pollutes search history HOT 2
- help with a bash switch? HOT 6
- Add case insesitivity HOT 2
- Does not working eruby_tag_type in eruby filetype. HOT 4
- [wiki] Anyone know how to write a substitution for React props? HOT 3
- Invert logical expression, using De Morgan Law HOT 1
- "." repeats always forward, even if the last used command was "SwitchReverse" HOT 2
- Undefined variable: g:switch_builtins and invalid expression error on startup when opening a Ruby file and loading the plugin through NeoBundle HOT 2
- Enable js toggles for typescript, typescript.tsx filetypes HOT 2
- switch#NormalizedCase and word boundaries HOT 3
- increase/decrease number HOT 2
- Switching all the flags at once HOT 2
- Possible to call normal commands in switch definition? HOT 10
- Enable switching booleans anywhere on the line and returning to original cursor position HOT 6
- Introduce a way to set priority/precedence? HOT 9
- Idea: Multiple switch alternatives HOT 3
- Comparison to swapit HOT 2
- can you please add a configuration example for lua HOT 2
- NormalizedCaseWords does not work for capitalized words HOT 2
- Patch to allow reverse action (and count) in lambda substitutions HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from switch.vim.