请给我一些有关Vimgolf问题的建议
https://www.vimgolf.com/challenges/9v006233d72d000000000219
启动文件
#!/bin/bash
a = 5
b = 10
sum = $a + $b
echo $sum
mul = $a * $b
echo $mul
<强>结束文件
#!/bin/bash
a=5
b=10
sum=$((a + b))
echo $sum
mul=$((a * b))
echo $mul
===================================
这个问题中的击键是 26 但我只得到 41。
我使用的方式 我不
:%s/ = /=/g
:%s/$a/$((a/g
:%s/$b/b))/g
知道如何进一步减少击键。请给我一些建议。
https://www.vimgolf.com/challenges/9v006233d72d000000000219
Start file
#!/bin/bash
a = 5
b = 10
sum = $a + $b
echo $sum
mul = $a * $b
echo $mul
End file
#!/bin/bash
a=5
b=10
sum=$((a + b))
echo $sum
mul=$((a * b))
echo $mul
=================================
The keystroke in this problem was 26 but I only get 41.
The way I used it
:%s/ = /=/g
:%s/$a/$((a/g
:%s/$b/b))/g
I don't know how to reduce keystrokes more. Please give me some advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
/g
意思是“在行中的每场比赛中进行替换”。每种模式只有一个匹配项,因此不需要/g
s:您降至36个击键。
参见
:help:s_g
。在这种特定情况下,
$ a + $ b
可以与单个模式匹配,$。*b
,因此您可以将最后两个替换融合到一个单个:,您降至26个击键。
参见
:帮助S/\&amp;
。/g
means "do the substitution on every match in the line". There is only one match for each pattern so the/g
s are not necessary:You are down to 36 keystrokes.
See
:help :s_g
.In this specific case,
$a + $b
can be matched with a single pattern,$.*b
, so you could fuse the two last substitutions into a single one:And you are down to 26 keystrokes.
See
:help s/\&
.