[英]Merge the current line with the line above in Vim
I have a pretty long list, like so:我有一个很长的清单,如下所示:
itemOne
itemTwo
,itemThree
itemFour
itemFive
,itemSix
,itemSeven
Each line that starts with a comma needs to be merged with the line above, like so:以逗号开头的每一行都需要与上面的行合并,如下所示:
itemOne
itemTwo,itemThree
itemFour
itemFive,itemSix,itemSeven
How can I do this?我怎样才能做到这一点?
一种有效的方法是使用以下:global
命令:
:g/^,/-j!
你可以这样做:
:%s/\n,/,/g
Try this substitution:试试这个替换:
:%s#\n\ze,##
Explanation:解释:
%s#
begin a substitution on all lines. %s#
开始替换所有行。\\n
match the newline character. \\n
匹配换行符。\\ze,
set the end of the match before the comma so the comma will not be replaced. \\ze,
在逗号之前设置匹配的结尾,这样逗号就不会被替换。##
replace with nothing (to remove the newline character). ##
替换为空(删除换行符)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.