I need replace all ; to \n , but :%s/;/\n/gc
not works
Asked
Active
Viewed 1.1k times
20

guilin 桂林
- 17,050
- 29
- 92
- 146
-
question for a superuser – Drakosha Oct 19 '10 at 06:40
2 Answers
53
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).

Eugene Yarmash
- 142,882
- 41
- 325
- 378
-
13doh! the first thing about vim that i hate. i love vim ... but wow ... this one is evil. – underrun Jul 23 '13 at 14:05
-
Is there any way to change this behaviour? I want \n to be LF and \r to be CR - *always*. – Bell Dec 23 '16 at 03:29
-
Was trying to match multi-line stuff, including newlines, and replace them with matching groups containing newlines. That wasn't working, as I was getting the whole \n vs \r problem. The only way I've found to get around this is to replace \n with some improbable sequence, do whatever regex stuff I was trying to do (using the improbable sequence in place of where I would've used \n), then replace the improbable sequence with \r. – Meower68 Dec 31 '19 at 23:53