xref: /openbsd/usr.bin/mg/mg.1 (revision fe834a0f)
1.\"	$OpenBSD: mg.1,v 1.139 2024/07/10 05:19:02 jmc Exp $
2.\" This file is in the public domain.
3.\"
4.Dd $Mdocdate: July 10 2024 $
5.Dt MG 1
6.Os
7.Sh NAME
8.Nm mg
9.Nd emacs-like text editor
10.Sh SYNOPSIS
11.Nm mg
12.Op Fl nR
13.Op Fl b Ar file
14.Op Fl f Ar mode
15.Op Fl u Ar file
16.Op + Ns Ar number
17.Op Ar
18.Sh DESCRIPTION
19.Nm
20is intended to be a small, fast, and portable editor for
21people who can't (or don't want to) run emacs for one
22reason or another, or are not familiar with the
23.Xr vi 1
24editor.
25It is compatible with emacs because there shouldn't
26be any reason to learn more editor types than emacs or
27.Xr vi 1 .
28.Pp
29The options are as follows:
30.Bl -tag -width Ds
31.It + Ns Ar number
32Go to the line specified by number (do not insert
33a space between the
34.Sq +
35sign and the number).
36If a negative number is specified, the line number counts
37backwards from the end of the file i.e. +-1 will be the last
38line of the file, +-2 will be second last, and so on.
39.It Fl b Ar file
40Turn on batch mode and execute the
41.Nm
42commands found in the specified
43.Ar file
44and then terminate.
45.It Fl f Ar mode
46Run the
47.Ar mode
48command for all buffers created from
49arguments on the command line, including the
50scratch buffer and all files.
51.It Fl n
52Turn off backup file generation.
53.It Fl R
54Files specified on the command line will be opened read-only.
55.It Fl u Ar file
56Use
57.Ar file
58as the startup file, instead of the default
59.Pa ~/.mg .
60.El
61.Sh WINDOWS AND BUFFERS
62When a file is loaded into
63.Nm ,
64it is stored in a
65.Em buffer .
66This buffer may be displayed on the screen in more than one window.
67At present, windows may only be split horizontally, so each window is
68delineated by a modeline at the bottom.
69If changes are made to a buffer, it will be reflected in all open windows.
70.Pp
71If a file is changed outside
72.Nm
73and its buffer is about to be changed,
74.Nm
75prompts if the change should go ahead (y), not go ahead (n) or if the buffer
76should be reverted (r) to the latest file on disk.
77.Pp
78If a buffer name begins and ends with an asterisk, the buffer is considered
79throwaway; i.e. the user will not be prompted to save changes when
80the buffer is killed.
81.Sh POINT AND MARK
82The current cursor location in
83.Nm
84is called the
85.Em point
86(or
87.Em dot ) .
88It is possible to define a window-specific region of text by setting a second
89location, called the
90.Em mark .
91The
92.Em region
93is the text between point and mark inclusive.
94Deleting the character at the mark position leaves
95the mark at the point of deletion.
96.Pp
97Note: The point and mark are window-specific in
98.Nm ,
99not buffer-specific, as in other emacs flavours.
100.Sh BACKUP FILES
101Backup files have a
102.Sq ~
103character appended to the file name and
104are created in the current working directory by default.
105Whether to create backup files or not can be toggled with the
106.Ic make-backup-files
107command.
108The backup file location can either be in the current
109working directory, or all backups can be moved to a
110.Pa ~/.mg.d
111directory where files retain their path name to retain uniqueness.
112Use the
113.Ic backup-to-home-directory
114command to alternate between these two locations.
115Further, if any application creates backup files in
116.Pa /tmp ,
117these can be left with the
118.Ic leave-tmpdir-backups
119command.
120.Sh TAGS
121.Nm
122supports tag files created by
123.Xr ctags 1 ,
124allowing the user to quickly locate various object definitions.
125Note though that emacs uses etags, not ctags.
126.Sh CSCOPE
127.Nm
128supports navigating source code using cscope.
129However,
130.Nm
131requires cscope and cscope-indexer executables to be present in
132.Ev PATH
133for it to work.
134.Sh DEFAULT KEY BINDINGS
135Normal editing commands are very similar to GNU Emacs.
136In the following examples, C-x means Control-x, and M-x means Meta-x,
137where the Meta key may be either a special key on the keyboard
138or the ALT key; otherwise ESC followed by the key X works as well.
139.Pp
140.Bl -tag -width xxxxxxxxxxxx -offset indent -compact
141.It C-SPC
142set-mark-command
143.It C-a
144beginning-of-line
145.It C-b
146backward-char
147.It C-c s c
148cscope-find-functions-calling-this-function
149.It C-c s d
150cscope-find-global-definition
151.It C-c s e
152cscope-find-egrep-pattern
153.It C-c s f
154cscope-find-this-file
155.It C-c s i
156cscope-find-files-including-file
157.It C-c s n
158cscope-next-symbol
159.It C-c s p
160cscope-prev-symbol
161.It C-c s s
162cscope-find-this-symbol
163.It C-c s t
164cscope-find-this-text-string
165.It C-d
166delete-char
167.It C-e
168end-of-line
169.It C-f
170forward-char
171.It C-g
172keyboard-quit
173.It C-h C-h
174help-help
175.It C-h a
176apropos
177.It C-h b
178describe-bindings
179.It C-h c
180describe-key-briefly
181.It C-j
182newline-and-indent
183.It C-k
184kill-line
185.It C-l
186recenter
187.It RET
188newline
189.It C-n
190next-line
191.It C-o
192open-line
193.It C-p
194previous-line
195.It C-q
196quoted-insert
197.It C-r
198isearch-backward
199.It C-s
200isearch-forward
201.It C-t
202transpose-chars
203.It C-u
204universal-argument
205.It C-v
206scroll-up
207.It C-w
208kill-region
209.It C-x C-b
210list-buffers
211.It C-x C-c
212save-buffers-kill-emacs
213.It C-x C-f
214find-file
215.It C-x C-j
216dired-jump
217.It C-x C-g
218keyboard-quit
219.It C-x C-l
220downcase-region
221.It C-x C-o
222delete-blank-lines
223.It C-x C-q
224toggle-read-only
225.It C-x C-r
226find-file-read-only
227.It C-x C-s
228save-buffer
229.It C-x C-u
230upcase-region
231.It C-x C-v
232find-alternate-file
233.It C-x C-w
234write-file
235.It C-x C-x
236exchange-point-and-mark
237.It C-x (
238start-kbd-macro
239.It C-x \&)
240end-kbd-macro
241.It C-x 0
242delete-window
243.It C-x 1
244delete-other-windows
245.It C-x 2
246split-window-vertically
247.It C-x 4 C-f
248find-file-other-window
249.It C-x 4 C-g
250keyboard-quit
251.It C-x 4 b
252switch-to-buffer-other-window
253.It C-x 4 f
254find-file-other-window
255.It C-x =
256what-cursor-position
257.It C-x ^
258enlarge-window
259.It C-x `
260next-error
261.It C-x b
262switch-to-buffer
263.It C-x d
264dired
265.It C-x e
266call-last-kbd-macro
267.It C-x f
268set-fill-column
269.It C-x g
270goto-line
271.It C-x h
272mark-whole-buffer
273.It C-x i
274insert-file
275.It C-x k
276kill-buffer
277.It C-x n
278other-window
279.It C-x o
280other-window
281.It C-x p
282previous-window
283.It C-x s
284save-some-buffers
285.It C-x u
286undo
287.It C-y
288yank
289.It C-z
290suspend-emacs
291.It M-C-v
292scroll-other-window
293.It M-SPC
294just-one-space
295.It M-!
296shell-command
297.It M-.
298find-tag
299.It M-*
300pop-tag-mark
301.It M-%
302query-replace
303.It M-<
304beginning-of-buffer
305.It M->
306end-of-buffer
307.It M-\e
308delete-horizontal-space
309.It M-^
310join-line
311.It M-b
312backward-word
313.It M-c
314capitalize-word
315.It M-d
316kill-word
317.It M-f
318forward-word
319.It M-h
320mark-paragraph
321.It M-l
322downcase-word
323.It M-m
324back-to-indentation
325.It M-q
326fill-paragraph
327.It M-r
328search-backward
329.It M-s
330search-forward
331.It M-t
332transpose-words
333.It M-u
334upcase-word
335.It M-v
336scroll-down
337.It M-w
338copy-region-as-kill
339.It M-x
340execute-extended-command
341.It M-z
342zap-to-char
343.It M-{
344backward-paragraph
345.It M-|
346shell-command-on-region
347.It M-}
348forward-paragraph
349.It M-~
350not-modified
351.It M-DEL
352backward-kill-word
353.It C-_
354undo
355.It )
356blink-and-insert
357.It DEL
358delete-backward-char
359.El
360.Pp
361For a complete description of
362.Nm
363commands, see
364.Sx MG COMMANDS .
365To see the active keybindings at any time, type
366.Dq M-x describe-bindings .
367.Sh MG COMMANDS
368Commands are invoked by
369.Dq M-x ,
370or by binding to a key.
371Many commands take an optional numerical parameter,
372.Va n .
373This parameter is set either by
374M-<n> (where
375.Va n
376is the numerical argument) before the command, or by
377one or more invocations of the universal argument, usually bound to C-u.
378When invoked in this manner, the value of the numeric parameter to
379be passed is displayed in the minibuffer before the M-x.
380One common use of the parameter is in mode toggles (e.g.\&
381make-backup-files).
382If no parameter is supplied, the mode is toggled to its
383alternate state.
384If a positive parameter is supplied, the mode is forced to on.
385Otherwise, it is forced to off.
386.\"
387.Bl -tag -width xxxxx
388.It Ic apropos
389Help Apropos.
390Prompt the user for a string, open the *help* buffer,
391and list all
392.Nm
393commands that contain that string.
394.It Ic audible-bell
395Toggle the audible system bell.
396.It Ic auto-execute
397Register an auto-execute hook; that is, specify a filename pattern
398(conforming to the shell's filename globbing rules) and an associated
399function to execute when a file matching the specified pattern
400is read into a buffer.
401.It Ic auto-fill-mode
402Toggle auto-fill mode (sometimes called mail-mode) in the current buffer,
403where text inserted past the fill column is automatically wrapped
404to a new line.
405Can be set globally with
406.Ic set-default-mode .
407.It Ic auto-indent-mode
408Toggle indent mode in the current buffer,
409where indentation is preserved after a newline.
410Can be set globally with
411.Ic set-default-mode .
412.It Ic back-to-indentation
413Move the dot to the first non-whitespace character on the current line.
414.It Ic backup-to-home-directory
415Save backup copies to a
416.Pa ~/.mg.d
417directory instead of working directory.
418Requires
419.Ic make-backup-files
420to be on.
421.It Ic backward-char
422Move cursor backwards one character.
423.It Ic backward-kill-word
424Kill text backwards by
425.Va n
426words.
427.It Ic backward-paragraph
428Move cursor backwards
429.Va n
430paragraphs.
431Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>.
432.It Ic backward-word
433Move cursor backwards by the specified number of words.
434.It Ic beginning-of-buffer
435Move cursor to the top of the buffer.
436If set, keep mark's position, otherwise set at current position.
437A numeric argument
438.Va n
439will move n/10th of the way from the top.
440.It Ic beginning-of-line
441Move cursor to the beginning of the line.
442.It Ic blink-and-insert
443Self-insert a character, then search backwards and blink its
444matching delimiter.
445For delimiters other than
446parenthesis, brackets, and braces, the character itself
447is used as its own match.
448Can be used in the startup file with the
449.Ic global-set-key
450command.
451.It Ic bsmap-mode
452Toggle bsmap mode, where DEL and C-h are swapped.
453.It Ic c-mode
454Toggle a KNF-compliant mode for editing C program files.
455.It Ic call-last-kbd-macro
456Invoke the keyboard macro.
457.It Ic capitalize-word
458Capitalize
459.Va n
460words; i.e. convert the first character of the word to
461upper case, and subsequent letters to lower case.
462.It Ic cd
463Change the global working directory.
464See also
465.Ic global-wd-mode .
466.It Ic column-number-mode
467Toggle whether the column number is displayed in the modeline.
468.It Ic copy-region-as-kill
469Copy all of the characters in the region to the kill buffer,
470clearing the mark afterwards.
471This is a bit like a
472.Ic kill-region
473followed by a
474.Ic yank .
475.It Ic count-matches
476Count the number of lines matching the supplied regular expression.
477.It Ic count-non-matches
478Count the number of lines not matching the supplied regular expression.
479.It Ic cscope-find-this-symbol
480List the matches for the given symbol.
481.It Ic cscope-find-global-definition
482List global definitions for the given literal.
483.It Ic cscope-find-called-functions
484List functions called from the given function.
485.It Ic cscope-find-functions-calling-this-function
486List functions calling the given function.
487.It Ic cscope-find-this-text-string
488List locations matching the given text string.
489.It Ic cscope-find-egrep-pattern
490List locations matching the given extended regular expression pattern.
491.It Ic cscope-find-this-file
492List filenames matching the given filename.
493.It Ic cscope-find-files-including-file
494List files that #include the given filename.
495.It Ic cscope-next-symbol
496Navigate to the next match.
497.It Ic cscope-prev-symbol
498Navigate to the previous match.
499.It Ic cscope-next-file
500Navigate to the next file.
501.It Ic cscope-prev-file
502Navigate to the previous file.
503.It Ic cscope-create-list-of-files-to-index
504Create cscope's List and Index in the given directory.
505.It Ic define-key
506Prompts the user for a named keymap (mode),
507a key, and an
508.Nm
509command, then creates a keybinding in the appropriate
510map.
511.It Ic delete-backward-char
512Delete backwards
513.Va n
514characters.
515Like
516.Ic delete-char ,
517this actually does a kill if presented
518with an argument.
519.It Ic delete-blank-lines
520Delete blank lines around dot.
521If dot is sitting on a blank line, this command
522deletes all the blank lines above and below the current line.
523Otherwise, it deletes all of the blank lines after the current line.
524.It Ic delete-char
525Delete
526.Va n
527characters forward.
528If any argument is present, it kills rather than deletes,
529saving the result in the kill buffer.
530.It Ic delete-horizontal-space
531Delete any whitespace around the dot.
532.It Ic delete-leading-space
533Delete leading whitespace on the current line.
534.It Ic delete-trailing-space
535Delete trailing whitespace on the current line.
536.It Ic delete-matching-lines
537Delete all lines after dot that contain a string matching
538the supplied regular expression.
539.It Ic delete-non-matching-lines
540Delete all lines after dot that don't contain a string matching
541the supplied regular expression.
542.It Ic delete-other-windows
543Make the current window the only window visible on the screen.
544.It Ic delete-window
545Delete current window.
546.It Ic describe-bindings
547List all global and local keybindings, putting the result in
548the *help* buffer.
549.It Ic describe-key-briefly
550Read a key from the keyboard, and look it up in the keymap.
551Display the name of the function currently bound to the key.
552.It Ic diff-buffer-with-file
553View the differences between buffer and its associated file.
554.It Ic digit-argument
555Process a numerical argument for keyboard-invoked functions.
556.It Ic dired-jump
557Open a dired buffer containing the current buffer's directory location.
558.It Ic downcase-region
559Set all characters in the region to lower case.
560.It Ic downcase-word
561Set characters to lower case, starting at the dot, and ending
562.Va n
563words away.
564.It Ic emacs-version
565Return an
566.Nm
567version string.
568.It Ic end-kbd-macro
569Stop defining a keyboard macro.
570.It Ic end-of-buffer
571Move cursor to the end of the buffer.
572If set, keep mark's position, otherwise set at current position.
573A numeric argument
574.Va n
575will move n/10th of the way from the end.
576.It Ic end-of-line
577Move cursor to the end of the line.
578.It Ic enlarge-window
579Enlarge the current window by shrinking either the window above
580or below it.
581.It Ic eval-current-buffer
582Evaluate the current buffer as a series of
583.Nm
584commands.
585Useful for testing
586.Nm
587startup files.
588.It Ic eval-expression
589Get one line from the user, and run it.
590Useful for testing expressions in
591.Nm
592startup files.
593.It Ic exchange-point-and-mark
594Swap the values of "dot" and "mark" in the current window.
595Return an error if no mark is set.
596.It Ic execute-extended-command
597Invoke an extended command; i.e. M-x.
598Call the message line routine to read in the command name and apply
599autocompletion to it.
600When it comes back, look the name up in the symbol table and run the
601command if it is found, passing arguments as necessary.
602Print an error if there is anything wrong.
603.It Ic fill-paragraph
604Justify a paragraph, wrapping text at the current fill column.
605.It Ic find-file
606Select a file for editing.
607First check if the file can be found
608in another buffer; if it is there, just switch to that buffer.
609If the file cannot be found, create a new buffer, read in the
610file from disk, and switch to the new buffer.
611.It Ic find-file-read-only
612Same as
613.Ic find-file ,
614except the new buffer is set to read-only.
615.It Ic find-alternate-file
616Replace the current file with an alternate one.
617Semantics for finding the replacement file are the same as
618.Ic find-file ,
619except the current buffer is killed before the switch.
620If the kill fails, or is aborted, revert to the original file.
621.It Ic find-file-other-window
622Opens the specified file in a second buffer.
623Splits the current window if necessary.
624.It Ic find-tag
625Jump to definition of tag at dot.
626.It Ic forward-char
627Move cursor forwards (or backwards, if
628.Va n
629is negative)
630.Va n
631characters.
632Returns an error if the end of buffer is reached.
633.It Ic forward-paragraph
634Move forward
635.Va n
636paragraphs.
637Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>.
638.It Ic forward-word
639Move the cursor forward by the specified number of words.
640.It Ic global-set-key
641Bind a key in the global (fundamental) key map.
642.It Ic global-unset-key
643Unbind a key from the global (fundamental) key map; i.e. set it to 'rescan'.
644.It Ic global-wd-mode
645Toggle global working-directory mode.
646When enabled,
647.Nm
648defaults to opening files (and executing commands like
649.Ic compile
650and
651.Ic grep )
652relative to the global working directory.
653When disabled, a working directory is set for each buffer.
654.It Ic goto-line
655Go to a specific line.
656If an argument is present, then
657it is the line number, else prompt for a line number to use.
658.It Ic help-help
659Prompts for one of (a)propos, (b)indings, des(c)ribe key briefly.
660.It Ic insert
661Insert a string, mainly for use from macros.
662.It Ic insert-buffer
663Insert the contents of another buffer at dot.
664.It Ic insert-file
665Insert a file into the current buffer at dot.
666.It Ic insert-with-wrap
667Insert the bound character with word wrap.
668Check to see if we're past the fill column, and if so,
669justify this line.
670.It Ic isearch-backward
671Use incremental searching, initially in the reverse direction.
672isearch ignores any explicit arguments.
673If invoked during macro definition or evaluation, the non-incremental
674.Ic search-backward
675is invoked instead.
676.It Ic isearch-forward
677Use incremental searching, initially in the forward direction.
678isearch ignores any explicit arguments.
679If invoked during macro definition or evaluation, the non-incremental
680.Ic search-forward
681is invoked instead.
682.It Ic join-line
683Join the current line to the previous.
684If called with an argument,
685join the next line to the current one.
686.It Ic just-one-space
687Delete any whitespace around dot, then insert a space.
688.It Ic keyboard-quit
689Abort the current action.
690.It Ic kill-buffer
691Dispose of a buffer, by name.
692If the buffer name does not start and end with an asterisk,
693prompt the user if the buffer
694has been changed.
695.It Ic kill-line
696Kill line.
697If called without an argument, it kills from dot to the end
698of the line, unless it is at the end of the line, when it kills the
699newline.
700If called with an argument of 0, it kills from the start of the
701line to dot.
702If called with a positive argument, it kills from dot
703forward over that number of newlines.
704If called with a negative argument
705it kills any text before dot on the current line, then it kills back
706abs(n) lines.
707.It Ic kill-paragraph
708Delete
709.Va n
710paragraphs starting with the current one.
711.It Ic kill-region
712Kill the currently defined region.
713.It Ic kill-word
714Delete forward
715.Va n
716words.
717.It Ic leave-tmpdir-backups
718Modifies the behaviour of
719.Ic backup-to-home-directory .
720Backup files that would normally reside in
721.Pa /tmp
722are left there and not moved to the
723.Pa ~/.mg.d
724directory.
725.It Ic line-number-mode
726Toggle whether the line number is displayed in the modeline.
727.It Ic list-buffers
728Display the list of available buffers.
729The first column in the output indicates which buffer is active with a '>'
730character.
731The second column indicates which buffers are modified.
732The third column indicates which buffers are read-only.
733The remaining columns are self-explanatory.
734.It Ic load
735Prompt the user for a filename, and then execute commands
736from that file.
737.It Ic local-set-key
738Bind a key mapping in the local (topmost) mode.
739.It Ic local-unset-key
740Unbind a key mapping in the local (topmost) mode.
741.It Ic make-backup-files
742Toggle generation of backup files.
743Enabled by default.
744.It Ic make-directory
745Prompt the user for a path or directory name which is then created.
746.It Ic mark-paragraph
747Mark
748.Va n
749paragraphs.
750.It Ic mark-whole-buffer
751Marks whole buffer as a region by putting dot at the beginning and mark
752at the end of buffer.
753.It Ic meta-key-mode
754When disabled, the meta key can be used to insert extended-ascii (8-bit)
755characters.
756When enabled, the meta key acts as usual.
757.It Ic negative-argument
758Process a negative argument for keyboard-invoked functions.
759.It Ic newline
760Insert a newline into the current buffer.
761.It Ic newline-and-indent
762Insert a newline, then enough tabs and spaces to duplicate the indentation
763of the previous line, respecting
764.Ic no-tab-mode
765and the buffer tab width.
766.It Ic next-line
767Move forward
768.Va n
769lines.
770.It Ic no-tab-mode
771Toggle notab mode.
772In this mode, spaces are inserted rather than tabs.
773Can be set globally with
774.Ic set-default-mode .
775.It Ic not-modified
776Turn off the modified flag in the current buffer.
777.It Ic open-line
778Open up some blank space.
779Essentially, insert
780.Va n
781newlines, then back up over them.
782.It Ic other-window
783The command to make the next (down the screen) window the current
784window.
785There are no real errors, although the command does nothing if
786there is only 1 window on the screen.
787.It Ic overwrite-mode
788Toggle overwrite mode in the current buffer,
789where typing overwrites existing characters rather than inserting them.
790Can be set globally with
791.Ic set-default-mode .
792.It Ic prefix-region
793Inserts a prefix string before each line of a region.
794The prefix string is settable by using
795.Ic set-prefix-string
796or by invoking this command with a prefix argument.
797.It Ic previous-line
798Move backwards
799.Va n
800lines.
801.It Ic previous-window
802This command makes the previous (up the screen) window the
803current window.
804There are no errors, although the command does not do
805a lot if there is only 1 window.
806.It Ic pop-tag-mark
807Return to position where find-tag was previously invoked.
808.It Ic push-shell
809Suspend
810.Nm
811and switch to alternate screen, if available.
812.It Ic pwd
813Display current (global) working directory in the status area.
814.It Ic query-replace
815Query Replace.
816Search and replace strings selectively, prompting after each match.
817.It Ic replace-regexp
818Replace regular expression globally without individual prompting.
819.It Ic replace-string
820Replace string globally without individual prompting.
821.It Ic query-replace-regexp
822Replace strings selectively.
823Does a search and replace operation using regular
824expressions for both patterns.
825.It Ic quoted-insert
826Insert the next character verbatim into the current buffer; i.e. ignore
827any function bound to that key.
828.It Ic re-search-again
829Perform a regular expression search again, using the same search
830string and direction as the last search command.
831.It Ic re-search-backward
832Search backwards using a regular expression.
833Get a search string from the user, and search, starting at dot
834and proceeding toward the front of the buffer.
835If found, dot is left
836pointing at the first character of the pattern [the last character that
837was matched].
838.It Ic re-search-forward
839Search forward using a regular expression.
840Get a search string from the user and search for it starting at dot.
841If found, move dot to just after the matched characters.
842display does all
843the hard stuff.
844If not found, it just prints a message.
845.It Ic recenter
846Reposition dot in the current window.
847By default, the dot is centered.
848If given a positive argument (n), the display is repositioned to line
849n.
850If
851.Va n
852is negative, it is that line from the bottom.
853.It Ic redraw-display
854Refresh the display.
855Recomputes all window sizes in case something has changed.
856.It Ic revert-buffer
857Revert the current buffer to the latest file on disk.
858.It Ic save-buffer
859Save the contents of the current buffer if it has been changed,
860optionally creating a backup copy.
861.It Ic save-buffers-kill-emacs
862Offer to save modified buffers and quit
863.Nm .
864.It Ic save-some-buffers
865Look through the list of buffers, offering to save any buffer that
866has been changed.
867Buffers that are not associated with files (such
868as *scratch*, *grep*, *compile*) are ignored.
869.It Ic scroll-down
870Scroll backwards
871.Va n
872pages.
873A two-line overlap between pages is
874assumed.
875If given a repeat argument, scrolls back lines, not pages.
876.It Ic scroll-one-line-down
877Scroll the display down
878.Va n
879lines without changing the cursor position.
880.It Ic scroll-one-line-up
881Scroll the display
882.Va n
883lines up without moving the cursor position.
884.It Ic scroll-other-window
885Scroll the next window in the window list window forward
886.Va n
887pages.
888.It Ic scroll-up
889Scroll forward one page.
890A two-line overlap between pages is
891assumed.
892If given a repeat argument, scrolls back lines, not pages.
893.It Ic search-again
894Search again, using the same search string and direction as the last
895search command.
896.It Ic search-backward
897Reverse search.
898Get a search string from the user, and search, starting
899at dot and proceeding toward the front of the buffer.
900If found, dot is
901left pointing at the first character of the pattern (the last character
902that was matched).
903.It Ic search-forward
904Search forward.
905Get a search string from the user, and search for it
906starting at dot.
907If found, dot gets moved to just after the matched
908characters, if not found, print a message.
909.It Ic self-insert-command
910Insert a character.
911.It Ic sentence-end-double-space
912Toggle double or single spaces for end of sentences.
913Double is the default.
914Currently only affects fill-paragraph.
915.It Ic set-case-fold-search
916Set case-fold searching, causing case not to matter
917in regular expression searches.
918This is the default.
919.It Ic set-case-replace
920Preserve the case of the replaced string.
921This is the default.
922.It Ic set-default-mode
923Append the supplied mode to the list of default modes
924used by subsequent buffer creation.
925Built in modes include: fill, indent, notab and overwrite.
926.It Ic set-fill-column
927Prompt the user for a fill column.
928Used by
929.Ic auto-fill-mode .
930.It Ic set-mark-command
931Sets the mark in the current window to the current dot location.
932.It Ic set-prefix-string
933Sets the prefix string to be used by the
934.Ic prefix-region
935command.
936.It Ic set-tab-width
937Set the tab width for the current buffer, or the default for new buffers
938if called with a prefix argument or from the startup file.
939.It Ic shell-command
940Execute external command from mini-buffer.
941With a universal argument it inserts the command output into the current
942buffer.
943.It Ic shell-command-on-region
944Provide the text in region to the shell command as input.
945With a universal argument it replaces the region with the command
946output.
947.It Ic shrink-window
948Shrink current window by one line.
949The window immediately below is expanded to pick up the slack.
950If only one window is present, this command has no effect.
951.It Ic space-to-tabstop
952Insert enough spaces to reach the next tab-stop position.
953By default, tab-stops occur every 8 characters.
954.It Ic split-window-vertically
955Split the current window.
956A window smaller than 3 lines cannot be split.
957.It Ic start-kbd-macro
958Start defining a keyboard macro.
959Macro definition is ended by invoking end-kbd-macro.
960.It Ic suspend-emacs
961Suspend
962.Nm
963and switch back to alternate screen, if in use.
964.It Ic switch-to-buffer
965Prompt and switch to a new buffer in the current window.
966.It Ic switch-to-buffer-other-window
967Switch to buffer in another window.
968.It Ic toggle-read-only
969Toggle the read-only flag on the current buffer.
970.It Ic toggle-read-only-all
971Toggle the read-only flag on all non-ephemeral buffers.
972A simple toggle that switches a global read-only flag either on
973or off.
974.It Ic transpose-chars
975Transpose the two characters in front of and under dot,
976then move forward one character.
977Treat newline characters the same as any other.
978.It Ic transpose-paragraphs
979Transpose adjacent paragraphs.
980If multiple iterations are requested, the current paragraph will
981be moved
982.Va n
983paragraphs forward.
984.It Ic transpose-words
985Transpose adjacent words.
986.It Ic undo
987Undo the most recent action.
988If invoked again without an intervening command,
989move the undo pointer to the previous action and undo it.
990.It Ic undo-boundary
991Add an undo boundary.
992This is not usually done interactively.
993.It Ic undo-boundary-toggle
994Toggle whether undo boundaries are generated.
995Undo boundaries are often disabled before operations that should
996be considered atomically undoable.
997.It Ic undo-enable
998Toggle whether undo information is kept.
999.It Ic undo-list
1000Show the undo records for the current buffer in a new buffer.
1001.It Ic universal-argument
1002Repeat the next command 4 times.
1003Usually bound to C-u.
1004This command may be stacked; e.g.\&
1005C-u C-u C-f moves the cursor forward 16 characters.
1006.It Ic upcase-region
1007Upper case region.
1008Change all of the lower case characters in the region to
1009upper case.
1010.It Ic upcase-word
1011Move the cursor forward by the specified number of words.
1012As it moves, convert any characters to upper case.
1013.It Ic visible-bell
1014Toggle the visible bell.
1015If this toggle is on, the modeline will flash.
1016.It Ic visit-tags-table
1017Load tags file to be used for subsequent
1018.Ic find-tag .
1019.It Ic what-cursor-position
1020Display a bunch of useful information about the current location of
1021dot.
1022The character under the cursor (in octal), the current line, row,
1023and column, and approximate position of the cursor in the file (as a
1024percentage) is displayed.
1025The column position assumes an infinite
1026position display; it does not truncate just because the screen does.
1027.It Ic write-file
1028Ask for a file name and write the contents of the current buffer to
1029that file.
1030Update the remembered file name and clear the buffer
1031changed flag.
1032.It Ic yank
1033Yank text from
1034.Ic kill-buffer .
1035Unlike emacs, the
1036.Nm
1037kill buffer consists only
1038of the most recent kill.
1039It is not a ring.
1040.It Ic zap-to-char
1041Ask for a character and delete text from the current cursor position
1042until the next instance of that character, including it.
1043.It Ic zap-up-to-char
1044Like
1045.Ic zap-to-char
1046but doesn't delete the target character.
1047.El
1048.Sh MG DIRED KEY BINDINGS
1049Specific key bindings are available in dired mode.
1050.Pp
1051.Bl -tag -width xxxxxxxxxxxxxxxxxx -offset indent -compact
1052.It DEL
1053dired-unmark-backward
1054.It RET, e, f and C-m
1055dired-find-file
1056.It SPC, n
1057dired-next-line
1058.It !
1059dired-shell-command
1060.It +
1061dired-create-directory
1062.It ^
1063dired-up-directory
1064.It a
1065dired-find-alternate-file
1066.It c
1067dired-do-copy
1068.It d and C-d
1069dired-flag-file-deletion
1070.It g
1071dired-revert
1072.It j
1073dired-goto-file
1074.It o
1075dired-find-file-other-window
1076.It p
1077dired-previous-line
1078.It q
1079quit-window
1080.It r
1081dired-do-rename
1082.It u
1083dired-unmark
1084.It x
1085dired-do-flagged-delete
1086.It C-v
1087dired-scroll-down
1088.It M-v
1089dired-scroll-up
1090.El
1091.Sh MG DIRED COMMANDS
1092The following are a list of the commands specific to dired mode:
1093.Bl -tag -width Ds
1094.It Ic dired-create-directory
1095Create a directory.
1096.It Ic dired-do-copy
1097Copy the file listed on the current line of the dired buffer.
1098.It Ic dired-do-flagged-delete
1099Delete the files that have been flagged for deletion.
1100.It Ic dired-do-rename
1101Rename the file listed on the current line of the dired buffer.
1102.It Ic dired-find-alternate-file
1103Replace the current dired buffer with an alternate one as specified
1104by the position of the cursor in the dired buffer.
1105.It Ic dired-find-file
1106Open the file on the current line of the dired buffer.
1107If the cursor is on a directory, it will be opened in dired mode.
1108.It Ic dired-flag-file-deletion
1109Flag the file listed on the current line for deletion.
1110This is indicated in the buffer by putting a D at the left margin.
1111No files are actually deleted until the function
1112.Ic dired-do-flagged-delete
1113is executed.
1114.It Ic dired-find-file-other-window
1115Open the file on the current line of the dired buffer in a
1116different window.
1117.It Ic dired-goto-file
1118Move the cursor to a file name in the dired buffer.
1119.It Ic dired-next-line
1120Move the cursor to the next line.
1121.It Ic dired-other-window
1122This function works just like dired, except that it puts the
1123dired buffer in another window.
1124.It Ic dired-previous-line
1125Move the cursor to the previous line.
1126.It Ic dired-revert
1127Refresh the dired buffer while retaining any flags.
1128.It Ic dired-scroll-down
1129Scroll down the dired buffer.
1130.It Ic dired-scroll-up
1131Scroll up the dired buffer.
1132.It Ic dired-shell-command
1133Pipe the file under the current cursor position through a shell command.
1134.It Ic dired-unmark
1135Remove the deletion flag for the file on the current line.
1136.It Ic dired-unmark-backward
1137Remove the deletion flag from the file listed on the previous line
1138of the dired buffer, then move up to that line.
1139.It Ic dired-up-directory
1140Open a dired buffer in the parent directory.
1141.It Ic quit-window
1142Close the current dired buffer.
1143.El
1144.Sh CONFIGURATION FILES
1145There are two configuration files,
1146.Pa .mg
1147and
1148.Pa .mg-TERM .
1149Here,
1150.Ev TERM
1151represents the name of the terminal type; e.g. if the terminal type
1152is set to
1153.Dq vt100 ,
1154.Nm
1155will use
1156.Pa .mg-vt100
1157as a startup file.
1158The terminal type startup file is used first.
1159.Pp
1160The startup file format is a list of commands, one per line, as used for
1161interactive evaluation.
1162Strings that are normally entered by the user at any subsequent prompts
1163may be specified after the command name; e.g.:
1164.Bd -literal -offset indent
1165global-set-key ")" self-insert-command
1166global-set-key "\e^x\e^f" find-file
1167global-set-key "\ee[Z" backward-char
1168set-default-mode fill
1169set-fill-column 72
1170auto-execute *.c c-mode
1171.Ed
1172.Pp
1173Comments can be added to the startup files by placing
1174.Sq ;\&
1175or
1176.Sq #
1177as the first character of a line.
1178.Sh FILES
1179.Bl -tag -width /usr/share/doc/mg/tutorial -compact
1180.It Pa ~/.mg
1181normal startup file
1182.It Pa ~/.mg-TERM
1183terminal-specific startup file
1184.It Pa ~/.mg.d
1185alternative backup file location
1186.It Pa /usr/share/doc/mg/tutorial
1187concise tutorial
1188.El
1189.Sh SEE ALSO
1190.Xr ctags 1 ,
1191.Xr vi 1
1192.Sh CAVEATS
1193Since it is written completely in C, there is currently no
1194language in which extensions can be written;
1195however, keys can be rebound and certain parameters can be changed
1196in startup files.
1197.Pp
1198In order to use 8-bit characters (such as German umlauts), the Meta key
1199needs to be disabled via the
1200.Ic meta-key-mode
1201command.
1202.Pp
1203Multi-byte character sets, such as UTF-8, are not supported.
1204