1MG(1)                     BSD General Commands Manual                    MG(1)
2

NAME

4     mg — emacs-like text editor
5

SYNOPSIS

7     mg [-n] [-f mode] [+number] [file ...]
8

DESCRIPTION

10     mg is intended to be a small, fast, and portable editor for people who
11     can't (or don't want to) run emacs for one reason or another, or are not
12     familiar with the vi(1) editor.  It is compatible with emacs because
13     there shouldn't be any reason to learn more editor types than emacs or
14     vi(1).
15
16     The options are as follows:
17
18     +number
19             Go to the line specified by number (do not insert a space between
20             the ‘+’ sign and the number).  If a negative number is specified,
21             the line number counts backwards from the end of the file i.e.
22             +-1 will be the last line of the file, +-2 will be second last,
23             and so on.
24
25     -f mode
26             Run the mode command for all buffers created from arguments on
27             the command line, including the scratch buffer and all files.
28
29     -n      Turn off backup file generation.
30

WINDOWS AND BUFFERS

32     When a file is loaded into mg, it is stored in a buffer.  This buffer may
33     be displayed on the screen in more than one window.  At present, windows
34     may only be split horizontally, so each window is delineated by a mode‐
35     line at the bottom.  If changes are made to a buffer, it will be
36     reflected in all open windows.
37
38     If a buffer name begins and ends with an asterisk, the buffer is consid‐
39     ered throwaway; i.e. the user will not be prompted to save changes when
40     the buffer is killed.
41

POINT AND MARK

43     The current cursor location in mg is called the point (or dot).  It is
44     possible to define a window-specific region of text by setting a second
45     location, called the mark.  The region is the text between point and mark
46     inclusive.  Deleting the character at the mark position leaves the mark
47     at the point of deletion.
48
49     Note: The point and mark are window-specific in mg, not buffer-specific,
50     as in other emacs flavours.
51

DEFAULT KEY BINDINGS

