Content-type: text/html
mcedit [-bcCdfhstVx?] file:lineno[:]
mcedit is a link to mc, the main GNU Midnight Commander executable. Executing GNU Midnight Commander under this name requests staring the internal editor and opening the file specified on the command line. The editor is based on the terminal version of cooledit - standalone editor for X Window System.
In addition to that, Shift combined with arrows does text highlighting (if supported by the terminal): Ctrl-Ins copies to the file ~/.cache/mc/mcedit/mcedit.clip, Shift-Ins pastes from ~/.cache/mc/mcedit/mcedit.clip, Shift-Del cuts to ~/.cache/mc/mcedit/mcedit.clip, and Ctrl-Del deletes highlighted text. Mouse highlighting also works on some terminals. To use the standard mouse support provided by your terminal, hold the Shift key. Please note that the mouse support in the terminal doesn't share the clipboard with mcedit.
The completion key (usually Meta-Tab or Escape Tab) completes the word under the cursor using the words used earlier in the file.
To define a macro, press Ctrl-R and then type out the keys you want to be executed. Press Ctrl-R again when finished. The macro can be assigned to any key by pressing that key. The macro is executed when you press the assigned key.
The macro commands are stored in section [editor] it the file ~/.local/share/mc/mc.macros.
External scripts (filters) can be assigned into the any hotkey by edit mc.macros like following:
[editor] ctrl-W=ExecuteScript:25;
This means that ctrl-W hotkey initiates the ExecuteScript(25) action, then editor handler translates this into execution of ~/.local/share/mc/mcedit/macros.d/macro.25.sh shell script.
External scripts are stored in ~/.local/share/mc/mcedit/macros.d/ directory and must be named as macro.XXXX.sh where XXXX is the number from 0 to 9999. See Menu File Edit for more detail about format of the script.
Following macro definition and directives can be used:
Feel free to edit this files, if you need. Here is a sample external script:
l comment selection TMPFILE=`mktemp ${MC_TMPDIR:-/tmp}/up.XXXXXX` || exit 1 echo #if 0 > $TMPFILE cat %b >> $TMPFILE echo #endif >> $TMPFILE cat $TMPFILE > %b rm -f $TMPFILE
If some keys don't work, you can use Learn Keys in the Options menu.
ctags -e --language-force=C -R ./
Meta-Enter show list box to select item under cursor (cusor should stand at end of word).
Meta-Minus where minus is symbol "-" go to previous function in navigation list (like a browser Back).
Meta-Equal where equal is symbol "=" go to next function in navigation list (like a browser Forward).
The file is divided into sections, each beginning with a line with the file command. The sections are normally put into separate files using the include command.
The file command has three arguments. The first argument is a regular expression that is applied to the file name to determine if the following section applies to the file. The second argument is the description of the file type. It is used in cooledit; future versions of mcedit may use it as well. The third optional argument is a regular expression to match the first line of text of the file. The rules in the following section apply if either the file name or the first line of text matches.
A section ends with the start of another 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 text within a C style comment (i.e. between /* and */) has its own color. This is a context, although it has 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 define comment brown 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 { brightcyan keyword } brightcyan keyword '*' green # C comments context /\* \*/ comment # C preprocessor directives context linestart # \n red keyword \\\n brightred # 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] [attributes]
The first context is an exception. It must start with the command
context default [foreground] [background] [attributes]
otherwise mcedit will report an error. The linestart option specifies that delim must start at the beginning of a line. The whole option tells that delim must be a whole word. To specify that a word must begin on the word boundary only on the left side, you can use the wholeleft option, and similarly a word that must end on the word boundary is specified by wholeright.
The set of characters that constitute a whole word can be changed at any point in the file with the wholechars command. 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] [attributes]
Context or keyword strings are interpreted, so that you can include tabs and spaces with the sequences \t and \s. Newlines and backslashes are specified with \n and \\ respectively. Since whitespace is used as a separator, it may not be used as is. Also, \* must be used to specify an asterisk. The * itself is a wildcard that matches any length of characters. For example,
keyword '*' green
colors all C single character constants green. You also could use
keyword "*" green
to color string constants, but the matched string would not be allowed to span across multiple 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 brightgreen
This line defines a keyword containing the backslash and newline characters. Since the keywords are matched before the context delimiters, this keyword prevents the context from ending at the end of the lines that end in a backslash, thus allowing C preprocessor directive to continue across multiple lines.
The possible colors are: black, gray, red, brightred, green, brightgreen, brown, yellow, blue, brightblue, magenta, brightmagenta, cyan, brightcyan, lightgray and white. The special keyword "default" means the terminal's default. Another special keyword "base" means mc's main colors, it is useful as a placeholder if you want to specify attributes without modifying the background color. When 256 colors are available, they can be specified either as color16 to color255, or as rgb000 to rgb555 and gray0 to gray23.
If the syntax file is shared with cooledit, it is possible to specify different colors for mcedit and cooledit by separating them with a slash, e.g.
keyword #include red/Orange
mcedit uses the color before the slash. See cooledit(1) for supported cooledit colors.
Attributes can be any of bold, underline, reverse and blink, appended by a plus sign if more than one are desired.
Comments may be put on a separate line starting with the hash sign (#).
If you are describing case insensitive language you need to use caseinsensitive derective. It should be specified at the begining of syntax file.
Because of the simplicity of the implementation, there are a few intricacies that will not be dealt 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 cannot 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 cannot deal with. Also remember that the aim of syntax highlighting is to make programming less prone to error, not to make code look pretty.
The syntax highlighting can be toggled using Ctrl-s shortcut.
MC_COLOR_TABLE="$MC_COLOR_TABLE:\ editnormal=lightgray,black:\ editbold=yellow,black:\ editmarked=black,cyan"
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/share/mc/mc.ini
/usr/share/mc/mc.lib
/usr/share/mc/syntax/*
~/.config/mc/ini
~/.local/share/mc/mcedit/