关键命令:

:%s/pattern//gn

参数说明:

% - 指明操作区间,%表示全文本;可以使用1,$或者行区间代替

s – substitute,表示替换

pattern - 要查找的字符串

// - 替代文本应该放在这里,两个斜杠中间没有任何字符表示无替代文本

g – Replace all occurences in the line. Without this argument, replacement occurs only for the first occurence in each line.

n – Report the number of matches, and do not actually substitute. 这是核心功能,同时也说明为什么//之间可以添加任意字符。

一些引申出的应用:

(1) :k,ls/pattern//gn

统计k行到l行出现pattern的次数

(2) :%s/pattern//gn

统计在当前编辑文本出现的次数

(3) cat file|greg –i pattern |wc –l

统计在文件中出现的行数

最新文章

  1. Vue插件开发入门
  2. *HDU3635 并查集
  3. Mysql中字段类型不一致导致索引无效
  4. Learning How To Learn
  5. linux根目录下文件夹概览
  6. Spring MVC 流程图
  7. ABBYY FineReader 12扫描界面介绍
  8. eclipse jetty启动内存溢出
  9. H TML5 之 (4) 小项目一 时钟
  10. 模拟电路"虚短" & "虚断"
  11. SQL Server系统表讲解
  12. Bellman-Ford 求含负权最短路
  13. 9、flask之SQLAlchemy
  14. 让VS2019支持.NET Core WinForms和WPF设计器的临时办法(比微软给出的办法更方便)
  15. Marshal.PtrToStringAnsi中文乱码
  16. Web API 处理机制剖析 --- 拨开迷雾看本质
  17. 剑指offer 二叉搜索树和双向链表
  18. Java设计模式--缺省适配器模式
  19. cudnn升级之后caffe无法训练的问题
  20. python学习之----深网和暗网

热门文章

  1. the blank final field factors may not have been initialized
  2. Python 文件名
  3. ubuntu QT安装以及配置交叉编译环境
  4. 笔记49 在Spittr应用中整合Hibernate
  5. Python全栈开发:RabbitMQ/Redis/Memcache/SQLAlchemy
  6. 1.Struts2快速入门
  7. 引用opencv异常
  8. gitj基础2
  9. Cucumber:启动类配置
  10. vue-cli整合axios的几种方法