4

Also asking how to apply an ex range to a normal command.

In a file of some 125k lines with a preamble followed by 8 columns of 10 character wide text, the contents of the column are 8 characters of numbers followed by spaces, except that the last column has no trailing space.

If I wanted to wrap it such that each column becomes a row in order, I would set tw=9 (or 8 or 10?) and then use gq to wrap it. I hoped the easiest thing to do would be to go to the first line after the preamble and type something like: :.,$gq

As you know, gq is not an ex mode command. I couldn't find in the help where the ex mode version of a formatting command is, I'd love both an answer to if that does exist what it is, or if it doesn't, and what you'd do to apply the gq normal mode command to everything to the end of the file. Is there something better than type:
200000gq ?

EG file:

These are very nice data points from our experiment.
This was carried out at our big data point lab by e@mail.tld
If you positioned your cursor on the fifth line, what would you
type in vim to turn all of these points into their own line?
       1        10       100      1000     10000    100000   1000000  10000000
10000001  10000010  10000100  10001000  10010000  10100000  11000000  20000000
... 125k lines later
88888881  18888818  18888188  18881888  18818888  18188888  11888888  28888888

Where the desired format would be:

These are very nice data points from our experiment.
This was carried out at our big data point lab by e@mail.tld
If you positioned your cursor on the fifth line, what would you
type in vim to turn all of these points back into columns? [BONUS]
1
10
100
1000
10000
100000
1000000
10000000
1.25M lines of data points; Padding or alignment aren't important now.
  • I did just try :.,$norm gqq but it only does about half of the lines, and I had to repeat this a lot. – dlamblin Oct 22 '15 at 18:17
  • 1
    :.,$!grep -oP '\w+' is probably faster. gqG should work too (but it will take some time...). Bonus : :.,$! fmt – JJoao Oct 22 '15 at 22:09
  • @JJoao fun fact, I'm using gvim 7.4 on Windows 10. – dlamblin Oct 24 '15 at 3:47
  • someone courageous enough to use vim (+1) in windows will surely benefit with install grep, fmt, awk, sort, 😃 – JJoao Oct 24 '15 at 9:06
  • 1
    @JJoao I think I have 3-12 copies of those tools "installed" variously throughout Windows. Github comes with Github's Git Shell that has embedded core utils (and it's own vim 7.4). Gnu on Windows installs a slightly more updated version of the tools. The Vim package installed some somewhere, and the Git installer installed them, and Vim 7.4 with python and perl bindings. The annoying thing so far seems to be the lack of a unified system, and gVim's confusion as to where they are. Trying to set a path doesn't always help. Oh and Visual Studio is some 20GB and includes them somewhere too. – dlamblin Oct 25 '15 at 20:58
2

I set tw=9 as you mentioned. Then I removed the spaces before de "1" in the first row and also left a blank line between the paragraph and the numbers.

These are very nice data points from our experiment.
This was carried out at our big data point lab by e@mail.tld
If you positioned your cursor on the fifth line, what would you
type in vim to turn all of these points into their own line?

1        10       100      1000     10000    100000   1000000  10000000
10000001  10000010  10000100  10001000  10010000  10100000  11000000  20000000
88888881  18888818  18888188  18881888  18818888  18188888  11888888  28888888

Then I put the cursor anywhere on the numbers and typed gqip. This is the result I obtained:

These are very nice data points from our experiment.
This was carried out at our big data point lab by e@mail.tld
If you positioned your cursor on the fifth line, what would you
type in vim to turn all of these points into their own line?

1
10
100
1000
10000
100000
1000000
10000000
10000001
10000010
10000100
10001000
10010000
10100000
11000000
20000000
88888881
18888818
18888188
18881888
18818888
18188888
11888888
28888888
  • Thanks; so, perhaps I'm still not conversant in vim. If I try and get help on gqip I get no results. Help on gq does mention it's an internal formatter possibly falling back on external fmt or the configured equivalent in some cases. Help on ip says its the inner paragraph range, apparently meaning from the previous blank line to the next. I'm guessing this applies gq to that. I suppose I was missing familiarity with text object selections (section 6 of cursor motions) in cusors.txt. I'm supposing the definition of a paragraph can change depending on the current syntax in use? – dlamblin Oct 27 '15 at 23:21
  • @dlamblin see :help paragraph for the precise definition of a paragraph. – Rich Oct 28 '15 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.