2

I have a text file of the form:

line one 1 Sun
line two 22 Mon
line three 33 Tue
line four 444 Wed

How can I vertically-align the columns at specific places (say, the 3rd word)? The required output is:

line one   1 Sun
line two   22 Mon
line three 33 Tue
line four  444 Wed

Update: the intention was for a native Vim solution. I am aware of a few plugin-based solutions. See comments below for the chosen solution that worked for me.

ysap
  • 7,357
  • 7
  • 54
  • 112
  • 1
    https://stackoverflow.com/search?q=%5Bvim%5D+align+table – phd Dec 18 '19 at 19:22
  • See [this answer](https://vi.stackexchange.com/a/20670/18609) for a flexible way to do custom alignment on Vim. In your case, for example, you can use `:normal 2W9i ` to insert leading spaces to the third column and then left-flush from there (using visual block mode and the ` – filbranden Dec 18 '19 at 19:50
  • Thanks for the recommended similar question. I used the solution from this answer: https://stackoverflow.com/a/24065725/274579 – ysap Dec 19 '19 at 18:02

1 Answers1

3

What I would do in command mode (not exactly what you asked):

%!column -t
Gilles Quenot
  • 154,891
  • 35
  • 213
  • 206
  • 1
    OP wants to align only on a single column... – filbranden Dec 18 '19 at 19:50
  • 1
    Added disclaimer – Gilles Quenot Dec 18 '19 at 20:07
  • 2
    I believe a simpler version of your answer is `%!column -t` – D. Ben Knoble Dec 18 '19 at 20:36
  • Apparently, `column` is supported by Cygwin bash. However, the `-t` option will determine every word as a separate column, which is not what I intended (see the sample output). Specifically in my actual case, I wanted to "columnize" at an assignment operator (`=`) so I could define that character using the `--output-separator` command option. – ysap Dec 19 '19 at 20:54