ex (short for extended) is a line editor based on and intended as an improvement to ed, the original Unix editor. Today, it is standardized by POSIX.
Contents
em
em is a super set of ed.
[...] for many years, they had no suitable terminals. They carried on with TTYs and other printing terminals for a long time, and when they did buy screens for everyone, they got Tektronix 4014s. These were large storage tube displays. You can't run a screen editor on a storage-tube display as the picture can't be updated. Thus it had to fall to someone else to pioneer screen editing for Unix, and that was us initially, and we continued to do so for many years. - George Coulouris, of Queen Mary College
Coulouris considered the cryptic commands of ed to be only suitable for "immortals", and thus in February 1976, he enhanced ed (using Ken Thompson's ed source as a starting point) to make em (the "editor for mortals") while acting as a lecturer at Queen Mary College.
George Coulouris of Queen Mary College developed an improved version of ed called em in 1975 that took advantage of video terminals. The em editor was designed for display terminals and was a single-line-at-a-time visual editor. It was one of the first programs on Unix to make heavy use of "raw terminal input mode", in which the running program, rather than the terminal device driver, handled all keystrokes.
"... I spent the summer of 1976 as a visitor to the CS Dept. at Berkeley. I worked in a room full of teletype terminals using the departmental Unix. I had brought 'em' with me on Dectape and installed it there for my own use." — George Coulouris
When Coulouris visited UC Berkeley in the summer of 1976, he brought a DECtape containing em, and showed the editor to various people. Some people considered this new kind of editor to be a potential resource hog. Others, including Bill Joy, were impressed, who was a developer of the text editor ex and its visual mode, vi.
ex
Bill Joy, along with Charles B. Haley, modified em to be less demanding of the processor. The editor became ex and got included in the Berkeley Software Distribution.
Later, ex was enhanced to support full-screen editing via a new, visual mode. The vi text editor is, in fact, ex running in visual mode. The program can be started in either the visual or legacy mode (via command vi vs. ex) and the user can switch between modes at runtime. And, in visual mode, ex commands can be issued at the colon (:) prompt. Even though vi is just a mode of ex, the editor is more commonly called vi today instead of ex. In fact, some programs such as vim provide both vi and ex compatibility modes such that neither vi nor ex are the program per se.
The core ex commands which relate to search and replace are essential to vi. For instance, the ex command :%s/XXX/YYY/g replaces every instance of XXX with YYY, and works in vi too. The % means every line in the file. The 'g' stands for global and means replace every instance on every line (if it was not specified, then only the first instance on each line would be replaced).




