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.
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:
#!/bin/sh # 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
#!/bin/sh # 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
The file ~/.cedit/syntax is rescanned on opening of a any new editor file. The file contains rules for highlighting, each of which is given on a separate 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. Following this is a description to be printed on the left of the editor window explaining the file type to the user. A third optional argument is a regular expression to match the first line of text of the file. If either the file name matches, or the first line of text, then those rules will be loaded.
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 C\sProgram\sFile (#include|/\\\*) wholechars abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ # default colors context default keyword whole if 24 keyword whole else 24 keyword whole for 24 keyword whole while 24 keyword whole do 24 keyword whole switch 24 keyword whole case 24 keyword whole static 24 keyword whole extern 24 keyword { 14 keyword } 14 keyword '*' 6 # C comments context /\* \*/ 22 # C preprocessor directives context linestart # \n 18 keyword \\\n 24 # C string constants context " " 6 keyword %d 24 keyword %s 24 keyword %c 24 keyword \\" 24
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 separately 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 separator, 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 '*' 6colours all C single character constants green. You could also have used
keyword "*" 6to 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 24This 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.
The colours themselves are numbered 0 to 26 and are explained below in FURTHER BEHAVIORAL OPTIONS. You can also use any of the named colors specified in /usr/lib/X11/rgb.txt, though only one word versions of them. It is better to stick to the numerical colors to limit use of the color palette.
Comments 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 a rule that would be useful, please email me with your request. However, do not ask for regular expression support, because this is flatly impossible.
A useful hint is to work with as much as possible with the things you can do rather than try to do things that this implementation can't cope with. Also remember that the aim of syntax highlighting is to make programming less prone to error, not to make code look pretty.
MC_COLOR_TABLE="$MC_COLOR_TABLE:editnormal=lightgray,black:editbold=yellow,black:editmarked=black,cyan"
(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 occurrences of say, an open bracket, three comma separated 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 (%d,%d,%d) Enter replace string apples %d oranges %d Enter replacement argument order 3,2
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.
/usr/lib/mc/mc.ini
/usr/lib/mc/mc.lib
$HOME/.mc.ini
$HOME/.cedit/