簡體   English   中英

在 Vim 中將當前行與上面的行合並

[英]Merge the current line with the line above in Vim

我有一個很長的清單,如下所示:

itemOne
itemTwo
,itemThree
itemFour
itemFive
,itemSix
,itemSeven

以逗號開頭的每一行都需要與上面的行合並,如下所示:

itemOne
itemTwo,itemThree
itemFour
itemFive,itemSix,itemSeven

我怎樣才能做到這一點?

一種有效的方法是使用以下:global命令:

:g/^,/-j!

你可以這樣做:

:%s/\n,/,/g

試試這個替換:

:%s#\n\ze,##

解釋:

  • %s#開始替換所有行。
  • \\n匹配換行符。
  • \\ze,在逗號之前設置匹配的結尾,這樣逗號就不會被替換。
  • ##替換為空(刪除換行符)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM