Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392376
  • 博文数量: 103
  • 博客积分: 3073
  • 博客等级: 中校
  • 技术积分: 1078
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-23 15:04
文章分类

全部博文(103)

文章存档

2012年(13)

2011年(76)

2010年(14)

分类: LINUX

2011-07-24 18:09:33

VIM中“:help count-items”以及“:help count-bytes

To count how often any pattern occurs in the current buffer use the substitute
command and add the 'n' flag to avoid the substitution.  The reported number
of substitutions is the number of items.  Examples: >

        :%s/./&/gn              characters     
        :%s/\i\+/&/gn           words          
        :%s/^//n                lines          
        :%s/the/&/gn            "the" anywhere
        :%s/\/&/gn        "the" as a word

You might want to reset 'hlsearch' or do ":nohlsearch".
Add the 'e' flag if you don't want an error when there are no matches.

An alternative is using |v_g_CTRL-G| in Visual mode.

If you want to find matches in multiple files use |:vimgrep|.


:%s/mystring//gn 



                                                        *count-bytes*
If you want to count bytes, you can use this:

        Visually select the characters (block is also possible)
        Use "y" to yank the characters
        Use the strlen() function: >
                :echo strlen(@")
A line break is counted for one byte.

%s            在整个文件中替换 (:help :s )
\w           匹配一个字 (word) (:help /\w )
g           替换行内所有出现的匹配 (:help :s_flags)
          只报告匹配的数目,并不真正进行替换(:help :s_flags)


vim 显示当前正在编辑的文件名
:f
或者ctrl+g



删除匹配的行
: g/template/d

阅读(5620) | 评论(0) | 转发(0) |
0

上一篇:硬链接与符号链接

下一篇:AMD 处理器

给主人留下些什么吧!~~