How to horizontally align IO << and >> flow operators in Vim?

For example, instead of the following alignment:

 std::cout << "Hello " << "Hello " << "world "; 

I want left aligned operator << , like:

 std::cout << "Hello " << " Hello " << "world "; 

By default, Vim selects the first. It looks like it just increments the indent by one level for a new line.

So, is there a way I can get the second alignment by default?

PS I already tried the Align plugin, but it aligns the area in the table, for example:

 std::cout << "Hello World" << "Hello " << "World" << "World Hello". 

which I find too rare.

+6
source share
2 answers

I use Tabular and it works for me

 :Tabularize /^[^<<]\S* 


Conclusion:

 std::cout << "Hello World" << "Hello " << "world " << "World Hello"; 

Explanation

^ Starting from << to the first << , then the match will begin exactly from the first << .

+4
source

With the Align plugin, a command to align selected lines of text the way you want :<,>Align! l: << :<,>Align! l: << . The first argument is the AlignCtrl command, which tells it the left margin of the first field and treats the rest of the line as a single field. The second argument is a delimiter. The Align Guide explains all available arguments and predefined mappings.

+1
source

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


All Articles