vim can't find carriage returns

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

vim can't find carriage returns

JP Lew
Hi there:
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

It's puzzling because Vim is matching other character classes like \t
and \n without any problems. I know for a fact that my document has
carriage returns in it, because when I open it in another text editor,
like BBEdit for example, the grep search is turning up carriage
returns in all the right places.

Any ideas? Thanks.

--
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
Reply | Threaded
Open this post in threaded view
|

RE: vim can't find carriage returns

JohnBeckett
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Frans-4
In reply to this post by JP Lew
On Mon, 23 May 2011 23:14:26 -0700 (PDT)
JP Lew <[hidden email]> wrote:

> Hi there:
> 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
>
> It's puzzling because Vim is matching other character classes like \t
> and \n without any problems. I know for a fact that my document has
> carriage returns in it, because when I open it in another text editor,
> like BBEdit for example, the grep search is turning up carriage
> returns in all the right places.
>
> Any ideas? Thanks.
>

what does your fileformat say when you are in vim? (:set fileformat)
What OS are you using?

--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Albie Janse van Rensburg
In reply to this post by JP Lew
JP Lew wrote on 24/05/2011 08:14 AM:

> Hi there:
> 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
>
> It's puzzling because Vim is matching other character classes like \t
> and \n without any problems. I know for a fact that my document has
> carriage returns in it, because when I open it in another text editor,
> like BBEdit for example, the grep search is turning up carriage
> returns in all the right places.
>
> Any ideas? Thanks.
>

Are you specifically looking for carriage returns? If you are just
looking for end-of-lines, then the following will serve you better:

/\n

Otherwise, see John Beckitt's sibling post.


--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

JP Lew
In reply to this post by JohnBeckett
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 <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Eljay Love-Jensen
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Frans-4
In reply to this post by JP Lew
On Tue, 24 May 2011 01:17:08 -0700
JP Lew <[hidden email]> wrote:

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

And it is only the first week :D  Boy, you have no idea how good this
will still get!! The real fun starts after you've assimilated the vim
mindset. That usually requires about a month imho. Then the true power
starts to show itself. I suggest grabbing a good cheat sheet off the
net for some ideas once things start to become fluent. Also check out
some of the .vimrc files used by seasoned vimmers. That should provide
some input for getting some of the more obscure, but very useful
features.
 

--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Eljay Love-Jensen
Hi JP Lew,
 
Frans Grotepass>  I suggest grabbing a good cheat sheet of the net...
 
I have found this tutorial / cheat sheet website to be fantastic:
 
Not only great for getting up to speed in Vim, I still refer to it for the Vim commands I only use infrequently.

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
Reply | Threaded
Open this post in threaded view
|

Re: [Bulk] Re: vim can't find carriage returns

Frans-4
On Tue, 24 May 2011 08:43:49 -0500
Eljay Love-Jensen <[hidden email]> wrote:

> Hi JP Lew,
>
> Frans Grotepass>  I suggest grabbing a good cheat sheet of the net...
>
> I have found this tutorial / cheat sheet website to be fantastic:
>
> http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
> Not only great for getting up to speed in Vim, I still refer to it
> for the Vim commands I only use infrequently.
>
> Happy Vim-ming,
> Eljay
>

And once things are up to speed, try
http://www.rayninfo.co.uk/vimtips.html

--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Jean-Rene David-2
In reply to this post by JP Lew
* JP Lew [2011.05.24 04:20]:
> My original problem was that I wanted to delete all the blank lines in my
> document.

By the way, you would have gotten immediate answers if you had asked
that to begin with. As a matter of fact it is a FAQ (12.4 on
http://vimdoc.sourceforge.net/htmldoc/vimfaq.html)

You almost always get inferior answers if you presume what the solution
is instead of stating the problem you want to solve. It never hurts to
say what solution you *tried* but stating the problem let's the more
imaginative members of the list really shine. :-)

My two cents,

--
JR

--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

JP Lew
On May 24, 5:31 am, Eljay Love-Jensen <[hidden email]> wrote:
> 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.

haha, "Zen Editing". I look forward to that "state of no mind". As of
now, it's a bit hard to enter into trance with my nose buried in the
help documentation. Although I must admit that the regular discoveries—
woah, I can do THAT!—are quite ecstatic.

> http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html

What a good idea, wish I had seen this earlier.

