replacing ^M with emacs

Malcolm Kay malcolm.kay at
Sun Oct 29 01:00:55 UTC 2006

On Sat, 28 Oct 2006 12:27 pm, Noah wrote:
> well I am pressing control-J for return not control-M so I
> dont understand your rationale.

There seems to be considerable confusion in this thread between 
keystrokes and the codes they produce.

Most modern keyboards report some form of scan code for each key 
pressed whether or not it is one of the modifier or special 
keys. At this stage there is no connection between the key or
key combination pressed and an ASCII code.

What an application sees in terms of codes depends on the OS and 
anything else that may get in between. We mostly think of keys 
and key combinations as being connected to the the codes seen by
an ordinary console application, but this can vary according to 
the OS.

With a standard setup running X applications with a graphics 
interface are able to see all keys translated to some form of 
symbol code (some sort of a super set of ASCII including codes
for special keys) which can be customised with xmodmap.
Character mode programs under X through some terminal emulation
window will see codes (usually ASCII) as further translated by
that terminal emulator. I find that by default xterm reports ^M
on pressing the "enter/return" key but this can further 
customised through XTerm or .Xdefaults. A basic key is generally
combined with the currently active modifier keys(shift,ctrl,alt,
etc) to produce the code reported to the application. Other keys 
such as function keys might be reported as a sequence of codes.

Utilities and applications may manage codes differently when they 
recognise the source as the keyboard so for example Ctrl-J, 
Ctrl-M and "enter" from the keyboard are all reported by "cat" 
as ^J.


> Jerry McAllister wrote:
> >> Thanks Peter,
> >>
> >> where is the logic here?  What is control-q for and what is
> >> control-j for?  I am trying to figure out how I could have
> >> figured that out.
> >
> > They are ASCII characters.   For example, the ^M you wanted
> > to get rid of is CTRL-M.    There are ASCII tables in
> > various places. A quick search should turn up a few.   The
> > assignment of the characters are ancient and traditional and
> > somewhat weird by how things are currently used, but will
> > probably continue to stay that way.
> >
> > Line-Feed, for example - which is that character that marks
> > the end of a line in text files, means it causes the printer
> > to move the paper up one line - in old line printers and
> > teletypes.  CTRL-M or ^M is a RETURN (also ENTER nowdays)
> > and that caused the print head to return to the beginning of
> > the line.  By the time UNIX came along, it wasn't necessary
> > to use both characters to move the paper and print head
> > because those were virtual.  So, they just used one
> > character - the line feed.   But, MS-DOS and some others
> > continued to use the pair to mean a new line for some reason
> > - maybe the original association with IBM, although they
> > didn't use ASCII, but EBCDIC - another animal.
> >
> > So, look up an ASCII chart with explanations and you can
> > make an educated guess on the meanings.
> >
> > ////jerry
> >
> >> also is there a better page than the one I am using below
> >> to figure all these keystrokes out?
> >>
> >>
> >>
> >> Cheers,
> >>
> >> Noah
> >>
> >> Peter A. Giessel wrote:
> >>> On 2006/10/27 15:20, Noah seems to have typed:
> >>>> this is the best answer.  Hits it right on the head of
> >>>> what I want. What if I want the character to replace the
> >>>> ^M with a new line what do I enter in the replace field?
> >>>
> >>> control-q control-j
> >>
> >> _______________________________________________
> >> freebsd-questions at mailing list
> >>
> >> To unsubscribe, send any mail to
> >> "freebsd-questions-unsubscribe at"
> _______________________________________________
> freebsd-questions at mailing list
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe at"

More information about the freebsd-questions mailing list