Vim Tips Wiki
(Change to TipImported template + severe manual clean)
(→‎Comments: way to change line endings in Vim (no reason to use emacs!))
Line 30: Line 30:
 
Also I noticed, I cannot even do this: %s,$,\r$, it always adds \n, not \r (on windows). I had to use gnu-EMACS to do this substitution on windows!
 
Also I noticed, I cannot even do this: %s,$,\r$, it always adds \n, not \r (on windows). I had to use gnu-EMACS to do this substitution on windows!
   
  +
:First of all, I have no problems yanking ^M characters. But, to add a ^M to the end of each line, I find this method easiest:
  +
:#<tt>:s;<C-Q><C-M>;;g</tt>
  +
:#<tt>:set ff=dos</tt>
  +
:#<tt>:w</tt>
  +
  +
:You can also use g:
  +
:#<tt>:g;\(^\|[^<C-Q><C-M>]\)$;normal A<C-Q><C-Q><C-Q><C-M></tt>
  +
:#<tt>:w</tt>
  +
:#<tt>:e</tt>
  +
  +
:See [[Change_end-of-line_format_for_dos-mac-unix]] for more details.
 
----
 
----
 
Try ^V^M (two keystrokes).
 
Try ^V^M (two keystrokes).

Revision as of 15:43, 14 November 2007

Tip 791 Printable Monobook Previous Next

created September 15, 2004 · complexity basic · author zzapper · version 5.7


Occasionally when you've pasted into Vim from some other application, you get a pesky visible non-ascii character. You can do a ga command to see what it is, but you might want to search for it or substitute it.

Here's a technique. Place the cursor on the character, then:

yl # yank one character into unnamed buffer
/<C-R>" # pull unnamed buffer contents onto search (that's Control-R)

References

Comments

I tried this on Vim 6.3, can't yank Control-M at all.

I have to do this the regular way: /<C-q>013

Also I noticed, I cannot even do this: %s,$,\r$, it always adds \n, not \r (on windows). I had to use gnu-EMACS to do this substitution on windows!

First of all, I have no problems yanking ^M characters. But, to add a ^M to the end of each line, I find this method easiest:
  1. :s;<C-Q><C-M>;;g
  2. :set ff=dos
  3. :w
You can also use g:
  1. :g;\(^\|[^<C-Q><C-M>]\)$;normal A<C-Q><C-Q><C-Q><C-M>
  2. :w
  3. :e
See Change_end-of-line_format_for_dos-mac-unix for more details.

Try ^V^M (two keystrokes).


xxd comes with vim, I use to create binary files. eg. s,\n,\r,g replace all newlines by carriage returns is possible only thru xxd.


For cleaning up win/dos text files for *nix, there's dos2unix (aka fromdos).