Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim replace character to \n

I need replace all ; to \n , but :%s/;/\n/gc not works

like image 807
guilin 桂林 Avatar asked Oct 19 '10 06:10

guilin 桂林


People also ask

How do I find and replace a character in Vim?

The simplest way to perform a search and replace in Vim editor is using the slash and dot method. We can use the slash to search for a word, and then use the dot to replace it. This will highlight the first occurrence of the word “article”, and we can press the Enter key to jump to it.

How do you go to a new line in vi?

Press l to move the cursor right and j to move the cursor down to get the cursor to the S. Then press i to "insert" and hit enter to create a new line. Then hit esc to stop inserting and :wq to save and quit. There are lots of basic vi command lists on the internet that might help.

Does vim add newline?

3.206 Line That's why Vim always adds a newline by default (because, according to POSIX, it should always be there). It is not the only editor doing that. Gedit, the default text editor in GNOME, does the same exact thing.


2 Answers

See http://vim.wikia.com/wiki/Search_and_replace

When searching: \n is newline, \r is CR (carriage return = Ctrl-M = ^M)
When replacing: \r is newline, \n is a null byte (0x00).

like image 93
Eugene Yarmash Avatar answered Oct 22 '22 04:10

Eugene Yarmash


You need to use \r as the replacement instead: :%s/;/\r/gc

like image 35
too much php Avatar answered Oct 22 '22 03:10

too much php