简体   繁体   中英

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.
  • \\n match the newline character.
  • \\ze, set the end of the match before the comma so the comma will not be replaced.
  • ## replace with nothing (to remove the newline character).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM