说我有这种代码:
__device__ float __cosf (float x);
//Calculate the fast approximate cosine of the input argument.
__device__ float __exp10f (float x);
//Calculate the fast approximate base 10 exponential of the input argument.
__device__ float __expf (float x);
//Calculate the fast approximate base e exponential of the input argument.
__device__ float __fadd_rd (float x, float y);
//Add two floating point values in round-down mode.
__device__ float __fadd_rn (float x, float y);
//Add two floating point values in round-to-nearest-even mode.
__device__ float __fadd_ru (float x, float y);
//Add two floating point values in round-up mode.
我如何在vi中交换奇数行和偶数行?
我的输出
__device__ float __cosf (float x);
//Calculate the fast approximate cosine of the input argument.
__device__ float __exp10f (float x);
//Calculate the fast approximate base 10 exponential of the input argument.
__device__ float __expf (float x);
//Calculate the fast approximate base e exponential of the input argument.
__device__ float __fadd_rd (float x, float y);
//Add two floating point values in round-down mode.
__device__ float __fadd_rn (float x, float y);
//Add two floating point values in round-to-nearest-even mode.
__device__ float __fadd_ru (float x, float y);
//Add two floating point values in round-up mode.
我在vi中用一个命令完成了:
:%s/\(__device.*\n\)\(.*$\)/\2^M\1/g
虽然有一个窍门。要输入^M
,请按Ctrl-V,然后按Enter键。
详细说明:
基本上替换vi命令中所有匹配项为:
%s/something/other/g
可以使用任何符号代替斜线。所以
%s,something,other,g
相同。
“某物”是我们要寻找的东西,“其他”是替代物。
在我的情况下,我正在寻找单词“ __device”,后跟任何符号(.*
代表“任何东西”,然后以换行符\n
结尾。
我标记了我想与\( \)
重用的搜索字符串的一部分。
美元代表“行尾”。
然后我只用\2
和\1
将它们放回相反的顺序。
要输入换行符,请按Ctrl-V,然后按Enter。
我希望这能解释。注意,我使用vi代表Vi改进。老派的简单VI可能缺少某些功能。在当今的大多数Unix中,安装软件包“ vim”使其默认不存在时可用。