Comments (2)
I don't think this is such a good idea. Splitting the code depends on the pattern under the cursor (or on the line), and that could take into account many factors. Heck, in the example you give, I could even check the syntax group. Putting an additional character as the delimiter is going to be very limited. In this case, it works, I guess it might also work for commas, but even that's not going to cut it for more complicated expressions.
For instance, splitting arguments by comma could be done with a gS,
to get this example to work:
foo = bar(:one, :two, :three)
foo = bar(
:one,
:two,
:three
)
I haven't responded to your other comment regarding splitting argument lists, since it's kind of long and I need to gather my brain around it, and I haven't had much time lately. I'll get to that soon. Suffice it to say, it's not that simple, both in terms of interface, implementation, and indentation.
In this particular example, consider options:
foo = bar(:one, :two, three: four, five: six)
Splitting by commas in the same way would result in
foo = bar(
:one,
:two,
three: four,
five: six
)
This is correct, but not idiomatic by far. Different people would want to split this in wildly varying ways. My preference would be:
foo = bar(:one, :two, {
three: four,
five: six
})
Another popular would be:
foo = bar :one, :two,
three: four,
five: six
Just saying "split by commas" results in something that most people would not appreciate. Then there's nesting:
foo = bar(:one, [:two, :three], :four)
Splitting directly by commas would not work in this case. For the record, splitjoin currently takes care of nesting by counting brackets and quotes:
foo 1, 2, { :bar => {:baz => :qux} }
# splits into:
foo 1, 2, {
:bar => {:baz => :qux},
}
#splits further into:
foo 1, 2, {
:bar => {
:baz => :qux,
},
}
(Although I did notice there's a bug with more complicated nesting that it seems I'm going to have to tackle :()
You've discovered one use case in which just providing a single character as a separator works fine, but that's not going to be enough for the majority of cases. Making a separate mapping for it that doesn't break gS
might work, but I honestly feel this kind of functionality is not worth a special mapping. There's going to be way too many edge cases for it to make sense.
from splitjoin.vim.
Thanks for considering this. You are right, splitting by char is very limited and it would be best if gS
could split argument lists out-of-the box.
Edge cases aside, at the moment it doesn't do anything at all for homogeneous lists (arg, arg, arg, arg)
. This is the most common scenario I would like to be able to handle.
The square brackets inside arguments (arg, [ arg, arg], arg)
is pretty contrived, and can be disregarded, don't think I ever saw that in real life.
To counter cases of over-splitting there is a nice J
oin lines shortcut in Vim. Anyway I will close this, I wasn't thinking straight when opened this ticket. It is better to concentrate on automated arguments split.
from splitjoin.vim.
Related Issues (20)
- YAML splitting flow-object with path as value fails to round-trip from joining HOT 3
- Feature request: Add solidity support HOT 1
- Feature request: "black" compatible python line-splitting HOT 3
- Feature request: Add Scala support HOT 3
- Rust: grouped multiline imports do not split correctly HOT 4
- Rust: attributes on grouped imports are not preserved HOT 10
- Adding splitjoins from one langage to another HOT 9
- Unexpected modifications when using `gS` / `gJ` HOT 1
- Python splitting and indentation HOT 2
- Feature request: Splitting LaTeX commands onto newlines HOT 1
- Can't work in visual after changing keymap HOT 2
- Rust: splitting multi-line expression into blocks produces broken code HOT 7
- Go: can't split/join var, const, type declarations inside block (not global scope) HOT 2
- Go: can't split/join var, const declarations with comma-separated one-typed vars, consts HOT 15
- Go: invalid join for var, const, import list HOT 11
- Go: join of struct fields inserts unnecessary spaces HOT 7
- Support for rmardown (rmd) and quarto (qmd) HOT 2
- Go: split of multiline var, const adds brackets in wrong place HOT 2
- vim: gS on dict access dot incorrectly adds space HOT 3
- Add support for R 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 splitjoin.vim.