Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keeping whitespace during alignment #100

Closed
mikelui opened this issue Feb 18, 2017 · 1 comment
Closed

Keeping whitespace during alignment #100

mikelui opened this issue Feb 18, 2017 · 1 comment
Labels

Comments

@mikelui
Copy link

mikelui commented Feb 18, 2017

I'm having trouble with the following example. I'm not sure if there's a feature that I'm missing.

Say I have this text

    auto Foo() -> void;
    auto Bar(const char *str) const -> void;
    auto Baz(unsigned val) const -> void;
    auto Qux() const -> int;
    auto FooBar(unsigned val, unsigned num) -> void;

And I want it to align it on -> and const:

    auto Foo()                              -> void;
    auto Bar(const char *str)         const -> void;
    auto Baz(unsigned val)            const -> void;
    auto Qux()                        const -> int;
    auto FooBar(unsigned val, unsigned num) -> void;

The closest I've gotten is :EasyAlign /\(const ->\|->\)/:

    auto Foo()                                    -> void;
    auto Bar(const char *str)               const -> void;
    auto Baz(unsigned val)                  const -> void;
    auto Qux()                              const -> int;
    auto FooBar(unsigned val, unsigned num)       -> void;

But I don't want the whitespace before the -> on the last line.

Or If I align on the consts I get:

    auto Foo()                              -> void;
    auto Bar(const char *str) const -> void;
    auto Baz(unsigned val)    const -> void;
    auto Qux()                const -> int;
    auto FooBar(unsigned val, unsigned num) -> void;

and then align again on ->

    auto Foo()                              -> void;
    auto Bar(const char *str) const         -> void;
    auto Baz(unsigned val)    const         -> void;
    auto Qux()                const         -> int;
    auto FooBar(unsigned val, unsigned num) -> void;

In the last example, if I right align on const and keep the whitespace, then that solves my problem, but I'm not quite sure how to get there. Any suggestions?

@junegunn
Copy link
Owner

I don't think easy-align supports the behavior you're trying to achieve. You'll have to preprocess or postprocess the output using :s command (e.g. :'<,'>s/ const\( *\)->/\1const ->/) or some vimscript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants