Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  MCEDIT (1)


mcedit - Full featured terminal text editor for Unix-like systems.


Redefining Keys
Syntax Highlighting
See Also


mcedit [ file [-bcCdfhstVx?]]


Mcedit is a link to mc, the Midnight Commander, forcing it to immediately start its internal editor. The editor is a terminal version of the cooledit standalone X Window editor.


-b Forces black and white display.
-c Force color mode on terminals where mcedit defaults to black and white.
-C <keyword>=<FGcolor>,<BGcolor>:<keyword>= ...
  Used to specify a different color set, where keyword is one of normal, selected, marked, markselect, errors, reverse menu, menusel, menuhot, menuhotsel and gauge. The colors are optional and are one of black, gray, red, brightred, green, brightgreen, brown, yellow, blue, brightblue, magenta, brightmagenta, cyan, brightcyan, lightgray and white. See the Colors section in mc.1 for more information.
-d Disables mouse support.
-f Displays the compiled-in search paths for Midnight Commander files.
-t Used only if the code was compiled with Slang and terminfo: it makes the Midnight Commander use the value of the TERMCAP variable for the terminal information instead of the information on the system wide terminal database
-V Displays the version of the program.
-x Forces xterm mode. Used when running on xterm-capable terminals (two screen modes, and able to send mouse escape sequences).


The internal file editor provides most of the features of common full screen editors. It has an extensible file size limit of sixteen megabytes and edits binary files flawlessly. The features it presently supports are: Block copy, move, delete, cut, paste; key for key undo ; pull-down menus; file insertion; macro definition; regular expression search and replace (and our own scanf-printf search and replace); shift-arrow MSW-MAC text highlighting (for the linux console only); insert-overwrite toggle; word-wrap; a variety of tabbing options; syntax highlighting for various file types; and an option to pipe text blocks through shell commands like indent and ispell.


The editor is very easy to use and requires no tutoring. To see what keys do what, just consult the appropriate pull-down menu. Other keys are: Shift movement keys do text highlighting (Linux console only). Ctrl-Ins copies to the file ~/.cedit/cooledit.clip, and Shift-Ins pastes from ~/.cedit/cooledit.clip. Shift-Del cuts to ~/.cedit/cooledit.clip, and Ctrl-Del deletes highlighted text - all linux console only. The completion key (see mc.1) also does a hard return without an automatic indent. Mouse highlighting also works, and you can override the mouse as usual by holding down the shift key while dragging the mouse to let normal terminal mouse highlighting work.

To define a macro, press Ctrl-R and then type out the key strokes you want to be executed. Press Ctrl-R again when finished. You can then assign the macro to any key you like by pressing that key. The macro is executed when you press Ctrl-A and then the assigned key. The macro is also executed if you press Meta, Ctrl, or Esc and the assigned key, provided that the key is not used for any other function. Once defined, the macro commands go into the file ~/.cedit/cooledit.macros. Do NOT edit this file unless you are not going to use macros again in the same editing session, because Mcedit caches macro key defines in memory. Mcedit now overwrites a macro if a macro with the same key already exists, so you won’t have to edit this file. You will also have to restart other running editors for macros to take effect.

F19 will format C code when it is highlighted. For this to work, make an executable file called .cedit/edit.indent.rc in your home directory containing the following:

# Use $HOME instead of ~ if this doesn’t work.
# You may also have to use a different redirection
# syntax for some machines.
/usr/bin/indent -kr -pcs ~/.cedit/cooledit.block >& /dev/null
cat /dev/null > ~/.cedit/cooledit.error

C-p will run ispell on a block of text in a similar way. The file is .cedit/edit.spell.rc
# Use $HOME instead of ~ if this doesn’t work.
# You may also have to use a different redirection
# syntax for some machines.
/usr/local/bin/ispell ~/.cedit/cooledit.block >& /dev/null
cat /dev/null > ~/.cedit/cooledit.error

Redefining Keys

Keys may be redefined from the Midnight Commander options menu.


As of version 3.6.0, cooledit has syntax highlighting. This means that keywords and contexts (like C comments, string constants, etc) are highlighted in different colours. The following section explains the format of the file ~/.cedit/syntax.

The file ~/.cedit/syntax (~/.cedit/mcsyntax for mcedit) is rescanned on opening of a any new editor file. The file contains rules for highlighting, each of which is given on a seperate line, and define which keywords will be highlighted to what colour. The file is also divided into sections, each beginning with a line with the file command, followed by a regular expression. The regular expression dictates the file name that that set of rules applies to.

A section ends with the start of a new section. Each section is divided into contexts, and each context contains rules. A context is a scope within the text that a particular set of rules belongs to. For instance, the region within a C style comment (i.e. between /* and */) has its own colour. This is a context, although it will have no further rules inside it because there is probably nothing that we want highlighted within a C comment.

A trivial C programming section might look like this:

file .\*\\.c

wholechars abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_

# default colors context default keyword whole if yellow keyword whole else yellow keyword whole for yellow keyword whole while yellow keyword whole do yellow keyword whole switch yellow keyword whole case yellow keyword whole static yellow keyword whole extern yellow keyword { yellow keyword } yellow keyword ’*’ green

# C comments context /\* \*/ brown

# C preprocessor directives context linestart # \n red keyword \\\n yellow

# C string constants context " " green keyword %d brightgreen keyword %s brightgreen keyword %c brightgreen keyword \\" brightgreen

Each context starts with a line of the form:
context [exclusive] [whole|wholeright|wholeleft] [linestart] delim [linestart] delim [foreground] [background]

One exception is the first context. It must start with the command
context default [foreground] [background]
or else cooledit will return an error.

The linestart option dictates that delim must start at the beginning of a line.

