gpt4 book ai didi

c++ - 在多行中用相应的元素格式化 C++ 代码

转载 作者:行者123 更新时间:2023-11-30 02:30:34 25 4
gpt4 key购买 nike

我正在寻找一种工具来制作丑陋的方 block

if   ( str == "str" ) decorator["str"] = &Props::goodstr;
else if ( str == "strM" )
decorator["strM"] = &Props::goodstrM;
else if ( str == "strXL" ) decorator["strXL"] = &Props::goodstrXL;
else if ( str == "strXXXL" ) decorator["strXXXL"] = &Props::goodstrXXXL;

在 vim 的可视 block 模式下可以轻松地在多行上编辑的漂亮 block :

if      ( str == "str"     ) decorator["str"    ] = &Props::goodstr    ;
else if ( str == "strM" ) decorator["strM" ] = &Props::goodstrM ;
else if ( str == "strXL" ) decorator["strXL" ] = &Props::goodstrXL ;
else if ( str == "strXXXL" ) decorator["strXXXL"] = &Props::goodstrXXXL;

或者类似的东西。
它不必在 vim 中!我只是将它标记为 vim,因为那是我通常使用的。请推荐其他可以完成这项工作的工具。

最佳答案

我实际上知道有一种工具可以帮助对齐所有“丑陋”的 block 。它叫做Align .你所要做的就是给他你想要对齐的模式。

所以对于上面的代码你可以这样做:

:%normal! ggJ
:%s/;/;\r/g
:%left
:AlignCtrl =Clp1P1IW
:% Align (\|)\|]\|[\|&.\+
:% Align ;

从第 5 个命令可以看出,您需要通过提供模式手动重新组织代码

结果:

if      ( str == "str"     ) decorator [ "str"     ] = &Props::goodstr     ;   
else if ( str == "strM" ) decorator [ "strM" ] = &Props::goodstrM ;
else if ( str == "strXL" ) decorator [ "strXL" ] = &Props::goodstrXL ;
else if ( str == "strXXXL" ) decorator [ "strXXXL" ] = &Props::goodstrXXXL ;

关于c++ - 在多行中用相应的元素格式化 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38465034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com