ziglang / zig.vim

Vim configuration for Zig
MIT License
448 stars 56 forks source link

Something about `zig fmt` #90

Closed wisonye closed 1 year ago

wisonye commented 1 year ago

Love this plugin except for one thing I hope to be solved:

I found that each statement is always a single line after formatted:

1

Is that possible zig fmt can accept the following style result by whatever options? As I think that's important for using vertical split in Laptop screen size to edit 2 source files at the same time:)

2

For example, this is the formatted result after I copy&paste into C file, it looks much better than a long long single line:

Screen Shot 2023-03-04 at 2 55 15 PM

I mean at least have an optional configuration file for zig fmt? (enable or disable part of the format rather than encapsulate all format policies inside and can't change?)

Sorry, I'm new to zig, love to learn more:)

ratfactor commented 1 year ago

@wisonye The answer is to use a trailing comma when you want each element on a separate line.

Without a comma after baz, zig fmt produces this:

.{ foo, bar, baz }

With a comma after baz, zig fmt produces this:

.{
    foo,
    bar,
    baz,
}

I personally think this is very clever and I like it, but you have to know the trick!

wisonye commented 1 year ago

@wisonye The answer is to use a trailing comma when you want each element on a separate line.

Without a comma after baz, zig fmt produces this:

.{ foo, bar, baz }

With a comma after baz, zig fmt produces this:

.{
    foo,
    bar,
    baz,
}

I personally think this is very clever and I like it, but you have to know the trick!

Yup thanks, actually I got the answer already from the Zig discord, just forgot to close this issue, thanks anyway :)