Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

:global + Tabularize == awesome #10

Closed
jwhitley opened this Issue · 6 comments

3 participants

@jwhitley

On a lark, I just tried the command below. It didn't work, but I really wish it did.

Sample text:

foo -- bar
1
adsfasdf -- bottle
3
wombat -- baz

Hypothetical command:

:g/\w+ --/Tabularize /--/l1c0r1

Intended result:

foo      --    bar
1
adsfasdf -- bottle
3
wombat   --    baz

Conceptually, the idea is that when used with :global, :Tabularize should only pay attention to the lines matched by global. This would be quite useful for things such as:

  • Aligning N-th column comments through an entire source code file
  • Any "broken block" type of alignment task where visual alignment across similar but non-adjacent lines in a file is desired.

If I get the copious free time and the above is actually possible, I'll turn this into a pull request. Beyond that, the idea seemed useful enough that I'm recording it here in case someone other than me nails it down first.

@godlygeek
Owner

I think that this and #8 are essentially requesting the same feature.

@jwhitley

Agreed, #8 does look like a very similar use case. Sadly, I've not had the bandwidth to dig in myself on this yet (many work and other OSS irons in the fire), but I'll definitely put effort into testing out any solutions that land in the meantime.

@godlygeek
Owner

I'm not entirely convinced that I'll stick with this implementation, but - you can give the gtabularize branch a shot and see how it works for you. It implements a :GTabularize command, which is different from :Tabularize in 3 ways (copied verbatim from my source comments):

  1. If a line in the range does not match the pattern, it will be left unchanged, and not in any way affect the outcome of other lines in the range (at least, normally - but Pipelines can and will still look at non-matching rows unless they are specifically written to be aware of tabular#DoGTabularize() and handle it appropriately).
  2. No automatic range determination - :Tabularize automatically expands a single-line range (or a call with no range) to include all adjacent matching lines. That behavior does not make sense for this command.
  3. If called without a range, it will act on all lines in the buffer (like :global) rather than only a single line
@jwhitley

I just gave it a quick spin for aligning RHS code comments. It works brilliantly:

:'<,'>GTabularize /^[^#]\+/r0l1

I'll continue to play with it over the next few days and see how it goes.

@godlygeek
Owner

:GTabularize has been merged into master.

@godlygeek godlygeek closed this
@svenXY

Hi,

just stumbled upon this gem, which perfectly solves my task

Is there a reason for not adding GTabularize to the docs?

Thanks,
Sven

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.