53     Normal editing commands are very similar to GNU Emacs.  In the following
54     examples, C-x means Control-x, and M-x means Meta-x, where the Meta key
55     may be either a special key on the keyboard or the ALT key; otherwise ESC
56     followed by the key X works as well.
57
58     C-SPC       set-mark-command
59     C-a         beginning-of-line
60     C-b         backward-char
61     C-d         delete-char
62     C-e         end-of-line
63     C-f         forward-char
64     C-g         keyboard-quit
65     C-h C-h     help-help
66     C-h a       apropos
67     C-h b       describe-bindings
68     C-h c       describe-key-briefly
69     C-j         newline-and-indent
70     C-k         kill-line
71     C-l         recenter
72     RET         newline
73     C-n         next-line
74     C-o         open-line
75     C-p         previous-line
76     C-q         quoted-insert
77     C-r         isearch-backward
78     C-s         isearch-forward
79     C-t         transpose-chars
80     C-u         universal-argument
81     C-v         scroll-up
82     C-w         kill-region
83     C-x C-b     list-buffers
84     C-x C-c     save-buffers-kill-emacs
85     C-x C-f     find-file
86     C-x C-g     keyboard-quit
87     C-x C-l     downcase-region
88     C-x C-o     delete-blank-lines
89     C-x C-q     toggle-read-only
90     C-x C-r     find-file-read-only
91     C-x C-s     save-buffer
92     C-x C-u     upcase-region
93     C-x C-v     find-alternate-file
94     C-x C-w     write-file
95     C-x C-x     exchange-point-and-mark
96     C-x (       start-kbd-macro
97     C-x )       end-kbd-macro
98     C-x 0       delete-window
99     C-x 1       delete-other-windows
100     C-x 2       split-window-vertically
101     C-x 4 C-f   find-file-other-window
102     C-x 4 C-g   keyboard-quit
103     C-x 4 b     switch-to-buffer-other-window
104     C-x 4 f     find-file-other-window
105     C-x =       what-cursor-position
106     C-x ^       enlarge-window
107     C-x `       next-error
108     C-x b       switch-to-buffer
109     C-x d       dired
110     C-x e       call-last-kbd-macro
111     C-x f       set-fill-column
112     C-x g       goto-line
113     C-x i       insert-file
114     C-x k       kill-buffer
115     C-x n       other-window
116     C-x o       other-window
117     C-x p       previous-window
118     C-x s       save-some-buffers
119     C-x u       undo
120     C-y         yank
121     C-z         suspend-emacs
122     M-C-v       scroll-other-window
123     M-SPC       just-one-space
124     M-%         query-replace
125     M-<         beginning-of-buffer
126     M->         end-of-buffer
127     M-\         delete-horizontal-space
128     M-^         join-line
129     M-b         backward-word
130     M-c         capitalize-word
131     M-d         kill-word
132     M-f         forward-word
133     M-l         downcase-word
134     M-m         back-to-indentation
135     M-q         fill-paragraph
136     M-r         search-backward
137     M-s         search-forward
138     M-u         upcase-word
139     M-v         scroll-down
140     M-w         copy-region-as-kill
141     M-x         execute-extended-command
142     M-{         backward-paragraph
143     M-}         forward-paragraph
144     M-~         not-modified
145     M-DEL       backward-kill-word
146     C-_         undo
147     )           blink-and-insert
148     DEL         delete-backward-char
149
150     For a complete description of mg commands, see MG COMMANDS.  To see the
151     active keybindings at any time, type “M-x describe-bindings”.
152

MG COMMANDS

154     Commands are invoked by “M-x”, or by binding to a key.  Many commands
155     take an optional numerical parameter, n.  This parameter is set either by
156     M-<n> (where n is the numerical argument) before the command, or by one
157     or more invocations of the universal argument, usually bound to C-U.
158     When invoked in this manner, the value of the numeric parameter to be
159     passed is displayed in the minibuffer before the M-x.  One common use of
160     the parameter is in mode toggles (e.g. make-backup-files).  If no parame‐
161     ter is supplied, the mode is toggled to its alternate state.  If a posi‐
162     tive parameter is supplied, the mode is forced to on.  Otherwise, it is
163     forced to off.
164
165     apropos
166            Help Apropos.  Prompt the user for a string, open the *help* buf‐
167            fer, and list all mg commands that contain that string.
168
169     auto-execute
170            Register an auto-execute hook; that is, specify a filename pattern
171            (conforming to the shell's filename globbing rules) and an associ‐
172            ated function to execute when a file matching the specified pat‐
173            tern is read into a buffer.
174
175     auto-fill-mode
176            Toggle auto-fill mode (sometimes called mail-mode), where text
177            inserted past the fill column is automatically wrapped to a new
178            line.
179
180     auto-indent-mode
181            Toggle indent mode, where indentation is preserved after a new‐
182            line.
183
184     back-to-indentation
185            Move the dot to the first non-whitespace character on the current
186            line.
187
188     backward-char
189            Move cursor backwards one character.
190
191     backward-kill-word
192            Kill text backwards by n words.
193
194     backward-paragraph
195            Move cursor backwards n paragraphs.  Paragraphs are delimited by
196            <NL><NL> or <NL><TAB> or <NL><SPACE>.
197
198     backward-word
199            Move cursor backwards by the specified number of words.
200
201     beginning-of-buffer
202            Move cursor to the top of the buffer.
203
204     beginning-of-line
205            Move cursor to the beginning of the line.
206
207     blink-and-insert
208            Self-insert a character, then search backwards and blink its
209            matching delimeter.  For delimeters other than parenthesis, brack‐
210            ets, and braces, the character itself is used as its own match.
211
212     bsmap-mode
213            Toggle bsmap mode, where DEL and c-H are swapped.
214
215     c-mode
216            Toggle a KNF-compliant mode for editing C program files.
217
218     call-last-kbd-macro
219            Invoke the keyboard macro.
220
221     capitalize-word
222            Capitalize n words; i.e. convert the first character of the word
223            to upper case, and subsequent letters to lower case.
224
225     cd     Change the global working directory.  See also global-wd-mode.
226
227     copy-region-as-kill
228            Copy all of the characters in the region to the kill buffer,
229            clearing the mark afterwards.  This is a bit like a kill-region
230            followed by a yank.
231
232     count-matches
233            Count the number of lines matching the supplied regular expres‐
234            sion.
235
236     count-non-matches
237            Count the number of lines not matching the supplied regular
238            expression.
239
240     define-key
241            Prompts the user for a named keymap (mode), a key, and an mg com‐
242            mand, then creates a keybinding in the appropriate map.
243
244     delete-backward-char
245            Delete backwards n characters.  Like delete-char, this actually
246            does a kill if presented with an argument.
247
248     delete-blank-lines
249            Delete blank lines around dot.  If dot is sitting on a blank line,
250            this command deletes all the blank lines above and below the cur‐
251            rent line.  Otherwise, it deletes all of the blank lines after the
252            current line.
253
254     delete-char
255            Delete n characters forward.  If any argument is present, it kills
256            rather than deletes, saving the result in the kill buffer.
257
258     delete-horizontal-space
259            Delete any whitespace around the dot.
260
261     delete-leading-space
262            Delete leading whitespace on the current line.
263
264     delete-trailing-space
265            Delete trailing whitespace on the current line.
266
267     delete-matching-lines
268            Delete all lines after dot that contain a string matching the sup‐
269            plied regular expression.
270
271     delete-non-matching-lines
272            Delete all lines after dot that contain a string matching the sup‐
273            plied regular expression.
274
275     delete-other-windows
276            Make the current window the only window visible on the screen.
277
278     delete-window
279            Delete current window.
280
281     describe-bindings
282            List all global and local keybindings, putting the result in the
283            *help* buffer.
284
285     describe-key-briefly
286            Read a key from the keyboard, and look it up in the keymap.  Dis‐
287            play the name of the function currently bound to the key.
288
289     digit-argument
290            Process a numerical argument for keyboard-invoked functions.
291
292     downcase-region
293            Set all characters in the region to lower case.
294
295     downcase-word
296            Set characters to lower case, starting at the dot, and ending n
297            words away.
298
299     emacs-version
300            Return an mg version string.
301
302     end-kbd-macro
303            Stop defining a keyboard macro.
304
305     end-of-buffer
306            Move cursor to the end of the buffer.
307
308     end-of-line
309            Move cursor to the end of the line.
310
311     enlarge-window
312            Enlarge the current window by shrinking either the window above or
313            below it.
314
315     eval-current-buffer
316            Evaluate the current buffer as a series of mg commands.  Useful
317            for testing mg startup files.
318
319     eval-expression
320            Get one line from the user, and run it.  Useful for testing
321            expressions in mg startup files.
322
323     exchange-point-and-mark
324            Swap the values of "dot" and "mark" in the current window.  Return
325            an error if no mark is set.
326
327     execute-extended-command
328            Invoke an extended command; i.e. M-x.  Call the message line rou‐
329            tine to read in the command name and apply autocompletion to it.
330            When it comes back, look the name up in the symbol table and run
331            the command if it is found, passing arguments as necessary.  Print
332            an error if there is anything wrong.
333
334     fill-paragraph
335            Justify a paragraph, wrapping text at the current fill column.
336
337     find-file
338            Select a file for editing.  First check if the file can be found
339            in another buffer; if it is there, just switch to that buffer.  If
340            the file cannot be found, create a new buffer, read in the file
341            from disk, and switch to the new buffer.
342
343     find-file-read-only
344            Same as find-file, except the new buffer is set to read-only.
345
346     find-alternate-file
347            Replace the current file with an alternate one.  Semantics for
348            finding the replacement file are the same as find-file, except the
349            current buffer is killed before the switch.  If the kill fails, or
350            is aborted, revert to the original file.
351
352     find-file-other-window
353            Opens the specified file in a second buffer.  Splits the current
354            window if necessary.
355
356     forward-char
357            Move cursor forwards (or backwards, if n is negative) n charac‐
358            ters.  Returns an error if the end of buffer is reached.
359
360     forward-paragraph
361            Move forward n paragraphs.  Paragraphs are delimited by <NL><NL>
362            or <NL><TAB> or <NL><SPACE>.
363
364     forward-word
365            Move the cursor forward by the specified number of words.
366
367     global-set-key
368            Bind a key in the global (fundamental) key map.
369
370     global-unset-key
371            Unbind a key from the global (fundamental) key map; i.e. set it to
372            'rescan'.
373
374     global-wd-mode
375            Toggle global working-directory mode.  When enabled, mg defaults
376            to opening files (and executing commands like compile and grep)
377            relative to the global working directory.  When disabled, a work‐
378            ing directory is set for each buffer.
379
380     goto-line
381            Go to a specific line.  If an argument is present, then it is the
382            line number, else prompt for a line number to use.
383
384     help-help
385            Prompts for one of (a)propos, (b)indings, des(c)ribe key briefly.
386
387     insert
388            Insert a string, mainly for use from macros.
389
390     insert-buffer
391            Insert the contents of another buffer at dot.
392
393     insert-file
394            Insert a file into the current buffer at dot.
395
396     insert-with-wrap
397            Insert the bound character with word wrap.  Check to see if we're
398            past the fill column, and if so, justify this line.
399
400     isearch-backward
401            Use incremental searching, initially in the reverse direction.
402            isearch ignores any explicit arguments.  If invoked during macro
403            definition or evaluation, the non-incremental search-backward is
404            invoked instead.
405
406     isearch-forward
407            Use incremental searching, initially in the forward direction.
408            isearch ignores any explicit arguments.  If invoked during macro
409            definition or evaluation, the non-incremental search-forward is
410            invoked instead.
411
412     join-line
413            Join the current line to the previous.  If called with an argu‐
414            ment, join the next line to the current one.
415
416     just-one-space
417            Delete any whitespace around dot, then insert a space.
418
419     keyboard-quit
420            Abort the current action.
421
422     kill-buffer
423            Dispose of a buffer, by name.  If the buffer name does not start
424            and end with an asterisk, prompt the user if the buffer has been
425            changed.
426
427     kill-line
428            Kill line.  If called without an argument, it kills from dot to
429            the end of the line, unless it is at the end of the line, when it
430            kills the newline.  If called with an argument of 0, it kills from
431            the start of the line to dot.  If called with a positive argument,
432            it kills from dot forward over that number of newlines.  If called
433            with a negative argument it kills any text before dot on the cur‐
434            rent line, then it kills back abs(n) lines.
435
436     kill-paragraph
437            Delete n paragraphs starting with the current one.
438
439     kill-region
440            Kill the currently defined region.
441
442     kill-word
443            Delete forward n words.
444
445     line-number-mode
446            Toggle whether line and column numbers are displayed in the mode‐
447            line.
448
449     list-buffers
450            Display the list of available buffers.
451
452     load   Prompt the user for a filename, and then execute commands from
453            that file.
454
455     local-set-key
456            Bind a key mapping in the local (topmost) mode.
457
458     local-unset-key
459            Unbind a key mapping in the local (topmost) mode.
460
461     make-backup-files
462            Toggle generation of backup files.
463
464     meta-key-mode
465            When disabled, the meta key can be used to insert extended-ascii
466            (8-bit) characters.  When enabled, the meta key acts as usual.
467
468     negative-argument
469            Process a negative argument for keyboard-invoked functions.
470
471     newline
472            Insert a newline into the current buffer.
473
474     newline-and-indent
475            Insert a newline, then enough tabs and spaces to duplicate the
476            indentation of the previous line.  Assumes tabs are every eight
477            characters.
478
479     next-line
480            Move forward n lines.
481
482     no-tab-mode
483            Toggle notab mode.  In this mode, spaces are inserted rather than
484            tabs.
485
486     not-modified
487            Turn off the modified flag in the current buffer.
488
489     open-line
490            Open up some blank space.  Essentially, insert n newlines, then
491            back up over them.
492
493     other-window
494            The command to make the next (down the screen) window the current
495            window.  There are no real errors, although the command does noth‐
496            ing if there is only 1 window on the screen.
497
498     overwrite-mode
499            Toggle overwrite mode, where typing in a buffer overwrites exist‐
500            ing characters rather than inserting them.
501
502     prefix-region
503            Inserts a prefix string before each line of a region.  The prefix
504            string is settable by using 'set-prefix-string'.
505
506     previous-line
507            Move backwards n lines.
508
509     previous-window
510            This command makes the previous (up the screen) window the current
511            window.  There are no errors, although the command does not do a
512            lot if there is only 1 window.
513
514     push-shell
515            Suspend mg and switch to alternate screen, if available.
516
517     pwd    Display current (global) working directory in the status area.
518
519     query-replace
520            Query Replace.  Search and replace strings selectively, prompting
521            after each match.
522
523     replace-string
524            Replace string globally without individual prompting.
525
526     query-replace-regexp
527            Replace strings selectively.  Does a search and replace operation
528            using regular expressions for both patterns.
529
530     quoted-insert
531            Insert the next character verbatim into the current buffer; i.e.
532            ignore any function bound to that key.
533
534     re-search-again
535            Perform a regular expression search again, using the same search
536            string and direction as the last search command.
537
538     re-search-backward
539            Search backwards using a regular expression.  Get a search string
540            from the user, and search, starting at dot and proceeding toward
541            the front of the buffer.  If found, dot is left pointing at the
542            first character of the pattern [the last character that was
543            matched].
544
545     re-search-forward
546            Search forward using a regular expression.  Get a search string
547            from the user and search for it starting at dot.  If found, move
548            dot to just after the matched characters.  display does all the
549            hard stuff.  If not found, it just prints a message.
550
551     recenter
552            Reposition dot in the current window.  By default, the dot is cen‐
553            tered.  If given a positive argument (n), the display is reposi‐
554            tioned to line n.  If n is negative, it is that line from the bot‐
555            tom.
556
557     redraw-display
558            Refresh the display.  Recomputes all window sizes in case some‐
559            thing has changed.
560
561     save-buffer
562            Save the contents of the current buffer if it has been changed,
563            optionally creating a backup copy.
564
565     save-buffers-kill-emacs
566            Offer to save modified buffers and quit mg.
567
568     save-some-buffers
569            Look through the list of buffers, offering to save any buffer that
570            has been changed.  Buffers that are not associated with files
571            (such as *scratch*, *grep*, *compile*) are ignored.
572
573     scroll-down
574            Scroll backwards n pages.  A two-line overlap between pages is
575            assumed.  If given a repeat argument, scrolls back lines, not
576            pages.
577
578     scroll-one-line-down
579            Scroll the display down n lines without changing the cursor posi‐
580            tion.
581
582     scroll-one-line-up
583            Scroll the display n lines up without moving the cursor position.
584
585     scroll-other-window
586            Scroll the next window in the window list window forward n pages.
587
588     scroll-up
589            Scroll forward one page.  A two-line overlap between pages is
590            assumed.  If given a repeat argument, scrolls back lines, not
591            pages.
592
593     search-again
594            Search again, using the same search string and direction as the
595            last search command.
596
597     search-backward
598            Reverse search.  Get a search string from the user, and search,
599            starting at dot and proceeding toward the front of the buffer.  If
600            found, dot is left pointing at the first character of the pattern
601            (the last character that was matched).
602
603     search-forward
604            Search forward.  Get a search string from the user, and search for
605            it starting at dot.  If found, dot gets moved to just after the
606            matched characters, if not found, print a message.
607
608     self-insert-command
609            Insert a character.
610
611     set-case-fold-search
612            Set case-fold searching, causing case nopt to matter in regular
613            expression searches.  This is the default.
614
615     set-default-mode
616            Append the supplied mode to the list of default modes used by sub‐
617            sequent buffer creation.  Built in modes include: fill, indent,
618            overwrite, and notab.
619
620     set-fill-column
621            Prompt the user for a fill column.  Used by auto-fill-mode.
622
623     set-mark-command
624            Sets the mark in the current window to the current dot location.
625
626     set-prefix-string
627            Sets the prefix string to be used by the 'prefix-region' command.
628
629     shrink-window
630            Shrink current window by one line.  The window immediately below
631            is expanded to pick up the slack.  If only one window is present,
632            this command has no effect.
633
634     space-to-tabstop
635            Insert enough spaces to reach the next tab-stop position.  By
636            default, tab-stops occur every 8 characters.
637
638     split-window-vertically
639            Split the current window.  A window smaller than 3 lines cannot be
640            split.
641
642     start-kbd-macro
643            Start defining a keyboard macro.  Macro definition is ended by
644            invoking end-kbd-macro.
645
646     suspend-emacs
647            Suspend mg and switch back to alternate screen, if in use.
648
649     switch-to-buffer
650            Prompt and switch to a new buffer in the current window.
651
652     switch-to-buffer-other-window
653            Switch to buffer in another window.
654
655     toggle-read-only
656            Toggle the read-only flag on the current buffer.
657
658     transpose-chars
659            Transpose the two characters on either side of dot.  If dot is at
660            the end of the line, transpose the two characters before it.
661            Return with an error if dot is at the beginning of line; it seems
662            to be a bit pointless to make this work.
663
664     undo   Undo the most recent action.  If invoked again without an inter‐
665            vening command, move the undo pointer to the previous action and
666            undo it.
667
668     undo-boundary
669            Add an undo boundary.  This is not usually done interactively.
670
671     undo-boundary-toggle
672            Toggle whether undo boundaries are generated.  Undo boundaries are
673            often disabled before operations that should be considered atomi‐
674            cally undoable.
675
676     undo-enable
677            Toggle whether undo information is kept.
678
679     undo-list
680            Show the undo records for the current buffer in a new buffer.
681
682     universal-argument
683            Repeat the next command 4 times.  Usually bound to C-u.  This com‐
684            mand may be stacked; e.g. C-u C-u C-f moves the cursor forward 16
685            characters.
686
687     upcase-region
688            Upper case region.  Change all of the lower case characters in the
689            region to upper case.
690
691     upcase-word
692            Move the cursor forward by the specified number of words.  As it
693            moves, convert any characters to upper case.
694
695     what-cursor-position
696            Display a bunch of useful information about the current location
697            of dot.  The character under the cursor (in octal), the current
698            line, row, and column, and approximate position of the cursor in
699            the file (as a percentage) is displayed.  The column position
700            assumes an infinite position display; it does not truncate just
701            because the screen does.
702
703     write-file
704            Ask for a file name and write the contents of the current buffer
705            to that file.  Update the remembered file name and clear the buf‐
706            fer changed flag.
707
708     yank   Yank text from kill-buffer.  Unlike emacs, the mg kill buffer con‐
709            sists only of the most recent kill.  It is not a ring.
710

CONFIGURATION FILES

712     There are two configuration files, .mg, and .mg-TERM.  Here, TERM repre‐
713     sents the name of the terminal type; e.g., if the terminal type is set to
714     “vt100”, mg will use .mg-vt100 as a startup file.  The terminal type
715     startup file is used first.
716
717     The startup file format is a list of commands, one per line, as used for
718     interactive evaluation.  Strings that are normally entered by the user at
719     any subsequent prompts may be specified after the command name; e.g.:
720
721           global-set-key ")" self-insert-command
722           global-set-key "\^x\^f" find-file
723           global-set-key "\e[Z" backward-char
724           set-default-mode fill
725           set-fill-column 72
726           auto-execute *.c c-mode
727

FILES

729     ~/.mg                       normal startup file
730     ~/.mg-TERM                  terminal-specific startup file
731     /usr/share/doc/mg/tutorial  concise tutorial
732

SEE ALSO

734     vi(1)
735

CAVEATS

737     Since it is written completely in C, there is currently no language in
738     which extensions can be written; however, keys can be rebound and certain
739     parameters can be changed in startup files.
740
741     In order to use 8-bit characters (such as German umlauts), the Meta key
742     needs to be disabled via the “meta-key-mode” command.
743
744BSD                              June 22, 2019                             BSD
Impressum