我有一个代码,我想从另一种语言翻译成Fortran.代码有一个大的编号向量 – V(n) – 以及名为tn的众多变量(其中n是一到四位数字)和许多当前写为整数的实数.为了让Fortran将整数视为双精度,我想将.0D0添加到每个整数的末尾.
所以如果我有一个像这样的表达式:
V(1000) = t434 * 45/7 + 1296 * t18
我希望Vim把它改成:
V(1000) = t434 * 45.0D0/7.0D0 + 1296.0D0 * t18
我一直试图用负面看后面来忽略以t或V开头的表达式(并且向前看或者是找到数字的结尾,但是我没有运气.有没有人有任何建议?
解决方法
V(1000) = t434 * 45/7 + 1296 * t18
命令:
:%s/\(\(t\|V(\)\d*\)\@<!\(\d\+\)\d\@!/\3.0D0/g
结果:
V(1000) = t434 * 45.0D0/7.0D0 + 1296.0D0 * t18
命令是:
:%s/ search/replace on every line \(\(t\|V(\)\d*\) t or V(,followed by no or more numbers otherwise it matches 34 in t434 \@<! negative lookbehind to block numbers starting with t or V( \(\d\+\) a run of digits - the bit we care about \d\@! negative lookahead more digits,otherwise it matches 10 in 1000 / replace part of the search/replace \3 match group 3 has the number we care about .0D0 the text you want to add /g global flag,apply many times in a line