Tuesday, May 24, 2011

Re: vim can't find carriage returns

Thank you John, Frans, and Albie!
your answers were timely, educational, and helped me solve my problem—much appreciated. For the record I am using Unix (Mac OS X). 

I've only been using Vim for a week now, but with every passing day am more and more impressed by its power.

My original problem was that I wanted to delete all the blank lines in my document. Previously, in BBEdit I would search for "\r\r" and replace with "\r", so that's why I was searching for carriage returns in the first place.
But I just discovered a much slicker workaround in Vim: :g/^$/d
Awesome!


On Tue, May 24, 2011 at 12:26 AM, John Beckett <johnb.beckett@gmail.com> wrote:
JP Lew wrote:
> No matter which document I'm editing, whenever I search for a
> carriage return like this:
>
> /\r
>
> I get the following error message:
>
> E486: Pattern not found: \r

Vim removes line endings when a file is read, so there may not
be any CR in the buffer that is displayed. Search for \n to find
what Vim has detected as a line ending.

To convert from one line ending type to another, see:
http://vim.wikia.com/wiki/File_format

For testing, you can enter insert mode and type Ctrl-V Enter (or
Ctrl-Q Enter if you have mapped Ctrl-V to paste). That will
insert a CR displayed as ^M (Ctrl-M = 13 = CR). Searching for \r
will find it.

John

--
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


--
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