Tuesday, May 24, 2011

Re: vim can't find carriage returns

Hi JP Lew,
 
Your discovery works great:
:g/^$/d
Depending what you consider a "blank line", you may want:
:g/^\s*$/d
 
If you want to delete runs of blank lines over a threshhold, that can be done as well.  One way to do it is a search-and-replace command like:
:%s/\n\{2,\}/\r\r/
 
I'm not sure why I have to search FOR multiple \n and replace WITH the \r.  That may be a vi-thing, a Vim-thing, or a quirk / detail of my platform (Windows 7, using the prebuilt gVim, using :set ff=unix line endings).  Hmmm, I never thought about that discrepancy before.  The help on it...
:help sub-replace-special
...doesn't really explain the discrepancy.  My speculation is that the discrepancy probably has to do with Vim ingesting a text file as strings, and those lines are stripped of the line endings and are '\0' terminated.  Which would make the discrepancy an implementation detail.
 
There are a lot of powerful editors available.  Vim is more than a powerful editor.  Vim is zen editing.  Vim lets me become one with my keyboard and edit my document; all the while the editor is not a distracting interface but rather is unobtrusive.
 
Happy Vim-ming!
Eljay

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment