junegunn / vim-easy-align

:sunflower: A Vim alignment plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal: remove alignment

thalesmello opened this issue · comments

@junegunn Here's a feature I think could be very useful to this plugin.

vim-surround provides mappings for you to surround text, as well as to delete a surround around some text.

By analogy, the same way vim-easy-align is used to align text, it makes sense for it to also be used to remove text. Let me describe the use case that sparked this idea.

Formatting SQL Query

Suppose you have the following SQL statement

INSERT INTO people(name, surname)
SELECT
    'John'            AS name
    'VeryLongSurname' AS surname

I needed to remove the alignment of the text, turning it into:

INSERT INTO people(name, surname)
SELECT
    'John' AS name
    'VeryLongSurname' AS surname

Reformatting function argument

Another use case I thought would be when formatting arguments in a function.

Suppose you have the following piece of text:

function sayHello(name,      surname,   greeting) {
...

This feature could be used to remove spaces from the commas (remove alignment), so that it is like this:

function sayHello(name, surname, greeting) {
...

Suggestion of implementation

It could be implemented as an option in interactive mode.
We could use CTRL-K to toggle "kill" alignment.
At the same time, it could also preserve the useful default, such as the
preserving the space after the comma.

What do you think?

I think this is just a regex substitution problem: deduplicate consecutive spaces except those at the line start.

Yes, regex will do. Something like s/[^ ]\zs */ /g.