将.0D0添加到Vim中的数字末尾

Cha*_*esF 4 regex vim fortran

我有一个代码,我想从另一种语言翻译成Fortran.代码有一个大编号的矢量V(n)- 以及名为tn的众多变量(其中n是一到四位数字)和当前写为整数的许多实数.为了让Fortran将整数视为双精度,我想将其添加.0D0到每个整数的末尾.

所以如果我有一个像这样的表达式:

V(1000) = t434 * 45/7 + 1296 * t18
Run Code Online (Sandbox Code Playgroud)

我希望Vim把它改成:

V(1000) = t434 * 45.0D0/7.0D0 + 1296.0D0 * t18
Run Code Online (Sandbox Code Playgroud)

我一直在尝试使用负面外观来忽略以t或开头的表达式V(,并向前看或者找到数字的结尾,但我没有运气.有没有人有什么建议?

Tes*_*ler 5

V(1000) = t434 * 45/7 + 1296 * t18
Run Code Online (Sandbox Code Playgroud)

命令:

:%s/\(\(t\|V(\)\d*\)\@<!\(\d\+\)\d\@!/\3.0D0/g
Run Code Online (Sandbox Code Playgroud)

结果:

V(1000) = t434 * 45.0D0/7.0D0 + 1296.0D0 * t18
Run Code Online (Sandbox Code Playgroud)

命令是:

:%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
Run Code Online (Sandbox Code Playgroud)