1MCEDIT(1) GNU Midnight Commander MCEDIT(1)
2
3
4
6 mcedit - Internal file editor of GNU Midnight Commander.
7
9 mcedit [-bcCdfhstVx?] [+lineno] file
10
11 mcedit [-bcCdfhstVx?] file:lineno[:]
12
14 mcedit is a link to mc, the main GNU Midnight Commander executable.
15 Executing GNU Midnight Commander under this name requests staring the
16 internal editor and opening the file specified on the command line.
17 The editor is based on the terminal version of cooledit - standalone
18 editor for X Window System.
19
21 +lineno
22 Go to the line specified by number (do not put a space between
23 the + sign and the number).
24
25 -b Force black and white display.
26
27 -c Force ANSI color mode on terminals that don't seem to have color
28 support.
29
30 -C <keyword>=<FGcolor>,<BGcolor>:<keyword>= ...
31 Specify a different color set. See the Colors section in mc(1)
32 for more information.
33
34 -d Disable mouse support.
35
36 -f Display the compiled-in search path for GNU Midnight Commander
37 data files.
38
39 -t Force using termcap database instead of terminfo. This option
40 is only applicable if GNU Midnight Commander was compiled with
41 S-Lang library with terminfo support.
42
43 -V Display the version of the program.
44
45 -x Force xterm mode. Used when running on xterm-capable terminals
46 (two screen modes, and able to send mouse escape sequences).
47
49 The internal file editor is a full-featured full screen editor. It can
50 edit files up to 64 megabytes. It is possible to edit binary files.
51 The features it presently supports are: block copy, move, delete, cut,
52 paste; key for key undo; pull-down menus; file insertion; macro com‐
53 mands; regular expression search and replace (and our own scanf-printf
54 search and replace); shift-arrow text highlighting (if supported by the
55 terminal); insert-overwrite toggle; word wrap; autoindent; tunable tab
56 size; syntax highlighting for various file types; and an option to pipe
57 text blocks through shell commands like indent and ispell.
58
60 The editor is easy to use and can be used without learning. The
61 pull-down menu is invoked by pressing F9. You can learn other keys
62 from the menu and from the button bar labels.
63
64 In addition to that, Shift combined with arrows does text highlighting
65 (if supported by the terminal): Ctrl-Ins copies to the file
66 ~/.mc/cedit/cooledit.clip, Shift-Ins pastes from
67 ~/.mc/cedit/cooledit.clip, Shift-Del cuts to ~/.mc/cedit/cooledit.clip,
68 and Ctrl-Del deletes highlighted text. Mouse highlighting also works
69 on some terminals. To use the standard mouse support provided by your
70 terminal, hold the Shift key. Please note that the mouse support in
71 the terminal doesn't share the clipboard with mcedit.
72
73 The completion key (usually Meta-Tab or Escape Tab) completes the word
74 under the cursor using the words used earlier in the file.
75
76 To define a macro, press Ctrl-R and then type out the keys you want to
77 be executed. Press Ctrl-R again when finished. You can then assign
78 the macro to any key you like by pressing that key. The macro is exe‐
79 cuted when you press Ctrl-A and then the assigned key. The macro is
80 also executed if you press Meta, Ctrl, or Esc and the assigned key,
81 provided that the key is not used for any other function. The macro
82 commands are stored in the file ~/.mc/cedit/cooledit.macros. Do NOT
83 edit this file if you are going to use macros again in the same editing
84 session, because mcedit caches macro key defines in memory. mcedit now
85 overwrites a macro if a macro with the same key already exists, so you
86 won't have to edit this file. You will also have to restart other run‐
87 ning editors for macros to take effect.
88
89 F19 will format C, C++, Java or HTML code when it is highlighted. An
90 executable file called ~/.mc/cedit/edit.indent.rc will be created for
91 you from the default template. Feel free to edit it if you need.
92
93 C-p will run ispell on a block of text in a similar way. The script
94 file will be called ~/.mc/cedit/edit.spell.rc.
95
96 If some keys don't work, you can use Learn Keys in the Options menu.
97
99 mcedit can be used for navigation through code with tags files created
100 by etags or ctags commands. If there is no TAGS file code navigation
101 will not work. For example, in case of exuberant-ctags for C language
102 command will be:
103
104 ctags -e --language-force=C -R ./
105
106 Meta-Enter shows list box to select item under cursor (cursor should
107 stand at the end of the word).
108
109 Meta-Minus where minus is symbol "-" goes to previous function in navi‐
110 gation list (like browser's Back button).
111
112 Meta-Equal where equal is symbol "=" goes to next function in naviga‐
113 tion list (like browser's Forward button).
114
116 mcedit supports syntax highlighting. This means that keywords and con‐
117 texts (like C comments, string constants, etc) are highlighted in dif‐
118 ferent colors. The following section explains the format of the file
119 ~/.mc/cedit/Syntax. If this file is missing, system-wide
120 /usr/share/mc/syntax/Syntax is used. The file ~/.mc/cedit/Syntax is
121 rescanned on opening of a any new editor file. The file contains rules
122 for highlighting, each of which is given on a separate line, and define
123 which keywords will be highlighted to what color.
124
125 The file is divided into sections, each beginning with a line with the
126 file command. The sections are normally put into separate files using
127 the include command.
128
129 The file command has three arguments. The first argument is a regular
130 expression that is applied to the file name to determine if the follow‐
131 ing section applies to the file. The second argument is the descrip‐
132 tion of the file type. It is used in cooledit; future versions of
133 mcedit may use it as well. The third optional argument is a regular
134 expression to match the first line of text of the file. The rules in
135 the following section apply if either the file name or the first line
136 of text matches.
137
138 A section ends with the start of another section. Each section is
139 divided into contexts, and each context contains rules. A context is a
140 scope within the text that a particular set of rules belongs to. For
141 instance, the text within a C style comment (i.e. between /* and */)
142 has its own color. This is a context, although it has no further rules
143 inside it because there is probably nothing that we want highlighted
144 within a C comment.
145
146 A trivial C programming section might look like this:
147
148 file .\*\\.c C\sProgram\sFile (#include|/\\\*)
149
150 wholechars abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_
151
152 # default colors
153 define comment brown
154 context default
155 keyword whole if yellow
156 keyword whole else yellow
157 keyword whole for yellow
158 keyword whole while yellow
159 keyword whole do yellow
160 keyword whole switch yellow
161 keyword whole case yellow
162 keyword whole static yellow
163 keyword whole extern yellow
164 keyword { brightcyan
165 keyword } brightcyan
166 keyword '*' green
167
168 # C comments
169 context /\* \*/ comment
170
171 # C preprocessor directives
172 context linestart # \n red
173 keyword \\\n brightred
174
175 # C string constants
176 context " " green
177 keyword %d brightgreen
178 keyword %s brightgreen
179 keyword %c brightgreen
180 keyword \\" brightgreen
181
182 Each context starts with a line of the form:
183
184 context [exclusive] [whole|wholeright|wholeleft] [linestart] delim
185 [linestart] delim [foreground] [background]
186
187 The first context is an exception. It must start with the command
188
189 context default [foreground] [background]
190
191 otherwise mcedit will report an error. The linestart option specifies
192 that delim must start at the beginning of a line. The whole option
193 tells that delim must be a whole word. To specify that a word must
194 begin on the word boundary only on the left side, you can use the
195 wholeleft option, and similarly a word that must end on the word bound‐
196 ary is specified by wholeright.
197
198 The set of characters that constitute a whole word can be changed at
199 any point in the file with the wholechars command. The left and right
200 set of characters can be set separately with
201
202 wholechars [left|right] characters
203
204 The exclusive option causes the text between the delimiters to be high‐
205 lighted, but not the delimiters themselves.
206
207 Each rule is a line of the form:
208
209 keyword [whole|wholeright|wholeleft] [linestart] string foreground
210 [background]
211
212 Context or keyword strings are interpreted, so that you can include
213 tabs and spaces with the sequences \t and \s. Newlines and backslashes
214 are specified with \n and \\ respectively. Since whitespace is used as
215 a separator, it may not be used as is. Also, \* must be used to spec‐
216 ify an asterisk. The * itself is a wildcard that matches any length of
217 characters. For example,
218
219 keyword '*' green
220
221 colors all C single character constants green. You also could use
222
223 keyword "*" green
224
225 to color string constants, but the matched string would not be allowed
226 to span across multiple newlines. The wildcard may be used within con‐
227 text delimiters as well, but you cannot have a wildcard as the last or
228 first character.
229
230 Important to note is the line
231
232 keyword \\\n brightgreen
233
234 This line defines a keyword containing the backslash and newline char‐
235 acters. Since the keywords are matched before the context delimiters,
236 this keyword prevents the context from ending at the end of the lines
237 that end in a backslash, thus allowing C preprocessor directive to con‐
238 tinue across multiple lines.
239
240 The possible colors are: black, gray, red, brightred, green, bright‐
241 green, brown, yellow, blue, brightblue, magenta, brightmagenta, cyan,
242 brightcyan, lightgray and white. If the syntax file is shared with
243 cooledit, it is possible to specify different colors for mcedit and
244 cooledit by separating them with a slash, e.g.
245
246 keyword #include red/Orange
247
248 mcedit uses the color before the slash. See cooledit(1) for supported
249 cooledit colors.
250
251 Comments may be put on a separate line starting with the hash sign (#).
252
253 Because of the simplicity of the implementation, there are a few intri‐
254 cacies that will not be dealt with correctly but these are a minor
255 irritation. On the whole, a broad spectrum of quite complicated situa‐
256 tions are handled with these simple rules. It is a good idea to take a
257 look at the syntax file to see some of the nifty tricks you can do with
258 a little imagination. If you cannot get by with the rules I have
259 coded, and you think you have a rule that would be useful, please email
260 me with your request. However, do not ask for regular expression sup‐
261 port, because this is flatly impossible.
262
263 A useful hint is to work with as much as possible with the things you
264 can do rather than try to do things that this implementation cannot
265 deal with. Also remember that the aim of syntax highlighting is to
266 make programming less prone to error, not to make code look pretty.
267
269 The default colors may be changed by appending to the MC_COLOR_TABLE
270 environment variable. Foreground and background colors pairs may be
271 specified for example with:
272
273 MC_COLOR_TABLE="$MC_COLOR_TABLE:\
274 editnormal=lightgray,black:\
275 editbold=yellow,black:\
276 editmarked=black,cyan"
277
279 Most options can now be set from the editors options dialog box. See
280 the Options menu. The following options are defined in ~/.mc/ini and
281 have obvious counterparts in the dialog box. You can modify them to
282 change the editor behavior, by editing the file. Unless specified, a 1
283 sets the option to on, and a 0 sets it to off, as is usual.
284
285 use_internal_edit
286 This option is ignored when invoking mcedit.
287
288 editor_tab_spacing
289 Interpret the tab character as being of this length. Default is
290 8. You should avoid using other than 8 since most other editors
291 and text viewers assume a tab spacing of 8. Use edi‐
292 tor_fake_half_tabs to simulate a smaller tab spacing.
293
294 editor_fill_tabs_with_spaces
295 Never insert a tab character. Rather insert spaces (ascii 32) to
296 fill to the desired tab size.
297
298 editor_return_does_auto_indent
299 Pressing return will tab across to match the indentation of the
300 first line above that has text on it.
301
302 editor_backspace_through_tabs
303 Make a single backspace delete all the space to the left margin
304 if there is no text between the cursor and the left margin.
305
306 editor_fake_half_tabs
307 This will emulate a half tab for those who want to program with
308 a tab spacing of 4, but do not want the tab size changed from 8
309 (so that the code will be formatted the same when displayed by
310 other programs). When editing between text and the left margin,
311 moving and tabbing will be as though a tab space were 4, while
312 actually using spaces and normal tabs for an optimal fill. When
313 editing anywhere else, a normal tab is inserted.
314
315 editor_option_save_mode
316 Possible values 0, 1 and 2. The save mode (see the options menu
317 also) allows you to change the method of saving a file. Quick
318 save (0) saves the file immediately, truncating the disk file to
319 zero length (i.e. erasing it) and then writing the editor con‐
320 tents to the file. This method is fast, but dangerous, since a
321 system error during a file save will leave the file only par‐
322 tially written, possibly rendering the data irretrievable. When
323 saving, the safe save (1) option enables creation of a temporary
324 file into which the file contents are first written. In the
325 event of a problem, the original file is untouched. When the
326 temporary file is successfully written, it is renamed to the
327 name of the original file, thus replacing it. The safest method
328 is create backups (2): a backup file is created before any
329 changes are made. You can specify your own backup file exten‐
330 sion in the dialog. Note that saving twice will replace your
331 backup as well as your original file.
332
333 editor_word_wrap_line_length
334 Line length to wrap at. Default is 72.
335
336 editor_backup_extension
337 Symbol to add to name of backup files. Default is "~".
338
339 editor_line_state
340 Show state line of editor. Currently it shows current line num‐
341 ber (in the future it might show things like folding, break‐
342 points, etc.). M-n toggles this option.
343
344 editor_visible_spaces
345 Toggle "show visible trailing spaces". If editor_visible_spa‐
346 ces=1, they are shown as '.'
347
348 editor_visible_tabs
349 Toggle "show visible tabs". If editor_visible_tabs=1, tabs are
350 shown as '<---->'
351
352 editor_persistent_selections
353 Do not remove block selection after cursor movement.
354
355 editor_cursor_beyond_eol
356 Allow moving cursor beyond the end of line.
357
358 editor_syntax_highlighting
359 enable syntax highlighting.
360
361 editor_edit_confirm_save
362 Show confirmation dialog on save.
363
364 editor_option_typewriter_wrap
365 to be described
366
367 editor_option_auto_para_formatting
368 to be described
369
370 editor_option_save_position
371 save file position on exit.
372
373 source_codepage
374 symbol representation of codepage name for file (i.e. CP1251, ~
375 - default).
376
377 editor_wordcompletion_collect_entire_file
378 Search autocomplete candidates in entire of file or just from
379 begin of file to cursor position (0)
380
381
383 You can use scanf search and replace to search and replace a C format
384 string. First take a look at the sscanf and sprintf man pages to see
385 what a format string is and how it works. Here's an example: suppose
386 that you want to replace all occurrences of an open bracket, three
387 comma separated numbers, and a close bracket, with the word apples, the
388 third number, the word oranges and then the second number. You would
389 fill in the Replace dialog box as follows:
390
391 Enter search string
392 (%d,%d,%d)
393 Enter replace string
394 apples %d oranges %d
395 Enter replacement argument order
396 3,2
397
398 The last line specifies that the third and then the second number are
399 to be used in place of the first and second.
400
401 It is advisable to use this feature with Prompt On Replace on, because
402 a match is thought to be found whenever the number of arguments found
403 matches the number given, which is not always a real match. Scanf also
404 treats whitespace as being elastic. Note that the scanf format %[ is
405 very useful for scanning strings, and whitespace.
406
407 The editor also displays non-us characters (160+). When editing binary
408 files, you should set display bits to 7 bits in the Midnight Commander
409 options menu to keep the spacing clean.
410
412 /usr/share/mc/mc.hlp
413
414 The help file for the program.
415
416 /usr/share/mc/mc.ini
417
418 The default system-wide setup for GNU Midnight Commander, used
419 only if the user's own ~/.mc/ini file is missing.
420
421 /usr/share/mc/mc.lib
422
423 Global settings for the Midnight Commander. Settings in this
424 file affect all users, whether they have ~/.mc/ini or not.
425
426 /usr/share/mc/syntax/*
427
428 The default system-wide syntax files for mcedit, used only if
429 the corresponding user's own ~/.mc/cedit/ file is missing.
430
431 $HOME/.mc/ini
432
433 User's own setup. If this file is present then the setup is
434 loaded from here instead of the system-wide setup file.
435
436 $HOME/.mc/cedit/
437
438 User's own directory where block commands are processed and
439 saved and user's own syntax files are located.
440
442 This program is distributed under the terms of the GNU General Public
443 License as published by the Free Software Foundation. See the built-in
444 help of the Midnight Commander for details on the License and the lack
445 of warranty.
446
448 The latest version of this program can be found at http://midnight-com‐
449 mander.org/.
450
452 cooledit(1), mc(1), gpm(1), terminfo(1), scanf(3).
453
455 Paul Sheer (psheer@obsidian.co.za) is the original author of the Mid‐
456 night Commander's internal editor.
457
459 Bugs should be reported to mc-devel@gnome.org
460
461
462
463MC Version 4.7.0-pre1 August 2009 MCEDIT(1)