vim 查看某字符串出现的次数
2014-05-29 09:58
190 查看
http://blog.chinaunix.net/uid-23577393-id-1751983.html
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/\<the\>/&/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)
n 只报告匹配的数目,并不真正进行替换(:help :s_flags)
vim 显示当前正在编辑的文件名
:f
或者ctrl+g
删除匹配的行
: g/template/d
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/\<the\>/&/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)
n 只报告匹配的数目,并不真正进行替换(:help :s_flags)
vim 显示当前正在编辑的文件名
:f
或者ctrl+g
删除匹配的行
: g/template/d
相关文章推荐
- vim中统计字符串出现的次数
- vim 查找字符串出现的次数
- vim 字符串出现次数统计(词频)
- oracle查看字符串中某个字符出现次数
- vim中字符串出现次数的统计及字符创替换
- Vim 匹配字符串出现次数
- vim 查找统计一个字符串出现次数
- vim匹配字符串出现 次数
- SQL中获取一个长字符串中某个字符串出现次数的简单方法(函数)
- 所谓微软面试题的解答:求一个字符串中连续出现次数最多的子串
- 取某个字符或字符串在另一个字符串中出现的次数的函数
- 所谓微软面试题的解答:求一个字符串中连续出现次数最多的子串
- 求一个字符串中连续出现次数最多的子串
- 从字符串中查找字符出现次数的方法和性能对比
- 用JS得到字符串中出现次数最多的字母
- 从字符串中查找字符出现次数的方法和性能对比
- C#获得1个字符串在另一个字符串里出现的次数的巧妙方法
- 学习笔记一:如何:对某词在字符串中出现的次数进行计数 (LINQ)
- sql语句实现返回某一字符串中出现某一字符的次数
- 用JS得到字符串中出现次数最多的字母