bgold12 wrote:
> I was confused as to why my command :%s/\n\n/\n/ was not 
> getting rid of all blank lines (instead it got rid of all 
> double newlines and replaced them with a single ^@ (null) 
> character; very strange), and then i found 
> http://vim.wikia.com/wiki/VimTip26. According to this
> site:
> 
>> To replace every CR with LF (when searching, \r matches CR, 
>> but when replacing, \r inserts LF):
>>:%s/\r/\r/g
> 
> This cleared up the issue. But I can't understand why \r 
> should mean one thing when searching, but something else when 
> replacing. Is this a bug, or is there a reason for this that 
> makes it worth complicating search/replace commands with 
> inconsistent character meanings?

The text you quote from tip 26 is correct, and it's not a bug. There's a tiny 
bit
more at
 :help /\r
 :help NL-used-for-Nul
 http://vim.wikia.com/wiki/Search_and_replace

I think the reason relates to the confusion surrounding how different operating
systems have represented end-of-line over the years. Vim attempts to handle
different systems as transparently as it can, with the weirdness shown above. 
In the
C language (and others), \r is CR (carriage return = ctrl-m) and \n is LF (line 
feed
= ctrl-j). We press Enter (CR) to insert a newline, but Unix uses an LF to 
indicate
end-of-line (newline), so %s/\r/\r/g makes sense...

John


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to