The whole option tells that delim must be a whole word. What constitutes a whole word are a set of characters that can be changed at any point in the file with the wholechars command. The wholechars command at the top just sets the set exactly to its default and could therefore have been omitted. To specify that a word must be whole on the left only, you can use the wholeleft option, and similarly on the right. The left and right set of characters can be set seperately with,
wholechars [left|right] characters

The exclusive option causes the text between the delimiters to be highlighted, but not the delimiters themselves.

Each rule is a line of the form:
keyword [whole|wholeright|wholeleft] [linestart] string foreground [background]

Context or keyword strings are interpreted so that you can include tabs and spaces with the sequences \t and \s. Newlines and the \ are specified with \n and \\ respectively. Since whitespace is used as a seperator, it may not be used explicitedly. Also, \* must be used to specify a *. The * itself is a wildcard that matches any length of characters. For example,

  keyword         ’*’      green

colours all C single character constants green. You could also have used
  keyword         "*"      green

to colour string constants, except that the matched string may not cross newlines. The wildcard may be used within context delimiters as well, but you cannot have a wildcard as the last or first character.

Important to note is the line

  keyword  \\\n  yellow

This line defines a keyword containing the \ and newline characters. Because keywords have a higher precedence than context delimiters, this keyword prevents the context from ending at the end of a line if the line ends in a \ thus allowing C preprocessor directive to continue across multiple lines.

Comment may be included on a line of there own and begin with a #.

Because of the simplicity of the implementation, there are a few intricacies that will not be coped with correctly, but these are a minor irritation. On the whole, a broad spectrum of quite complicated situations are handled with these simple rules. It is a good idea to take a look at the syntax file to see some of the nifty tricks you can do with a little imagination. If you can’t get by with the rules I have coded, and you think you have rule that would be useful, please email me with your request.


Most options can now be set from the editors options dialog box. See the Options menu. The following options are defined in .mc.ini, and have obvious correspondences in the dialog box. You can modifiy them to change the editor behaviour, by editing the file. Unless specified, a 1 sets the option to on, and a 0 sets it to off, as is usual.
  This option is ignored when envoking mcedit.
  1 for Emacs keys, and 0 for normal Cooledit keys.
  Interpret the tab character as being of this length. Default is 8. You should avoid using other than 8 since most other editors and text viewers assume a tab spacing of 8. Use editor_fake_half_tabs to simulate a smaller tab spacing.
  Never insert a tab space. Rather insert spaces (ascii 20h) to fill to the desired tab size.
  Pressing return will tab across to match the indentation of the first line above that has text on it.
  Make a single backspace delete all the space to the left margin if there is no text between the cursor and the left margin.
  This will emulate a half tab for those who want to program with a tab spacing of 4, but do not want the tab size changed from 8 (so that the code will be formatted the same when displayed by other programs). When editing between text and the left margin, moving and tabbing will be as though a tab space were 4, while actually using spaces and normal tabs for an optimal fill. When editing anywhere else, a normal tab is inserted.
  (0, 1 or 2.) The save mode (see the options menu also) allows you to change the method of saving a file. Quick save (0) saves the file by immediately, truncating the disk file to zero length (i.e. erasing it) and the writing the editor contents to the file. This method is fast, but dangerous, since a system error during a file save will leave the file only partially written, possibly rendering the data irretrievable. When saving, the safe save (1) option enables creation of a temporary file into which the file contents are first written. In the event of an problem, the original file is untouched. When the temporary file is successfully written, it is renamed to the name of the original file, thus replacing it. The safest method is create backups (2). Where a backup file is created before any changes are made. You can specify your own backup file extension in the dialog. Note that saving twice will replace your backup as well as your original file.


(Scanf search and replace have previously not worked properly. With this release, problems with search and replace have been fixed.)

You can use scanf search and replace to search and replace a C format string. First take a look at the sscanf and sprintf man pages to see what a format string is and how it works. An example is as follows: Suppose you want to replace all occurances of say, an open bracket, three comma seperated numbers, and a close bracket, with the word apples, the third number, the word oranges and then the second number, you would fill in the Replace dialog box as follows:

Enter search string 

Enter replace string 
apples %d oranges %d

Enter replacement argument order 

The last line specifies that the third and then the second number are to be used in place of the first and second.

It is advisable to use this feature with Prompt On Replace on, because a match is thought to be found whenever the number of arguments found matches the number given, which is not always a real match. Scanf also treats whitespace as being elastic. Note that the scanf format %[ is very useful for scanning strings, and whitespace.

The editor also displays non-us characters (160+). When editing binary files, you should set display bits to 7 bits in the Midnight Commander options menu to keep the spacing clean.


The help file for the program.
The default system-wide setup for the Midnight Commander, used only if the user lacks his own ~/.mc.ini file.
Global settings for the Midnight Commander. Settings in this file are global to any Midnight Commander, it is useful to define site-global terminal settings.
User’s own setup. If this file is present then the setup is loaded from here instead of the system-wide startup file.
User’s own temporary directory where block commands are processed and saved.


This program is distributed under the terms of the GNU General Public License as published by the Free Software Foundation. See the built-in help of the Midnight Commander for details on the License and the lack of warranty.


The latest version of this program can be found at in the directory /linux/local and from Europe at in the directory /GNU/mc and at in the directory /lmb/mc. The X Window version can be found at in /pub/Linux/apps/editors/X or at in /pub/unix/cooledit.


cooledit(1), mc(1), gpm(1), terminfo(1), scanf(3).


Paul Sheer ( is the developer of the Midnight Commander’s internal editor.


See the file README.edit in the distribution for more information.
Search for    or go to Top of page |  Section 1 |  Main Index

--> MCEDIT (1) 30 January 1997

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.