How can I align columns where the largest number or largest row is an alignment indicator?

How to correctly align (and align left?) A block of numbers or text in vim as follows:

from

45 209 25 1 2 4 2 3 34 5 300 5 34 120 34 12 

:

 45 209 25 1 2 4 2 3 34 5 300 5 34 120 34 12 

This means that the largest number or largest row in each column does not move.
In the first column it is 45 + 34, in the second column 209 + 120, in the third column 300 and in the last column 12.

+6
source share
5 answers

With Align and AlignMaps plugins: select with V, then \ anum (AlignMaps comes with alignment). One of the benefits of \ anum is that it also processes decimal points (commas) and scientific notation.

+2
source

Look at the align plugin, it can do it and much more. Great tool in your belt!

Found here

After some serious vimhelp / reading, I found the correct AlignCtrl display ... Visually select a table, for example. using ggVG then do a \Tsp ie <leader>Tsp

Then I get the following:

  45 209 25 1 2 4 2 3 34 5 300 5 34 120 34 12 

From vimhelp:

 \Tsp : use Align to make a table separated by blanks |alignmap-Tsp| (right justified) 
+5
source

You can take a look at the Tabularize plugin. Therefore, if you have something like

 45 209 25 1 2 4 2 3 34 5 300 5 34 120 34 12 

just select these lines in visual mode and type :Tab/ and it will format it as

 45 209 25 1 2 4 2 3 34 5 300 5 34 120 34 12 

Also, it looks like you don't have an equal number of spaces separating the numbers at the moment. Therefore, before using the plugin, replace all several spaces with one space with the following regular expression :

 %s![^ ]\zs \+! !g 
+3
source

With the Align plugin, you can select the lines you want to align and click:

<Leader>Tsp

From Align.txt

  \Tsp : use Align to make a table separated by blanks |alignmap-Tsp| (right justified) 

(Help mentions \ because it is the default leader, but if you changed it to something else, you must adapt accordingly)

Just by trying my installation, I got the following result:

 45 209 25 1 2 4 2 3 34 5 300 5 34 120 34 12 

In my opinion, the Align plugin is wonderful, but "aligning cards" and various commands are not so easy to remember.

+3
source

I think it’s best to eat all a few spaces first with

 :{range}s/ \+/ /g 

And then call Tabularize

 :Tab / /r1 

Or change that r to l .

+2
source

Source: https://habr.com/ru/post/891732/


All Articles