Long align

I have the following code:

a = 123 p.value 0.123 p.long.name = "abc" 

How can I align each line as shown below in vim?

 a = 123 p.value = 0.123 p.long.name = "abc" 

Thanks for any tips.

+6
source share
1 answer

Without plugin:

 :%s/=/ &/ :%s/\%13c\s\+=/= 

The first command will insert spaces before the first equal signs on all lines, the second will remove all spaces before the equal sign in the 13th column. You can also use the Visual block selection and <..... to shift left as many times as necessary.

However, it is really unclean. With the tabular plugin, you simply type :Tab /=/ , and this will do the job, and the range will be calculated automatically (the largest range around the cursor in which all lines match the pattern).

+6
source

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


All Articles