Podrška #14549
Zatvorenvim ukloni ^M
100%
Opis
26: Getting rid of ^M - mixing dos and unix
tip karma Rating 2987/1121, Viewed by 151403
Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.
created: March 5, 2001 17:00 complexity: basic
author: scrott@users.sourceforge.net as of Vim: 5.7
If you work in a mixed environment you will often open files that have ^M's in them. An example would be this:
------------------------------------------------------------------
import java.util.Hashtable; ^M
import java.util.Properties; ^Mimport java.io.IOException;
import org.xml.sax.AttributeList; ^M
import org.xml.sax.HandlerBase; ^Mimport org.xml.sax.SAXException;
/**^M * XMLHandler: This class parses the elements contained^M * within a XML message and builds a Hashtable^M
[snip]
------------------------------------------------------------------
Notice that some programs are not consistent in the way they insert the line breaks so you end up with some lines that have both a carrage return and a ^M and some lines that have a ^M and no carrage return (and so blend into one). There are two steps to clean this up.
1. replace all extraneous ^M:
:%s/^M$//g
BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This expression will replace all the ^M's that have carriage returns after them with nothing. (The dollar ties the search to the end of a line)
2. replace all ^M's that need to have carriage returns:
:%s/^M/ /g
Once again: BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This expression will replace all the ^M's that didn't have carriage returns after them with a carriage return.
Voila! Clean file. Map this to something if you do it frequently.
:help ffs - for more info on file formats
thanks to jonathan merz, douglas potts, and benji fisher
Povezani tiketi 1 (0 otvoreno — 1 zatvoren)
Izmjenjeno od Ernad Husremović prije više od 16 godina
- Kategorija postavljeno na vi
- % završeno promijenjeno iz 0 u 100
Izmjenjeno od Ernad Husremović prije više od 16 godina
međutim kdo cygwin vim ovo ne funkcioniše (ctr+V ctrl+M) ne daje željeni rezultat
na kraju sam sa geany tekst editorom ovo ispravio
probao sam na linux-u i ovaj tip tu funkcioniše
Izmjenjeno od Ernad Husremović prije oko 16 godina
- Status promijenjeno iz Novo u Zatvoreno
Izmjenjeno od Ernad Husremović prije više od 15 godina
- Naslov promijenjeno iz vim ^M u vim ukloni ^M