Remove all white space in a file and replace them with a comma using Vim

前端 未结 4 1943
栀梦
栀梦 2021-01-31 10:12

Anyone has an idea how to remove all white space and replace them with a comma , in a file using Vim ? File input example (words could be everywhere !):

4条回答
  •  难免孤独
    2021-01-31 10:31

    First delete the blank lines:

    :g/^\s*$/d
    

    Then use a substitution (:s///) over each line (%) to replace all (g) continuous whitespace (\s\+) with a comma (,).

     :%s/\s\+/,/g
    

提交回复
热议问题