[英]Vim - Count number of certain character
I'm trying to define a function that does A
if there's an even number of dollar signs (in my buffer), and B
if there's an odd number of dollar signs. 我试图定义做了功能
A
,如果有偶数个美元符号(在我的缓冲区)和B
,如果有一个奇数的美元符号。 However, I'm unsure how to count the number of dollar signs, and then report that number for defining the function. 但是,我不确定如何计算美元符号的数量,然后报告该数字以定义函数。 For instance, entering
例如,进入
:%s/\\$//gn
:%s / \\ $ // GN
will spit out this number on the status line. 将在状态行上吐出这个数字。 But how can one apply the result for defining a function?
但是如何应用结果来定义函数呢?
根据@ DaveNewman的评论,你可以写:
:%s/\$//gn | let i = split(v:statusmsg)[0] | if i % 2 | ... | else | ... | endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.