0

When I open Vim on my laptop and run regex like this:

:%s/foo/\n/g

vim inserts ^@ instead of line breaks.

This problem started happening last week. I'm running Ubuntu 18.04.04. I think the problem might have started after Ubuntu installed updates.

Things I've tried

encoding and fileencoding

I tried setting the encoding and fileencoding to utf-8, and then to latin1, but this made no difference.

:lang

:lang produces "Current language: "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=es_ES.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=es_ES.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=es_ES.UTF-8;LC_NAME=es_ES.UTF-8;LC_ADDRESS=es_ES.UTF-8;LC_ TELEPHONE=es_ES.UTF-8;LC_MEASUREMENT=es_ES.UTF-8;LC_IDENTIFICATION=es_ES.UTF-8"

If I call vim with

LC_ALL=C vim foo

then its makes no difference, the problem still occurs.

Paul Jones
  • 151
  • 6
  • 2
    Related: [Vim - how to replace one new line \n with two \n's](https://unix.stackexchange.com/questions/247329/vim-how-to-replace-one-new-line-n-with-two-ns) – steeldriver Mar 19 '20 at 18:26
  • 2
    Does this answer your question? [Vim - how to replace one new line \n with two \n's](https://unix.stackexchange.com/questions/247329/vim-how-to-replace-one-new-line-n-with-two-ns) – Thomas Dickey Mar 20 '20 at 00:15

1 Answers1

1

\n in vim for replacement does not mean newline, but null.

Use \r instead. E.g.

:%s/foo/\r/g
Paul Jones
  • 151
  • 6