xref: /openbsd/usr.bin/mg/mg.1 (revision e1665715)
1.\"	$OpenBSD: mg.1,v 1.46 2010/03/26 19:30:40 jmc Exp $
2.\" This file is in the public domain.
3.\"
4.Dd $Mdocdate: March 26 2010 $
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 n
13.Op Fl f Ar mode
14.Op + Ns Ar number
15.Op Ar
16.Sh DESCRIPTION
17.Nm
18is intended to be a small, fast, and portable editor for
19people who can't (or don't want to) run emacs for one
20reason or another, or are not familiar with the
21.Xr vi 1
22editor.
23It is compatible with emacs because there shouldn't
24be any reason to learn more editor types than emacs or
25.Xr vi 1 .
26.Pp
27The options are as follows:
28.Bl -tag -width Ds
29.It + Ns Ar number
30Go to the line specified by number (do not insert
31a space between the
32.Sq +
33sign and the number).
34If a negative number is specified, the line number counts
35backwards from the end of the file i.e. +-1 will be the last
36line of the file, +-2 will be second last, and so on.
37.It Fl f Ar mode
38Run the mode command for all buffers created from
39arguments on the command line, including the
40scratch buffer and all files.
41.It Fl n
42Turn off backup file generation.
43.El
44.Sh WINDOWS AND BUFFERS
45When a file is loaded into
46.Nm ,
47it is stored in a
48.Em buffer .
49This buffer may be displayed on the screen in more than one window.
50At present, windows may only be split horizontally, so each window is
51delineated by a modeline at the bottom.
52If changes are made to a buffer, it will be reflected in all open windows.
53.Pp
54If a buffer name begins and ends with an asterisk, the buffer is considered
55throwaway; i.e. the user will not be prompted to save changes when
56the buffer is killed.
57.Sh POINT AND MARK
58The current cursor location in
59.Nm
60is called the
61.Em point
62(or
63.Em dot ) .
64It is possible to define a window-specific region of text by setting a second
65location, called the
66.Em mark .
67The
68.Em region
69is the text between point and mark inclusive.
70Deleting the character at the mark position leaves
71the mark at the point of deletion.
72.Pp
73Note: The point and mark are window-specific in
74.Nm ,
75not buffer-specific, as in other emacs flavours.
76.Sh DEFAULT KEY BINDINGS
77Normal editing commands are very similar to Gnu Emacs.
78In the following examples, C-x means control-X, and M-x means Meta-X,
79where the Meta key may be either a special key on your keyboard
80or the ALT key; otherwise ESC followed by the key X works as well.
81.Pp
82.Bl -tag -width xxxxxxxxxx -compact
83.It C-SPC
84set-mark-command
85.It C-a
86beginning-of-line
87.It C-b
88backward-char
89.It C-d
90delete-char
91.It C-e
92end-of-line
93.It C-f
94forward-char
95.It C-g
96keyboard-quit
97.It C-h C-h
98help-help
99.It C-h a
100apropos
101.It C-h b
102describe-bindings
103.It C-h c
104describe-key-briefly
105.It C-j
106newline-and-indent
107.It C-k
108kill-line
109.It C-l
110recenter
111.It RET
112newline
113.It C-n
114next-line
115.It C-o
116open-line
117.It C-p
118previous-line
119.It C-q
120quoted-insert
121.It C-r
122isearch-backward
123.It C-s
124isearch-forward
125.It C-t
126transpose-chars
127.It C-u
128universal-argument
129.It C-v
130scroll-up
131.It C-w
132kill-region
133.It C-x C-b
134list-buffers
135.It C-x C-c
136save-buffers-kill-emacs
137.It C-x C-f
138find-file
139.It C-x C-g
140keyboard-quit
141.It C-x C-l
142downcase-region
143.It C-x C-o
144delete-blank-lines
145.It C-x C-q
146toggle-read-only
147.It C-x C-r
148find-file-read-only
149.It C-x C-s
150save-buffer
151.It C-x C-u
152upcase-region
153.It C-x C-v
154find-alternate-file
155.It C-x C-w
156write-file
157.It C-x C-x
158exchange-point-and-mark
159.It C-x (
160start-kbd-macro
161.It C-x \&)
162end-kbd-macro
163.It C-x 0
164delete-window
165.It C-x 1
166delete-other-windows
167.It C-x 2
168split-window-vertically
169.It C-x 4 C-f
170find-file-other-window
171.It C-x 4 C-g
172keyboard-quit
173.It C-x 4 b
174switch-to-buffer-other-window
175.It C-x 4 f
176find-file-other-window
177.It C-x =
178what-cursor-position
179.It C-x ^
180enlarge-window
181.It C-x `
182next-error
183.It C-x b
184switch-to-buffer
185.It C-x d
186dired
187.It C-x e
188call-last-kbd-macro
189.It C-x f
190set-fill-column
191.It C-x g
192goto-line
193.It C-x i
194insert-file
195.It C-x k
196kill-buffer
197.It C-x n
198other-window
199.It C-x o
200other-window
201.It C-x p
202previous-window
203.It C-x s
204save-some-buffers
205.It C-x u
206undo
207.It C-y
208yank
209.It C-z
210suspend-emacs
211.It M-C-v
212scroll-other-window
213.It M-SPC
214just-one-space
215.It M-%
216query-replace
217.It M-<
218beginning-of-buffer
219.It M->
220end-of-buffer
221.It M-\e
222delete-horizontal-space
223.It M-b
224backward-word
225.It M-c
226capitalize-word
227.It M-d
228kill-word
229.It M-f
230forward-word
231.It M-l
232downcase-word
233.It M-q
234fill-paragraph
235.It M-r
236search-backward
237.It M-s
238search-forward
239.It M-u
240upcase-word
241.It M-v
242scroll-down
243.It M-w
244copy-region-as-kill
245.It M-x
246execute-extended-command
247.It M-{
248backward-paragraph
249.It M-}
250forward-paragraph
251.It M-~
252not-modified
253.It M-DEL
254backward-kill-word
255.It C-_
256undo
257.It )
258blink-and-insert
259.It DEL
260delete-backward-char
261.El
262.Pp
263For a complete description of
264.Nm
265commands, see
266.Sx MG COMMANDS .
267To see the active keybindings at any time, type
268.Dq M-x describe-bindings .
269.Sh MG COMMANDS
270Commands are invoked by
271.Dq M-x ,
272or by binding to a key.
273Many commands take an optional numerical parameter,
274.Va n .
275This parameter is set either by
276M-<n> (where
277.Va n
278is the numerical argument) before the command, or by
279one or more invocations of the universal argument, usually bound to C-U.
280When invoked in this manner, the value of the numeric parameter to
281be passed is displayed in the minibuffer before the M-x.
282One common use of the parameter is in mode toggles (e.g.\&
283make-backup-files).
284If no parameter is supplied, the mode is toggled to its
285alternate state.
286If a positive parameter is supplied, the mode is forced to on.
287Otherwise, it is forced to off.
288.\"
289.Bl -tag -width xxxxx
290.It apropos
291Help Apropos.
292Prompt the user for a string, open the *help* buffer,
293and list all
294.Nm
295commands that contain that string.
296.It auto-execute
297Register an auto-execute hook; that is, specify a filename pattern
298(conforming to the shell's filename globbing rules) and an associated
299function to execute when a file matching the specified pattern
300is read into a buffer.
301.It auto-fill-mode
302Toggle auto-fill mode (sometimes called mail-mode),
303where text inserted past the fill column is automatically wrapped
304to a new line.
305.It auto-indent-mode
306Toggle indent mode, where indentation is preserved after a newline.
307.It backward-char
308Move cursor backwards one character.
309.It backward-kill-word
310Kill text backwards by
311.Va n
312words.
313.It backward-paragraph
314Move cursor backwards
315.Va n
316paragraphs.
317Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>.
318.It backward-word
319Move cursor backwards by the specified number of words.
320.It beginning-of-buffer
321Move cursor to the top of the buffer.
322.It beginning-of-line
323Move cursor to the beginning of the line.
324.It blink-and-insert
325Self-insert a character, then search backwards and blink its
326matching delimeter.
327For delimeters other than
328parenthesis, brackets, and braces, the character itself
329is used as its own match.
330.It bsmap-mode
331Toggle bsmap mode, where DEL and c-H are swapped.
332.It c-mode
333Toggle a KNF-compliant mode for editing C program files.
334.It call-last-kbd-macro
335Invoke the keyboard macro.
336.It capitalize-word
337Capitalize
338.Va n
339words; i.e. convert the first character of the word to
340upper case, and subsequent letters to lower case.
341.It cd
342Change the global working directory.
343See also global-wd-mode.
344.It copy-region-as-kill
345Copy all of the characters in the region to the kill buffer,
346clearing the mark afterwards.
347This is a bit like a kill-region followed by a yank.
348.It count-matches
349Count the number of lines matching the supplied regular expression.
350.It count-non-matches
351Count the number of lines not matching the supplied regular expression.
352.It define-key
353Prompts the user for a named keymap (mode),
354a key, and an
355.Nm
356command, then creates a keybinding in the appropriate
357map.
358.It delete-backward-char
359Delete backwards
360.Va n
361characters.
362Like delete-char, this actually does a kill if presented
363with an argument.
364.It delete-blank-lines
365Delete blank lines around dot.
366If dot is sitting on a blank line, this command
367deletes all the blank lines above and below the current line.
368Otherwise, it deletes all of the blank lines after the current line.
369.It delete-char
370Delete
371.Va n
372characters forward.
373If any argument is present, it kills rather than deletes,
374saving the result in the kill buffer.
375.It delete-horizontal-space
376Delete any whitespace around the dot.
377.It delete-leading-space
378Delete leading whitespace on the current line.
379.It delete-trailing-space
380Delete trailing whitespace on the current line.
381.It delete-matching-lines
382Delete all lines after dot that contain a string matching
383the supplied regular expression.
384.It delete-non-matching-lines
385Delete all lines after dot that contain a string matching
386the supplied regular expression.
387.It delete-other-windows
388Make the current window the only window visible on the screen.
389.It delete-window
390Delete current window.
391.It describe-bindings
392List all global and local keybindings, putting the result in
393the *help* buffer.
394.It describe-key-briefly
395Read a key from the keyboard, and look it up in the keymap.
396Display the name of the function currently bound to the key.
397.It digit-argument
398Process a numerical argument for keyboard-invoked functions.
399.It downcase-region
400Set all characters in the region to lower case.
401.It downcase-word
402Set characters to lower case, starting at the dot, and ending
403.Va n
404words away.
405.It emacs-version
406Return an
407.Nm
408version string.
409.It end-kbd-macro
410Stop defining a keyboard macro.
411.It end-of-buffer
412Move cursor to the end of the buffer.
413.It end-of-line
414Move cursor to the end of the line.
415.It enlarge-window
416Enlarge the current window by shrinking either the window above
417or below it.
418.It eval-current-buffer
419Evaluate the current buffer as a series of
420.Nm
421commands.
422Useful for testing
423.Nm
424startup files.
425.It eval-expression
426Get one line from the user, and run it.
427Useful for testing expressions in
428.Nm
429startup files.
430.It exchange-point-and-mark
431Swap the values of "dot" and "mark" in the current window.
432Return an error if no mark is set.
433.It execute-extended-command
434Invoke an extended command; i.e. M-x.
435Call the message line routine to read in the command name and apply
436autocompletion to it.
437When it comes back, look the name up in the symbol table and run the
438command if it is found, passing arguments as necessary.
439Print an error if there is anything wrong.
440.It fill-paragraph
441Justify a paragraph, wrapping text at the current fill column.
442.It find-file
443Select a file for editing.
444First check if you can find the file
445in another buffer; if you can find it, just switch to the buffer.
446If you cannot find the file, create a new buffer, read in the
447file from disk, and switch to the new buffer.
448.It find-file-read-only
449Same as find-file, except the new buffer is set to read-only.
450.It find-alternate-file
451Replace the current file with an alternate one.
452Semantics for finding the replacement file are the same as
453find-file, except the current buffer is killed before the switch.
454If the kill fails, or is aborted, revert to the original file.
455.It find-file-other-window
456Opens the specified file in a second buffer.
457Splits the current window if necessary.
458.It forward-char
459Move cursor forwards (or backwards, if
460.Va n
461is negative)
462.Va n
463characters.
464Returns an error if the end of buffer is reached.
465.It forward-paragraph
466Move forward
467.Va n
468paragraphs.
469Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>.
470.It forward-word
471Move the cursor forward by the specified number of words.
472.It global-set-key
473Bind a key in the global (fundamental) key map.
474.It global-unset-key
475Unbind a key from the global (fundamental) key map; i.e. set it to 'rescan'.
476.It global-wd-mode
477Toggle global working-directory mode.
478When enabled,
479.Nm
480defaults to opening files (and executing commands like compile and grep)
481relative to the global working directory.
482When disabled, a working directory is set for each buffer.
483.It goto-line
484Go to a specific line.
485If an argument is present, then
486it is the line number, else prompt for a line number to use.
487.It help-help
488Prompts for one of (a)propos, (b)indings, des(c)ribe key briefly.
489.It insert
490Insert a string, mainly for use from macros.
491.It insert-buffer
492Insert the contents of another buffer at dot.
493.It insert-file
494Insert a file into the current buffer at dot.
495.It insert-with-wrap
496Insert the bound character with word wrap.
497Check to see if we're past the fill column, and if so,
498justify this line.
499.It isearch-backward
500Use incremental searching, initially in the reverse direction.
501isearch ignores any explicit arguments.
502If invoked during macro definition or evaluation, the non-incremental
503search-backward is invoked instead.
504.It isearch-forward
505Use incremental searching, initially in the forward direction.
506isearch ignores any explicit arguments.
507If invoked during macro definition or evaluation, the non-incremental
508search-forward is invoked instead.
509.It just-one-space
510Delete any whitespace around dot, then insert a space.
511.It keyboard-quit
512Abort the current action.
513.It kill-buffer
514Dispose of a buffer, by name.
515If the buffer name does not start and end with an asterisk,
516prompt the user if the buffer
517has been changed.
518.It kill-line
519Kill line.
520If called without an argument, it kills from dot to the end
521of the line, unless it is at the end of the line, when it kills the
522newline.
523If called with an argument of 0, it kills from the start of the
524line to dot.
525If called with a positive argument, it kills from dot
526forward over that number of newlines.
527If called with a negative argument
528it kills any text before dot on the current line, then it kills back
529abs(n) lines.
530.It kill-paragraph
531Delete
532.Va n
533paragraphs starting with the current one.
534.It kill-region
535Kill the currently defined region.
536.It kill-word
537Delete forward
538.Va n
539words.
540.It line-number-mode
541Toggle whether line and column numbers are displayed in the modeline.
542.It list-buffers
543Display the list of available buffers.
544.It load
545Prompt the user for a filename, and then execute commands
546from that file.
547.It local-set-key
548Bind a key mapping in the local (topmost) mode.
549.It local-unset-key
550Unbind a key mapping in the local (topmost) mode.
551.It make-backup-files
552Toggle generation of backup files.
553.It meta-key-mode
554When disabled, the meta key can be used to insert extended-ascii (8-bit)
555characters.
556When enabled, the meta key acts as usual.
557.It negative-argument
558Process a negative argument for keyboard-invoked functions.
559.It newline
560Insert a newline into the current buffer.
561.It newline-and-indent
562Insert a newline, then enough tabs and spaces to duplicate the indentation
563of the previous line.
564Assumes tabs are every eight characters.
565.It next-line
566Move forward
567.Va n
568lines.
569.It no-tab-mode
570Toggle notab mode.
571In this mode, spaces are inserted rather than tabs.
572.It not-modified
573Turn off the modified flag in the current buffer.
574.It open-line
575Open up some blank space.
576Essentially, insert
577.Va n
578newlines, then back up over them.
579.It other-window
580The command to make the next (down the screen) window the current
581window.
582There are no real errors, although the command does nothing if
583there is only 1 window on the screen.
584.It overwrite-mode
585Toggle overwrite mode, where typing in a buffer overwrites
586existing characters rather than inserting them.
587.It prefix-region
588Inserts a prefix string before each line of a region.
589The prefix string is settable by using 'set-prefix-string'.
590.It previous-line
591Move backwards
592.Va n
593lines.
594.It previous-window
595This command makes the previous (up the screen) window the
596current window.
597There are no errors, although the command does not do
598a lot if there is only 1 window.
599.It push-shell
600Suspend
601.Nm
602and switch to alternate screen, if available.
603.It pwd
604Display current (global) working directory in the status area.
605.It query-replace
606Query Replace.
607Search and replace strings selectively, prompting after each match.
608.It replace-string
609Replace string globally without individual prompting.
610.It query-replace-regexp
611Replace strings selectively.
612Does a search and replace operation using regular
613expressions for both patterns.
614.It quoted-insert
615Insert the next character verbatim into the current buffer; i.e. ignore
616any function bound to that key.
617.It re-search-again
618Perform a regular expression search again, using the same search
619string and direction as the last search command.
620.It re-search-backward
621Search backwards using a regular expression.
622Get a search string from the user, and search, starting at dot
623and proceeding toward the front of the buffer.
624If found, dot is left
625pointing at the first character of the pattern [the last character that
626was matched].
627.It re-search-forward
628Search forward using a regular expression.
629Get a search string from the user and search for it starting at dot.
630If found, move dot to just after the matched characters.
631display does all
632the hard stuff.
633If not found, it just prints a message.
634.It recenter
635Reposition dot in the current window.
636By default, the dot is centered.
637If given a positive argument (n), the display is repositioned to line
638n.
639If
640.Va n
641is negative, it is that line from the bottom.
642.It redraw-display
643Refresh the display.
644Recomputes all window sizes in case something has changed.
645.It save-buffer
646Save the contents of the current buffer if it has been changed,
647optionally creating a backup copy.
648.It save-buffers-kill-emacs
649Offer to save modified buffers and quit
650.Nm .
651.It save-some-buffers
652Look through the list of buffers, offering to save any buffer that
653has been changed.
654Buffers that are not associated with files (such
655as *scratch*, *grep*, *compile*) are ignored.
656.It scroll-down
657Scroll backwards
658.Va n
659pages.
660A two-line overlap between pages is
661assumed.
662If given a repeat argument, scrolls back lines, not pages.
663.It scroll-one-line-down
664Scroll the display down
665.Va n
666lines without changing the cursor position.
667.It scroll-one-line-up
668Scroll the display
669.Va n
670lines up without moving the cursor position.
671.It scroll-other-window
672Scroll the next window in the window list window forward
673.Va n
674pages.
675.It scroll-up
676Scroll forward one page.
677A two-line overlap between pages is
678assumed.
679If given a repeat argument, scrolls back lines, not pages.
680.It search-again
681Search again, using the same search string and direction as the last
682search command.
683.It search-backward
684Reverse search.
685Get a search string from the user, and search, starting
686at dot and proceeding toward the front of the buffer.
687If found, dot is
688left pointing at the first character of the pattern (the last character
689that was matched).
690.It search-forward
691Search forward.
692Get a search string from the user, and search for it
693starting at dot.
694If found, dot gets moved to just after the matched
695characters, if not found, print a message.
696.It self-insert-command
697Insert a character.
698.It set-case-fold-search
699Set case-fold searching, causing case nopt to matter
700in regular expression searches.
701This is the default.
702.It set-default-mode
703Append the supplied mode to the list of default modes
704used by subsequent buffer creation.
705Built in modes include: fill, indent, overwrite, and notab.
706.It set-fill-column
707Prompt the user for a fill column.
708Used by auto-fill-mode.
709.It set-mark-command
710Sets the mark in the current window to the current dot location.
711.It set-prefix-string
712Sets the prefix string to be used by the 'prefix-region' command.
713.It shrink-window
714Shrink current window by one line.
715The window immediately below is expanded to pick up the slack.
716If only one window is present, this command has no effect.
717.It space-to-tabstop
718Insert enough spaces to reach the next tab-stop position.
719By default, tab-stops occur every 8 characters.
720.It split-window-vertically
721Split the current window.
722A window smaller than 3 lines cannot be split.
723.It start-kbd-macro
724Start defining a keyboard macro.
725Macro definition is ended by invoking end-kbd-macro.
726.It suspend-emacs
727Suspend
728.Nm
729and switch back to alternate screen, if in use.
730.It switch-to-buffer
731Prompt and switch to a new buffer in the current window.
732.It switch-to-buffer-other-window
733Switch to buffer in another window.
734.It toggle-read-only
735Toggle the read-only flag on the current buffer.
736.It transpose-chars
737Transpose the two characters on either side of dot.
738If dot is at the end of the line, transpose the two characters before it.
739Return with an error if dot is at the beginning of line;
740it seems to be a bit pointless to
741make this work.
742.It undo
743Undo the most recent action.
744If invoked again without an intervening command,
745move the undo pointer to the previous action and undo it.
746.It undo-boundary
747Add an undo boundary.
748This is not usually done interactively.
749.It undo-boundary-toggle
750Toggle whether undo boundaries are generated.
751Undo boundaries are often disabled before operations that should
752be considered atomically undoable.
753.It undo-enable
754Toggle whether undo information is kept.
755.It undo-list
756Show the undo records for the current buffer in a new buffer.
757.It universal-argument
758Repeat the next command 4 times.
759Usually bound to C-u.
760This command may be stacked; e.g.\&
761C-u C-u C-f moves the cursor forward 16 characters.
762.It upcase-region
763Upper case region.
764Change all of the lower case characters in the region to
765upper case.
766.It upcase-word
767Move the cursor forward by the specified number of words.
768As you move, convert any characters to upper case.
769.It what-cursor-position
770Display a bunch of useful information about the current location of
771dot.
772The character under the cursor (in octal), the current line, row,
773and column, and approximate position of the cursor in the file (as a
774percentage) is displayed.
775The column position assumes an infinite
776position display; it does not truncate just because the screen does.
777.It write-file
778Ask for a file name and write the contents of the current buffer to
779that file.
780Update the remembered file name and clear the buffer
781changed flag.
782.It yank
783Yank text from kill-buffer.
784Unlike emacs, the
785.Nm
786kill buffer consists only
787of the most recent kill.
788It is not a ring.
789.El
790.Sh CONFIGURATION FILES
791There are two configuration files,
792.Pa .mg ,
793and
794.Pa .mg-TERM .
795Here,
796.Ev TERM
797represents the name of your terminal type; e.g., if your terminal type
798is set to
799.Dq vt100 ,
800.Nm
801will use
802.Pa .mg-vt100
803as a startup file.
804The terminal type startup file is used first.
805.Pp
806The startup file format is a list of commands, one per line, as used for
807interactive evaluation.
808Strings that are normally entered by the user at any subsequent prompts
809may be specified after the command name; e.g.:
810.Bd -literal -offset indent
811global-set-key ")" self-insert-command
812global-set-key "\e^x\e^f" find-file
813global-set-key "\ee[Z" backward-char
814set-default-mode fill
815set-fill-column 72
816auto-execute *.c c-mode
817.Ed
818.Sh FILES
819.Bl -tag -width ~/.mg-TERM -compact
820.It Pa ~/.mg
821normal startup file
822.It Pa ~/.mg-TERM
823terminal-specific startup file
824.El
825.Sh SEE ALSO
826.Xr vi 1
827.Sh CAVEATS
828Since it is written completely in C, there is currently no
829language in which you can write extensions;
830however, you can rebind keys and change certain parameters
831in startup files.
832.Pp
833In order to use 8-bit characters (such as German umlauts), the Meta key
834needs to be disabled via the
835.Dq meta-key-mode
836command.
837