:global + Tabularize == awesome #10

Closed
jwhitley opened this Issue Jul 2, 2012 · 6 comments

Comments

Projects
None yet
3 participants
@jwhitley

jwhitley commented Jul 2, 2012

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

This comment has been minimized.

Show comment
Hide comment
@godlygeek

godlygeek Aug 5, 2012

Owner

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

Owner

godlygeek commented Aug 5, 2012

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

@jwhitley

This comment has been minimized.

Show comment
Hide comment
@jwhitley

jwhitley Aug 5, 2012

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.

jwhitley commented Aug 5, 2012

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

This comment has been minimized.

Show comment
Hide comment
@godlygeek

godlygeek Sep 11, 2012

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
Owner

godlygeek commented Sep 11, 2012

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

This comment has been minimized.

Show comment
Hide comment
@jwhitley

jwhitley Sep 13, 2012

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.

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

This comment has been minimized.

Show comment
Hide comment
@godlygeek

godlygeek Jan 28, 2013

Owner

:GTabularize has been merged into master.

Owner

godlygeek commented Jan 28, 2013

:GTabularize has been merged into master.

@svenXY

This comment has been minimized.

Show comment
Hide comment
@svenXY

svenXY Aug 18, 2014

Hi,

just stumbled upon this gem, which perfectly solves my task

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

Thanks,
Sven

svenXY commented Aug 18, 2014

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