【问题标题】:Unable to count the number of matches in Vim无法计算 Vim 中的匹配数
【发布时间】:2009-03-15 01:05:10
【问题描述】:

如何计算 Vim 中的匹配数?

例如,对于文本

<?

【问题讨论】:

    标签: vim count match


    【解决方案1】:
    :%s/<?//ng
    

    :h count-items

    【讨论】:

    • 我收到错误消息“尾随字符”。我也用 ":set report=0" 尝试了代码。
    • 我会再试一次,尾随字符的帮助描述“一个参数已添加到不允许的 Ex 命令。”
    • Hrmm .. 对不起,Masi,不知道你怎么了。我只是在我机器上的 vim 缓冲区中仔细检查了这个,它工作正常。
    • 如果您从网络浏览器复制/粘贴代码,您可能会选择一个尾随换行符 (^M)。尝试手动输入。
    • @Brian:我找到了问题的根源。我服务器上的 Vim 是 6.3 版。当我在 Vim 7.2 上运行该代码时,它运行良好。感谢您的帮助!
    【解决方案2】:

    Count-items 描述了你的追求。

    :%s/<?/whatever/ng
    

    这是替换命令,但 n 标志避免了实际替换。

    【讨论】:

      【解决方案3】:
      :help count-items
      

      在 VIM 6.3 中,您可以这样做:

      :set report=0
      :%s/<?/&/g   # returns the count without substitution
      

      在 VIM 7.2 中,您可以这样做:

      :%s/<?/&/gn   # returns the count without substitution
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多