85a24e90cf6ccc8cdc4ae26ce9e47bca8c4cc892
[midnight-commander.git] / doc / man / mcedit.1.in
blob85a24e90cf6ccc8cdc4ae26ce9e47bca8c4cc892
1 .TH MCEDIT 1 "%DATE_OF_MAN_PAGE%" "MC Version %DISTR_VERSION%" "GNU Midnight Commander"
2 .SH NAME
3 mcedit \- Internal file editor of GNU Midnight Commander.
4 .SH USAGE
5 .B mcedit
6 [\-bcCdfhstVx?] [+lineno] [file1] [file2] ...
7 .PP
8 .B mcedit
9 [\-bcCdfhstVx?] file1:lineno[:] file2:lineno[:] ...
10 .SH DESCRIPTION
11 .LP
12 mcedit is a link to
13 .BR mc ,
14 the main GNU Midnight Commander executable. Executing GNU Midnight Commander
15 under this name requests staring the internal editor and opening files
16 specified on the command line. The editor is based on the terminal version of
17 .B cooledit
18 \- standalone editor for X Window System.
19 .SH OPTIONS
20 .TP
21 .I "+lineno"
22 Go to the line specified by number (do not put a space between the
23 .I "+"
24 sign and the number). Several line numbers are allowed but the last one will be
25 actual and it will be applied to the first file only.
26 .TP
27 .I "\-b"
28 Force black and white display.
29 .TP
30 .I "\-c"
31 Force ANSI color mode on terminals that don't seem to have color
32 support.
33 .TP
34 .I "\-C <keyword>=<fgcolor>,<bgcolor>,<attributes>:<keyword>= ..."
35 Specify a different color set.  See the
36 .B Colors
37 section in mc(1) for more information.
38 .TP
39 .I "\-d"
40 Disable mouse support.
41 .TP
42 .I "\-f"
43 Display the compiled\-in search path for GNU Midnight Commander data
44 files.
45 .TP
46 .I "\-t"
47 Force using termcap database instead of terminfo.  This option is only
48 applicable if GNU Midnight Commander was compiled with S\-Lang library
49 with terminfo support.
50 .TP
51 .I "\-V"
52 Display the version of the program.
53 .TP
54 .I "\-x"
55 Force xterm mode.  Used when running on xterm\-capable terminals (two
56 screen modes, and able to send mouse escape sequences).
57 .SH FEATURES
58 The internal file editor is a full\-featured windowed editor.  It can
59 edit several files at the same time. Maximim size of each file is 64
60 megabytes. It is possible to edit binary files. The features it presently
61 supports are: block copy, move, delete, cut, paste; key for key undo;
62 pull\-down menus; file insertion; macro commands; regular expression
63 search and replace; shift\-arrow text highlighting (if supported by
64 the terminal); insert\-overwrite toggle; autoindent; tunable tab size;
65 syntax highlighting for various file types; and an option to pipe text
66 blocks through shell commands like indent and ispell.
67 .PP
68 Each file is opened in its own window in full\-screen mode. Window control
69 in mcedit is similar to the window control in other multi\-window program:
70 double click on window title maximizes the window to full\-screen or restores
71 window size and position; left\-click on window title and mouse drag moves
72 the window in editor area; left\-click on low\-right frame corner and mouse drag
73 resizes the window. These actions can be made using "Window" menu.
74 .SH KEYS
75 The editor is easy to use and can be used without learning.  The
76 pull\-down menu is invoked by pressing F9.  You can learn other keys from
77 the menu and from the button bar labels.
78 .PP
79 In addition to that, Shift combined with arrows does text highlighting
80 (if supported by the terminal):
81 .B Ctrl\-Ins
82 copies to the file
83 .BR ~/.cache/mc/mcedit/mcedit.clip ,
84 .B Shift\-Ins
85 pastes from
86 .BR ~/.cache/mc/mcedit/mcedit.clip ,
87 .B Shift\-Del
88 cuts to
89 .BR ~/.cache/mc/mcedit/mcedit.clip ,
90 and
91 .B Ctrl\-Del
92 deletes highlighted text.  Mouse highlighting also works on some
93 terminals.  To use the standard mouse support provided by your terminal,
94 hold the Shift key.  Please note that the mouse support in the terminal
95 doesn't share the clipboard with
96 .BR mcedit .
97 .PP
98 The completion key (usually
99 .B "Meta\-Tab"
101 .BR "Escape Tab" )
102 completes the word under the cursor using the words used in the file.
103 .SH MACRO
105 To define a macro, press
106 .B Ctrl\-R
107 and then type out the keys you want to be executed.  Press
108 .B Ctrl\-R
109 again when finished.  The macro can be assigned to any key by pressing that key.
110 The macro is executed when you press the assigned key.
112 The macro commands are stored in section
113 .B [editor]
114 it the file
115 .BR ~/.local/share/mc/mc.macros .
117 External scripts (filters) can be assigned into the any hotkey by edit
118 .B mc.macros
119 like following:
122 [editor]
123 ctrl\-W=ExecuteScript:25;
126 This means that ctrl\-W hotkey initiates the
127 .I ExecuteScript(25)
128 action, then editor handler translates this into execution of
129 .B ~/.local/share/mc/mcedit/macros.d/macro.25.sh
130 shell script.
132 External scripts are stored in
133 .B ~/.local/share/mc/mcedit/macros.d/
134 directory and must be named as
135 .B macro.XXXX.sh
136 where
137 .B XXXX
138 is the number from 0 to 9999.
140 .B Menu File Edit
141 for more detail about format of the script.
143 Following macro definition and directives can be used:
145 .I #silent
146 If this directive is set, then script starts without interactive subshell.
148 .I %c
149 The cursor column position number.
151 .I %i
152 The indent of blank space, equal the cursor column.
154 .I %y
155 The syntax type of current file.
157 .I %b
158 The block file name.
160 .I %f
161 The current file name.
163 .I %n
164 Only the current file name without extension.
166 .I %x
167 The extension of current file name.
169 .I %d
170 The current directory name.
172 .I %F
173 The current file in the unselected panel.
175 .I %D
176 The directory name of the unselected panel.
178 .I %t
179 The currently tagged files.
181 .I %T
182 The tagged files in the unselected panel.
184 .I %u
186 .I %U
187 Similar to the
188 .I %t
190 .I %T
191 macros, but in addition the files are untagged. You can use this macro
192 only once per menu file entry or extension file entry, because next time
193 there will be no tagged files.
195 .I %s
197 .I %S
198 The selected files: The tagged files if there are any. Otherwise the
199 current file.
201 Feel free to edit this files, if you need.
202 Here is a sample external script:
205 l       comment selection
206         TMPFILE=`mktemp ${MC_TMPDIR:\-/tmp}/up.XXXXXX` || exit 1
207         echo #if 0 > $TMPFILE
208         cat %b >> $TMPFILE
209         echo #endif >> $TMPFILE
210         cat $TMPFILE > %b
211         rm \-f $TMPFILE
214 If some keys don't work, you can use
215 .B Learn Keys
216 in the
217 .B Options
218 menu.
219 .SH CODE NAVIGATION
220 .B mcedit
221 can be used to navigation through code with tags files created by etags
222 or ctags commands. If there is no file TAGS code navigation would not work.
223 In example, in case of exuberant\-ctags for C language command will be:
225 ctags \-e \-\-language\-force=C \-R ./
227 .B Meta\-Enter 
228 show list box to select item under cursor (cusor should stand at end of
229 word).
231 .B Meta\-Minus 
232 where minus is symbol "\-" go to previous function in navigation list (like a browser
233 Back).
235 .B Meta\-Equal
236 where equal is symbol "=" go to next function in navigation list (like a browser
237 Forward).
239 .SH SYNTAX HIGHLIGHTING
240 .B mcedit
241 supports syntax highlighting.  This means that keywords and contexts
242 (like C comments, string constants, etc) are highlighted in different
243 colors.  The following section explains the format of the file
244 .BR ~/.config/mc/mcedit/Syntax .
245 If this file is missing, system\-wide
246 .B %prefix%/share/mc/syntax/Syntax
247 is used.
248 The file
249 .B ~/.config/mc/mcedit/Syntax
250 is rescanned on opening of a any new editor file.  The file contains
251 rules for highlighting, each of which is given on a separate line, and
252 define which keywords will be highlighted to what color.
254 The file is divided into sections, each beginning with a line with the
255 .B file
256 command.  The sections are normally put into separate files using the
257 .B include
258 command.
261 .B file
262 command has three arguments.  The first argument is a regular expression
263 that is applied to the file name to determine if the following section
264 applies to the file.  The second argument is the description of the file
265 type.  It is used in
266 .BR cooledit ;
267 future versions of
268 .B mcedit
269 may use it as well.  The third optional argument is a regular expression
270 to match the first line of text of the file.  The rules in the following
271 section apply if either the file name or the first line of text matches.
273 A section ends with the start of another section.  Each section is
274 divided into contexts, and each context contains rules.  A context is a
275 scope within the text that a particular set of rules belongs to.  For
276 instance, the text within a C style comment (i.e. between
277 .B /*
279 .BR */ )
280 has its own color.  This is a context, although it has no further rules
281 inside it because there is probably nothing that we want highlighted
282 within a C comment.
284 A trivial C programming section might look like this:
287 file .\\*\\\\.c C\\sProgram\\sFile (#include|/\\\\\\*)
289 wholechars abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_
291 # default colors
292 define  comment   brown
293 context default
294   keyword  whole  if       yellow
295   keyword  whole  else     yellow
296   keyword  whole  for      yellow
297   keyword  whole  while    yellow
298   keyword  whole  do       yellow
299   keyword  whole  switch   yellow
300   keyword  whole  case     yellow
301   keyword  whole  static   yellow
302   keyword  whole  extern   yellow
303   keyword         {        brightcyan
304   keyword         }        brightcyan
305   keyword         '*'      green
307 # C comments
308 context /\\* \\*/ comment
310 # C preprocessor directives
311 context linestart # \\n red
312   keyword  \\\\\\n  brightred
314 # C string constants
315 context " " green
316   keyword  %d    brightgreen
317   keyword  %s    brightgreen
318   keyword  %c    brightgreen
319   keyword  \\\\"   brightgreen
322 Each context starts with a line of the form:
324 .B context
325 .RB [ exclusive ]
326 .RB [ whole | wholeright | wholeleft ]
327 .RB [ linestart ]
328 .I delim
329 .RB [ linestart ]
330 .I delim
331 .RI [ foreground ]
332 .RI [ background ]
333 .RI [ attributes ]
335 The first context is an exception.  It must start with the command
337 .B context default
338 .RI [ foreground ]
339 .RI [ background ]
340 .RI [ attributes ]
342 otherwise
343 .B mcedit
344 will report an error.  The
345 .B linestart
346 option specifies that
347 .I delim
348 must start at the beginning of a line.  The
349 .B whole
350 option tells that
351 .I delim
352 must be a whole word.  To specify that a word must begin on the word
353 boundary only on the left side, you can use the
354 .B wholeleft
355 option, and similarly a word that must end on the word boundary is specified by
356 .BR wholeright .
358 The set of characters that constitute a whole word can be changed at any
359 point in the file with the
360 .B wholechars
361 command.  The left and right set of characters can be set separately
362 with
364 .B wholechars
365 .RB [ left | right ]
366 .I characters
369 .B exclusive
370 option causes the text between the delimiters to be highlighted, but not
371 the delimiters themselves.
373 Each rule is a line of the form:
375 .B keyword
376 .RB [ whole | wholeright | wholeleft ]
377 .RB [ linestart ]
378 .I string foreground
379 .RI [ background ]
380 .RI [ attributes ]
382 Context or keyword strings are interpreted, so that you can include tabs
383 and spaces with the sequences \\t and \\s.  Newlines and backslashes are
384 specified with \\n and \\\\ respectively.  Since whitespace is used as a
385 separator, it may not be used as is.  Also, \\* must be used to specify
386 an asterisk.  The * itself is a wildcard that matches any length of
387 characters.  For example,
390   keyword         '*'      green
393 colors all C single character constants green.  You also could use
396   keyword         "*"      green
399 to color string constants, but the matched string would not be allowed
400 to span across multiple newlines.  The wildcard may be used within
401 context delimiters as well, but you cannot have a wildcard as the last
402 or first character.
404 Important to note is the line
407   keyword  \\\\\\n  brightgreen
410 This line defines a keyword containing the backslash and newline
411 characters.  Since the keywords are matched before the context
412 delimiters, this keyword prevents the context from ending at the end of
413 the lines that end in a backslash, thus allowing C preprocessor
414 directive to continue across multiple lines.
416 The possible colors are: black, gray, red, brightred, green,
417 brightgreen, brown, yellow, blue, brightblue, magenta, brightmagenta,
418 cyan, brightcyan, lightgray and white. The special keyword "default" means
419 the terminal's default. Another special keyword "base" means mc's main
420 colors, it is useful as a placeholder if you want to specify attributes
421 without modifying the background color. When 256 colors are available,
422 they can be specified either as color16 to color255, or as rgb000 to rgb555
423 and gray0 to gray23.
425 If the syntax file is shared with
426 .BR cooledit ,
427 it is possible to specify different colors for
428 .B mcedit
430 .B cooledit
431 by separating them with a slash, e.g.
434 keyword  #include  red/Orange
437 .B mcedit
438 uses the color before the slash.  See cooledit(1) for supported
439 .B cooledit
440 colors.
442 Attributes can be any of bold, underline, reverse and blink, appended by a
443 plus sign if more than one are desired.
445 Comments may be put on a separate line starting with the hash sign (#).
447 If you are describing case insensitive language you need to use
448 .B caseinsensitive
449 directive. It should be specified at the beginning of syntax file.
451 Because of the simplicity of the implementation, there are a few
452 intricacies that will not be dealt with correctly but these are a minor
453 irritation.  On the whole, a broad spectrum of quite complicated
454 situations are handled with these simple rules.  It is a good idea to
455 take a look at the syntax file to see some of the nifty tricks you can
456 do with a little imagination.  If you cannot get by with the rules I
457 have coded, and you think you have a rule that would be useful, please
458 email me with your request.  However, do not ask for regular expression
459 support, because this is flatly impossible.
461 A useful hint is to work with as much as possible with the things you
462 can do rather than try to do things that this implementation cannot deal
463 with.  Also remember that the aim of syntax highlighting is to make
464 programming less prone to error, not to make code look pretty.
466 The syntax highlighting can be toggled using Ctrl\-s shortcut.
467 .SH COLORS
468 The default colors may be changed by appending to the
469 .B MC_COLOR_TABLE
470 environment variable.  Foreground and background colors pairs may be
471 specified for example with:
474 MC_COLOR_TABLE="$MC_COLOR_TABLE:\\
475 editnormal=lightgray,black:\\
476 editbold=yellow,black:\\
477 editmarked=black,cyan"
479 .SH OPTIONS
480 Most options can now be set from the editors options dialog box.  See
482 .B Options
483 menu.  The following options are defined in
484 .B ~/.config/mc/ini
485 and have obvious counterparts in the dialog box.  You can modify them to
486 change the editor behavior, by editing the file.  Unless specified, a 1
487 sets the option to on, and a 0 sets it to off, as is usual.
489 .I use_internal_edit
490 This option is ignored when invoking
491 .BR mcedit .
493 .I editor_tab_spacing
494 Interpret the tab character as being of this length.
495 Default is 8. You should avoid using
496 other than 8 since most other editors and text viewers
497 assume a tab spacing of 8. Use
498 .B editor_fake_half_tabs
499 to simulate a smaller tab spacing.
501 .I editor_fill_tabs_with_spaces
502 Never insert a tab space. Rather insert spaces (ascii 20h) to fill to the
503 desired tab size.
505 .I editor_return_does_auto_indent
506 Pressing return will tab across to match the indentation
507 of the first line above that has text on it.
509 .I editor_backspace_through_tabs
510 Make a single backspace delete all the space to the left
511 margin if there is no text between the cursor and the left
512 margin.
514 .I editor_fake_half_tabs
515 This will emulate a half tab for those who want to program
516 with a tab spacing of 4, but do not want the tab size changed
517 from 8 (so that the code will be formatted the same when displayed
518 by other programs). When editing between text and the left
519 margin, moving and tabbing will be as though a tab space were
520 4, while actually using spaces and normal tabs for an optimal fill.
521 When editing anywhere else, a normal tab is inserted.
523 .I editor_option_save_mode
524 Possible values 0, 1 and 2.  The save mode (see the options menu also)
525 allows you to change the method of saving a file.  Quick save (0) saves
526 the file by immediately, truncating the disk file to zero length (i.e.
527 erasing it) and the writing the editor contents to the file.  This
528 method is fast, but dangerous, since a system error during a file save
529 will leave the file only partially written, possibly rendering the data
530 irretrievable.  When saving, the safe save (1) option enables creation
531 of a temporary file into which the file contents are first written.  In
532 the event of an problem, the original file is untouched.  When the
533 temporary file is successfully written, it is renamed to the name of the
534 original file, thus replacing it.  The safest method is create backups
535 (2).  Where a backup file is created before any changes are made.  You
536 can specify your own backup file extension in the dialog.  Note that
537 saving twice will replace your backup as well as your original file.
539 .I editor_word_wrap_line_length
540 line length to wrap. 72 default.
542 .I editor_backup_extension
543 symbol for add extension to name of backup files. Default "~".
545 .I editor_line_state
546 show state line of editor now it show number of file line (in future it
547 can show things like folding, breakpoints, etc.). M\-n toglle this option.
549 .I editor_visible_spaces
550 Toggle show visible trailing spaces (TWS), if editor_visible_spaces=1 TWS
551 showed as '.'
553 .I editor_visible_tabs
554 Toggle show visible tabs, if editor_visible_tabs=1 tabs showed as '<\-\-\-\->'
556 .I editor_persistent_selections
557 Do not remove block selection after moving the cursor.
559 .I editor_cursor_beyond_eol
560 Allow moving cursor beyond the end of line.
562 .I editor_cursor_after_inserted_block
563 Allow moving cursor after inserted block.
565 .I editor_syntax_highlighting
566 enable syntax highlighting.
568 .I editor_edit_confirm_save
569 show confirm dialog on save.
571 .I editor_option_typewriter_wrap
572 to be described
574 .I editor_option_auto_para_formatting
575 to be described
577 .I editor_option_save_position
578 save file position on exit.
580 .I source_codepage
581 symbol representation of codepage name for file (i.e. CP1251, ~ \- default).
583 .I editor_group_undo
584 do UNDO for several of the same type of action (inserting/overwriting,
585 deleting, navigating, typing)
587 .I editor_wordcompletion_collect_entire_file
588 Search autocomplete candidates in entire of file or just from
589 begin of file to cursor position (0)
591 .SH MISCELLANEOUS
592 You can use scanf search and replace to search and replace a C format
593 string.  First take a look at the
594 .B sscanf
596 .B sprintf
597 man pages to see what a format string is and how it works.  Here's an
598 example: suppose that you want to replace all occurrences of an open
599 bracket, three comma separated numbers, and a close bracket, with the
600 word
601 .IR apples ,
602 the third number, the word
603 .I oranges
604 and then the second number.  You would fill in the Replace dialog box as
605 follows:
608 .B Enter search string
609 (%d,%d,%d)
610 .B Enter replace string
611 apples %d oranges %d
612 .B Enter replacement argument order
616 The last line specifies that the third and then the second number are to
617 be used in place of the first and second.
619 It is advisable to use this feature with Prompt On Replace on, because a
620 match is thought to be found whenever the number of arguments found
621 matches the number given, which is not always a real match. Scanf also
622 treats whitespace as being elastic.  Note that the scanf format %[ is
623 very useful for scanning strings, and whitespace.
625 The editor also displays non\-us characters (160+).  When editing
626 binary files, you should set
627 .B display bits
628 to 7 bits in the Midnight Commander options menu to keep the spacing
629 clean.
630 .SH FILES
631 .I %prefix%/share/mc/mc.hlp
633 The help file for the program.
635 .I %prefix%/share/mc/mc.ini
637 The default system\-wide setup for GNU Midnight Commander, used only if
638 the user's own ~/.config/mc/ini file is missing.
640 .I %prefix%/share/mc/mc.lib
642 Global settings for the Midnight Commander.  Settings in this file
643 affect all users, whether they have ~/.config/mc/ini or not.
645 .I %prefix%/share/mc/syntax/*
647 The default system\-wide syntax files for mcedit, used only if
648 the corresponding user's own ~/.local/share/mc/mcedit/ file is missing.
650 .I ~/.config/mc/ini
652 User's own setup.  If this file is present then the setup is loaded
653 from here instead of the system\-wide setup file.
655 .I ~/.local/share/mc/mcedit/
657 User's own directory where block commands are processed and saved and
658 user's own syntax files are located.
659 .SH LICENSE
660 This program is distributed under the terms of the GNU General Public
661 License as published by the Free Software Foundation.  See the built\-in
662 help of the Midnight Commander for details on the License and the lack
663 of warranty.
664 .SH AVAILABILITY
665 The latest version of this program can be found at
666 http://midnight\-commander.org/.
667 .SH SEE ALSO
668 cooledit(1), mc(1), gpm(1), terminfo(1), scanf(3).
669 .SH AUTHORS
670 Paul Sheer (psheer@obsidian.co.za) is the original author of
671 the Midnight Commander's internal editor.
672 .SH BUGS
673 Bugs should be reported to mc\-devel@gnome.org