I copy pasted cells of a long google spreadsheet into a txt file that is a list of email addresses separated by commas. There are many "blank" cells as well, i.e. a blank space surrounded by commas. So I could have the following list:
[email protected], ,[email protected], , , , [email protected]
In vim, when I try to add separate each address by a new line with this command:
:%s/, /,\n/g
instead of adding a new line after the comman, I get "^@" instead.
I know this has something to do with character sets, but I don't know how to fix it.
Substituting by \n inserts a null character into the text. To get a newline, use \r . When searching for a newline, you'd still use \n , however.
So: Press CTRL-h and the Replace dialog will open. Type \r\n in "Find what" and \\r\\n in "Replace with". Then select search mode Extended (\r, \n, \t, \x..., \0) and click "Replace All".
Starting in normal mode, you can press O to insert a blank line before the current line, or o to insert one after. O and o ("open") also switch to insert mode so you can start typing. To add 10 empty lines below the cursor in normal mode, type 10o<Esc> or to add them above the cursor type 10O<Esc> .
In :s
's replacement field, you need to use \r
not \n
for newline characters.
^@ is the ASCII null character. Vim internally uses \r for newlines (which is ^M), and \n for ASCII null, so in the replacement, if you use \n you're getting those null characters instead of newlines. See also :h sub-replace-special
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With