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.

2

1 Answer 1

2

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

Use \r instead. E.g.

:%s/foo/\r/g

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.