On May 24, 7:01 am, Frans Grotepass <[hidden email]> wrote:
> And once things are up to speed, tryhttp://www.rayninfo.co.uk/vimtips.html

You know something is good when, after being together for 22 years,
things are still ever-fresh. When I think about it, none of my other
relationships have passed that test. :)

On May 24, 7:16 am, Jean-Rene David <[hidden email]> wrote:
> By the way, you would have gotten immediate answers if you had asked
> that to begin with. As a matter of fact it is a FAQ (12.4 onhttp://vimdoc.sourceforge.net/htmldoc/vimfaq.html)

Thanks JR for the tip, and for referring me to the FAQ, I never knew
that existed either.
You're right though—as a rule, a general question begets a general
answer, a specific question a specific one. I can say I learned a lot
in the process however. :)
Now it's evident to me how alive and enthused the Vim community is. It
seems the only thing exceeding Vim's might is the fanatic loyalty it
inspires in its users. Thanks all, wish me luck.

-JP

--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Christian Brabandt
In reply to this post by Jean-Rene David-2
Hi Jean-Rene!

On Di, 24 Mai 2011, Jean-Rene David wrote:

> * JP Lew [2011.05.24 04:20]:
> > My original problem was that I wanted to delete all the blank lines in my
> > document.
>
> By the way, you would have gotten immediate answers if you had asked
> that to begin with. As a matter of fact it is a FAQ (12.4 on
> http://vimdoc.sourceforge.net/htmldoc/vimfaq.html)

By the way, that page is outdated. The current version is available at
http://vimhelp.appspot.com/vim_faq.txt.html

regards,
Christian
--
Glückliche Mädgen in der Ehe lieben schon Romane nicht mehr, weil sie
nichts mehr auf sich beziehen können.
                -- Jean Paul

--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Tony Mechelynck
In reply to this post by Eljay Love-Jensen
On 24/05/11 14:31, Eljay Love-Jensen wrote:
[...]
> 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.  [...]

It may be vi-compatible, but it's one of those "Vim quirks" which one
has to know: in Vim, to replace a line break by itself, you use :s/\n/\r
-- i.e., search for \n to find a line break, insert \r to add a line break.

Don't ask me why.


Best regards,
Tony.
--
There once was a member of Mensa
Who was a most excellent fencer.
        The sword that he used
        Was his -- (line is refused,
And has now been removed by the censor).

--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Dave Land
On May 24, 2011, at 1:45 PM, Tony Mechelynck wrote:

> On 24/05/11 14:31, Eljay Love-Jensen wrote:
> [...]
>> 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.  [...]
>
> It may be vi-compatible, but it's one of those "Vim quirks" which one has to know: in Vim, to replace a line break by itself, you use :s/\n/\r -- i.e., search for \n to find a line break, insert \r to add a line break.

And all these years, I've been using

    :s/\n/^M/

Where "^M" is typed "control-v, control-m") Usin

> Don't ask me why.

I can't tell you why "\n" matches newline on the "search" side of the substitute command, but inserts <00> ("null", equivalent to ^@) on the replace side. It is a mystery of life.

Obviously, "\r" means "return", short for "carriage return" but "\n" seems to mean both "newline" and "null" to vim.

Dave

PS: While reading up on this, I discovered something new, at least to me:

Save typing by using \zs and \ze to set the start and end of a pattern.

For example, instead of:

  :s/Copyright 2007 All Rights Reserved/Copyright 2008 All Rights Reserved/

Use:

  :s/Copyright \zs2007\ze All Rights Reserved/2008/

How cool is that?

--
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
Reply | Threaded
Open this post in threaded view
|

Re: vim can't find carriage returns

Tony Mechelynck
On 25/05/11 02:08, Dave Land wrote:
[...]

> PS: While reading up on this, I discovered something new, at least to me:
>
> Save typing by using \zs and \ze to set the start and end of a pattern.
>
> For example, instead of:
>
>    :s/Copyright 2007 All Rights Reserved/Copyright 2008 All Rights Reserved/
>
> Use:
>
>    :s/Copyright \zs2007\ze All Rights Reserved/2008/
>
> How cool is that?
>

Quite cool, and of course, in this particular case you could even do

   :s/Copyright 200\zs7\ze All Rights Reserved/8/

;-)


Best regards,
Tony.
--
Basic, n.:
        A programming language.  Related to certain social diseases in
that those who have it will not admit it in polite company.

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