# [vim, sed and vi] cannot :s/something/\n



## nekoexmachina (Mar 25, 2010)

Hello again, forums.
Got a strange problem with vim:
Some file:

```
some text here
```
Running 
[CMD=":"]%s/ /\n/g[/CMD]
results in:

```
some^@text^@here
```
With vi, problem is (almost) same, the space symbols are just wiped out, e.g.:

```
sometexthere
```
locale, if matters: en_us.utf-8, no changes with c.
vimrc is very simple:

```
set nocp
syntax on
set autoindent "autoindenting
set expandtab "tab to space
set softtabstop=4 "tab = 4 space
set ignorecase "ignore case while searching
set background=dark "dark background
set hlsearch "highlight all fount results
set backup  "backup files
set incsearch "jump to found text while typing
set virtualedit=all
```
and problem is same with empty .vimrc
Problem is same with sed (as vi's), but not with tr & awk.
world was updated 11 days ago, 8-STABLE.
What is happening and how do i fix this?


----------



## richardpl (Mar 25, 2010)

vim is not part of FreeBSD base system.

In vim \n is ^V^M, at least in your situation.


----------



## nekoexmachina (Mar 25, 2010)

Yep, but sed and vi are.


----------



## richardpl (Mar 25, 2010)

nekoexmachina said:
			
		

> yep, but sed and vi are.



pebkac


----------



## nekoexmachina (Mar 25, 2010)

> pebkac


Ok, so, does 
`$ cat file_with_text|sed -e 's/some_text/\n/'`
or, in vi
[CMD=":"]%s/some_text/\n/[/CMD]
works for you?


----------



## jailed (Mar 25, 2010)

```
sed -e 'N;s/\n//
```
edit: sorry it's reverse. \n in substitute not working for me too.


----------



## ckester (Mar 25, 2010)

An escaped newline in the sed command works:


```
$ echo "foo bar zot" | sed 's/ /\
/g'
foo
bar
zot
```


----------



## ckester (Mar 25, 2010)

Using gsed from textproc/gsed allows you to use escape characters in the replacement string.


```
echo "foo bar zot" | gsed 's/ /\n/g'
foo
bar
zot
```

Linux uses GNU sed, FreeBSD does not.  Perhaps that's the source of the confusion.


----------

