本文主要是介绍vi中如何删除行末的空格及替换法则,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
删除行尾空格
:%s//s/+$//g
删除行尾空格和回车
%s//(/d/+/s/+/l/+/)/s/+/_s/+$//$1/
简写及意思解释:
item matches equivalent
/d digit [0-9]
/D non-digit [^0-9]
/x hex digit [0-9a-fA-F]
/X non-hex digit [^0-9a-fA-F]
/s white space [ ] (<Tab> and <Space>)
/S non-white characters [^ ] (not <Tab> and <Space>)
/l lowercase alpha [a-z]
/L non-lowercase alpha [^a-z]
/u uppercase alpha [A-Z]
/U non-uppercase alpha [^A-Z]
重复匹配:
pattern match count
/{,4} 0, 1, 2, 3 or 4
/{3,} 3, 4, 5, etc.
/{0,1} 0 or 1, same as /=
/{0,} 0 or more, same as *
/{1,} 1 or more, same as /+
/{3} 3
贪婪匹配和最小匹配
/a./{-}b
This matches "axb" in "axbxb". If this pattern would be used:
/a.*b
It would try to match as many characters as possible with ".*", thus it
matches "axbxb" as a whole.
这篇关于vi中如何删除行末的空格及替换法则的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!