Provided by: mg_20110905-1.1_amd64
NAME
mg — emacs-like text editor
SYNOPSIS
mg [-n] [-f mode] [+number] [file ...]
DESCRIPTION
mg is intended to be a small, fast, and portable editor for people who can't (or don't want to) run emacs for one reason or another, or are not familiar with the vi(1) editor. It is compatible with emacs because there shouldn't be any reason to learn more editor types than emacs or vi(1). The options are as follows: +number Go to the line specified by number (do not insert a space between the ‘+’ sign and the number). If a negative number is specified, the line number counts backwards from the end of the file i.e. +-1 will be the last line of the file, +-2 will be second last, and so on. -f mode Run the mode command for all buffers created from arguments on the command line, including the scratch buffer and all files. -n Turn off backup file generation.
WINDOWS AND BUFFERS
When a file is loaded into mg, it is stored in a buffer. This buffer may be displayed on the screen in more than one window. At present, windows may only be split horizontally, so each window is delineated by a modeline at the bottom. If changes are made to a buffer, it will be reflected in all open windows. If a buffer name begins and ends with an asterisk, the buffer is considered throwaway; i.e. the user will not be prompted to save changes when the buffer is killed.
POINT AND MARK
The current cursor location in mg is called the point (or dot). It is possible to define a window-specific region of text by setting a second location, called the mark. The region is the text between point and mark inclusive. Deleting the character at the mark position leaves the mark at the point of deletion. Note: The point and mark are window-specific in mg, not buffer-specific, as in other emacs flavours.
DEFAULT KEY BINDINGS
Normal editing commands are very similar to GNU Emacs. In the following examples, C-x means Control-x, and M-x means Meta-x, where the Meta key may be either a special key on the keyboard or the ALT key; otherwise ESC followed by the key X works as well. C-SPC set-mark-command C-a beginning-of-line C-b backward-char C-d delete-char C-e end-of-line C-f forward-char C-g keyboard-quit C-h C-h help-help C-h a apropos C-h b describe-bindings C-h c describe-key-briefly C-j newline-and-indent C-k kill-line C-l recenter RET newline C-n next-line C-o open-line C-p previous-line C-q quoted-insert C-r isearch-backward C-s isearch-forward C-t transpose-chars C-u universal-argument C-v scroll-up C-w kill-region C-x C-b list-buffers C-x C-c save-buffers-kill-emacs C-x C-f find-file C-x C-g keyboard-quit C-x C-l downcase-region C-x C-o delete-blank-lines C-x C-q toggle-read-only C-x C-r find-file-read-only C-x C-s save-buffer C-x C-u upcase-region C-x C-v find-alternate-file C-x C-w write-file C-x C-x exchange-point-and-mark C-x ( start-kbd-macro C-x ) end-kbd-macro C-x 0 delete-window C-x 1 delete-other-windows C-x 2 split-window-vertically C-x 4 C-f find-file-other-window C-x 4 C-g keyboard-quit C-x 4 b switch-to-buffer-other-window C-x 4 f find-file-other-window C-x = what-cursor-position C-x ^ enlarge-window C-x ` next-error C-x b switch-to-buffer C-x d dired C-x e call-last-kbd-macro C-x f set-fill-column C-x g goto-line C-x i insert-file C-x k kill-buffer C-x n other-window C-x o other-window C-x p previous-window C-x s save-some-buffers C-x u undo C-y yank C-z suspend-emacs M-C-v scroll-other-window M-SPC just-one-space M-% query-replace M-< beginning-of-buffer M-> end-of-buffer M-\ delete-horizontal-space M-^ join-line M-b backward-word M-c capitalize-word M-d kill-word M-f forward-word M-l downcase-word M-m back-to-indentation M-q fill-paragraph M-r search-backward M-s search-forward M-u upcase-word M-v scroll-down M-w copy-region-as-kill M-x execute-extended-command M-{ backward-paragraph M-} forward-paragraph M-~ not-modified M-DEL backward-kill-word C-_ undo ) blink-and-insert DEL delete-backward-char For a complete description of mg commands, see MG COMMANDS. To see the active keybindings at any time, type “M-x describe-bindings”.
MG COMMANDS
Commands are invoked by “M-x”, or by binding to a key. Many commands take an optional numerical parameter, n. This parameter is set either by M-<n> (where n is the numerical argument) before the command, or by one or more invocations of the universal argument, usually bound to C-U. When invoked in this manner, the value of the numeric parameter to be passed is displayed in the minibuffer before the M-x. One common use of the parameter is in mode toggles (e.g. make-backup-files). If no parameter is supplied, the mode is toggled to its alternate state. If a positive parameter is supplied, the mode is forced to on. Otherwise, it is forced to off. apropos Help Apropos. Prompt the user for a string, open the *help* buffer, and list all mg commands that contain that string. auto-execute Register an auto-execute hook; that is, specify a filename pattern (conforming to the shell's filename globbing rules) and an associated function to execute when a file matching the specified pattern is read into a buffer. auto-fill-mode Toggle auto-fill mode (sometimes called mail-mode), where text inserted past the fill column is automatically wrapped to a new line. auto-indent-mode Toggle indent mode, where indentation is preserved after a newline. back-to-indentation Move the dot to the first non-whitespace character on the current line. backward-char Move cursor backwards one character. backward-kill-word Kill text backwards by n words. backward-paragraph Move cursor backwards n paragraphs. Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>. backward-word Move cursor backwards by the specified number of words. beginning-of-buffer Move cursor to the top of the buffer. beginning-of-line Move cursor to the beginning of the line. blink-and-insert Self-insert a character, then search backwards and blink its matching delimeter. For delimeters other than parenthesis, brackets, and braces, the character itself is used as its own match. bsmap-mode Toggle bsmap mode, where DEL and c-H are swapped. c-mode Toggle a KNF-compliant mode for editing C program files. call-last-kbd-macro Invoke the keyboard macro. capitalize-word Capitalize n words; i.e. convert the first character of the word to upper case, and subsequent letters to lower case. cd Change the global working directory. See also global-wd-mode. copy-region-as-kill Copy all of the characters in the region to the kill buffer, clearing the mark afterwards. This is a bit like a kill-region followed by a yank. count-matches Count the number of lines matching the supplied regular expression. count-non-matches Count the number of lines not matching the supplied regular expression. define-key Prompts the user for a named keymap (mode), a key, and an mg command, then creates a keybinding in the appropriate map. delete-backward-char Delete backwards n characters. Like delete-char, this actually does a kill if presented with an argument. delete-blank-lines Delete blank lines around dot. If dot is sitting on a blank line, this command deletes all the blank lines above and below the current line. Otherwise, it deletes all of the blank lines after the current line. delete-char Delete n characters forward. If any argument is present, it kills rather than deletes, saving the result in the kill buffer. delete-horizontal-space Delete any whitespace around the dot. delete-leading-space Delete leading whitespace on the current line. delete-trailing-space Delete trailing whitespace on the current line. delete-matching-lines Delete all lines after dot that contain a string matching the supplied regular expression. delete-non-matching-lines Delete all lines after dot that contain a string matching the supplied regular expression. delete-other-windows Make the current window the only window visible on the screen. delete-window Delete current window. describe-bindings List all global and local keybindings, putting the result in the *help* buffer. describe-key-briefly Read a key from the keyboard, and look it up in the keymap. Display the name of the function currently bound to the key. digit-argument Process a numerical argument for keyboard-invoked functions. downcase-region Set all characters in the region to lower case. downcase-word Set characters to lower case, starting at the dot, and ending n words away. emacs-version Return an mg version string. end-kbd-macro Stop defining a keyboard macro. end-of-buffer Move cursor to the end of the buffer. end-of-line Move cursor to the end of the line. enlarge-window Enlarge the current window by shrinking either the window above or below it. eval-current-buffer Evaluate the current buffer as a series of mg commands. Useful for testing mg startup files. eval-expression Get one line from the user, and run it. Useful for testing expressions in mg startup files. exchange-point-and-mark Swap the values of "dot" and "mark" in the current window. Return an error if no mark is set. execute-extended-command Invoke an extended command; i.e. M-x. Call the message line routine to read in the command name and apply autocompletion to it. When it comes back, look the name up in the symbol table and run the command if it is found, passing arguments as necessary. Print an error if there is anything wrong. fill-paragraph Justify a paragraph, wrapping text at the current fill column. find-file Select a file for editing. First check if the file can be found in another buffer; if it is there, just switch to that buffer. If the file cannot be found, create a new buffer, read in the file from disk, and switch to the new buffer. find-file-read-only Same as find-file, except the new buffer is set to read-only. find-alternate-file Replace the current file with an alternate one. Semantics for finding the replacement file are the same as find-file, except the current buffer is killed before the switch. If the kill fails, or is aborted, revert to the original file. find-file-other-window Opens the specified file in a second buffer. Splits the current window if necessary. forward-char Move cursor forwards (or backwards, if n is negative) n characters. Returns an error if the end of buffer is reached. forward-paragraph Move forward n paragraphs. Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>. forward-word Move the cursor forward by the specified number of words. global-set-key Bind a key in the global (fundamental) key map. global-unset-key Unbind a key from the global (fundamental) key map; i.e. set it to 'rescan'. global-wd-mode Toggle global working-directory mode. When enabled, mg defaults to opening files (and executing commands like compile and grep) relative to the global working directory. When disabled, a working directory is set for each buffer. goto-line Go to a specific line. If an argument is present, then it is the line number, else prompt for a line number to use. help-help Prompts for one of (a)propos, (b)indings, des(c)ribe key briefly. insert Insert a string, mainly for use from macros. insert-buffer Insert the contents of another buffer at dot. insert-file Insert a file into the current buffer at dot. insert-with-wrap Insert the bound character with word wrap. Check to see if we're past the fill column, and if so, justify this line. isearch-backward Use incremental searching, initially in the reverse direction. isearch ignores any explicit arguments. If invoked during macro definition or evaluation, the non- incremental search-backward is invoked instead. isearch-forward Use incremental searching, initially in the forward direction. isearch ignores any explicit arguments. If invoked during macro definition or evaluation, the non- incremental search-forward is invoked instead. join-line Join the current line to the previous. If called with an argument, join the next line to the current one. just-one-space Delete any whitespace around dot, then insert a space. keyboard-quit Abort the current action. kill-buffer Dispose of a buffer, by name. If the buffer name does not start and end with an asterisk, prompt the user if the buffer has been changed. kill-line Kill line. If called without an argument, it kills from dot to the end of the line, unless it is at the end of the line, when it kills the newline. If called with an argument of 0, it kills from the start of the line to dot. If called with a positive argument, it kills from dot forward over that number of newlines. If called with a negative argument it kills any text before dot on the current line, then it kills back abs(n) lines. kill-paragraph Delete n paragraphs starting with the current one. kill-region Kill the currently defined region. kill-word Delete forward n words. line-number-mode Toggle whether line and column numbers are displayed in the modeline. list-buffers Display the list of available buffers. load Prompt the user for a filename, and then execute commands from that file. local-set-key Bind a key mapping in the local (topmost) mode. local-unset-key Unbind a key mapping in the local (topmost) mode. make-backup-files Toggle generation of backup files. meta-key-mode When disabled, the meta key can be used to insert extended-ascii (8-bit) characters. When enabled, the meta key acts as usual. negative-argument Process a negative argument for keyboard-invoked functions. newline Insert a newline into the current buffer. newline-and-indent Insert a newline, then enough tabs and spaces to duplicate the indentation of the previous line. Assumes tabs are every eight characters. next-line Move forward n lines. no-tab-mode Toggle notab mode. In this mode, spaces are inserted rather than tabs. not-modified Turn off the modified flag in the current buffer. open-line Open up some blank space. Essentially, insert n newlines, then back up over them. other-window The command to make the next (down the screen) window the current window. There are no real errors, although the command does nothing if there is only 1 window on the screen. overwrite-mode Toggle overwrite mode, where typing in a buffer overwrites existing characters rather than inserting them. prefix-region Inserts a prefix string before each line of a region. The prefix string is settable by using 'set-prefix-string'. previous-line Move backwards n lines. previous-window This command makes the previous (up the screen) window the current window. There are no errors, although the command does not do a lot if there is only 1 window. push-shell Suspend mg and switch to alternate screen, if available. pwd Display current (global) working directory in the status area. query-replace Query Replace. Search and replace strings selectively, prompting after each match. replace-string Replace string globally without individual prompting. query-replace-regexp Replace strings selectively. Does a search and replace operation using regular expressions for both patterns. quoted-insert Insert the next character verbatim into the current buffer; i.e. ignore any function bound to that key. re-search-again Perform a regular expression search again, using the same search string and direction as the last search command. re-search-backward Search backwards using a regular expression. Get a search string from the user, and search, starting at dot and proceeding toward the front of the buffer. If found, dot is left pointing at the first character of the pattern [the last character that was matched]. re-search-forward Search forward using a regular expression. Get a search string from the user and search for it starting at dot. If found, move dot to just after the matched characters. display does all the hard stuff. If not found, it just prints a message. recenter Reposition dot in the current window. By default, the dot is centered. If given a positive argument (n), the display is repositioned to line n. If n is negative, it is that line from the bottom. redraw-display Refresh the display. Recomputes all window sizes in case something has changed. save-buffer Save the contents of the current buffer if it has been changed, optionally creating a backup copy. save-buffers-kill-emacs Offer to save modified buffers and quit mg. save-some-buffers Look through the list of buffers, offering to save any buffer that has been changed. Buffers that are not associated with files (such as *scratch*, *grep*, *compile*) are ignored. scroll-down Scroll backwards n pages. A two-line overlap between pages is assumed. If given a repeat argument, scrolls back lines, not pages. scroll-one-line-down Scroll the display down n lines without changing the cursor position. scroll-one-line-up Scroll the display n lines up without moving the cursor position. scroll-other-window Scroll the next window in the window list window forward n pages. scroll-up Scroll forward one page. A two-line overlap between pages is assumed. If given a repeat argument, scrolls back lines, not pages. search-again Search again, using the same search string and direction as the last search command. search-backward Reverse search. Get a search string from the user, and search, starting at dot and proceeding toward the front of the buffer. If found, dot is left pointing at the first character of the pattern (the last character that was matched). search-forward Search forward. Get a search string from the user, and search for it starting at dot. If found, dot gets moved to just after the matched characters, if not found, print a message. self-insert-command Insert a character. set-case-fold-search Set case-fold searching, causing case nopt to matter in regular expression searches. This is the default. set-default-mode Append the supplied mode to the list of default modes used by subsequent buffer creation. Built in modes include: fill, indent, overwrite, and notab. set-fill-column Prompt the user for a fill column. Used by auto-fill-mode. set-mark-command Sets the mark in the current window to the current dot location. set-prefix-string Sets the prefix string to be used by the 'prefix-region' command. shrink-window Shrink current window by one line. The window immediately below is expanded to pick up the slack. If only one window is present, this command has no effect. space-to-tabstop Insert enough spaces to reach the next tab-stop position. By default, tab-stops occur every 8 characters. split-window-vertically Split the current window. A window smaller than 3 lines cannot be split. start-kbd-macro Start defining a keyboard macro. Macro definition is ended by invoking end-kbd- macro. suspend-emacs Suspend mg and switch back to alternate screen, if in use. switch-to-buffer Prompt and switch to a new buffer in the current window. switch-to-buffer-other-window Switch to buffer in another window. toggle-read-only Toggle the read-only flag on the current buffer. transpose-chars Transpose the two characters on either side of dot. If dot is at the end of the line, transpose the two characters before it. Return with an error if dot is at the beginning of line; it seems to be a bit pointless to make this work. undo Undo the most recent action. If invoked again without an intervening command, move the undo pointer to the previous action and undo it. undo-boundary Add an undo boundary. This is not usually done interactively. undo-boundary-toggle Toggle whether undo boundaries are generated. Undo boundaries are often disabled before operations that should be considered atomically undoable. undo-enable Toggle whether undo information is kept. undo-list Show the undo records for the current buffer in a new buffer. universal-argument Repeat the next command 4 times. Usually bound to C-u. This command may be stacked; e.g. C-u C-u C-f moves the cursor forward 16 characters. upcase-region Upper case region. Change all of the lower case characters in the region to upper case. upcase-word Move the cursor forward by the specified number of words. As it moves, convert any characters to upper case. what-cursor-position Display a bunch of useful information about the current location of dot. The character under the cursor (in octal), the current line, row, and column, and approximate position of the cursor in the file (as a percentage) is displayed. The column position assumes an infinite position display; it does not truncate just because the screen does. write-file Ask for a file name and write the contents of the current buffer to that file. Update the remembered file name and clear the buffer changed flag. yank Yank text from kill-buffer. Unlike emacs, the mg kill buffer consists only of the most recent kill. It is not a ring.
CONFIGURATION FILES
There are two configuration files, .mg, and .mg-TERM. Here, TERM represents the name of the terminal type; e.g., if the terminal type is set to “vt100”, mg will use .mg-vt100 as a startup file. The terminal type startup file is used first. The startup file format is a list of commands, one per line, as used for interactive evaluation. Strings that are normally entered by the user at any subsequent prompts may be specified after the command name; e.g.: global-set-key ")" self-insert-command global-set-key "\^x\^f" find-file global-set-key "\e[Z" backward-char set-default-mode fill set-fill-column 72 auto-execute *.c c-mode
FILES
~/.mg normal startup file ~/.mg-TERM terminal-specific startup file /usr/share/doc/mg/tutorial concise tutorial
SEE ALSO
vi(1)
CAVEATS
Since it is written completely in C, there is currently no language in which extensions can be written; however, keys can be rebound and certain parameters can be changed in startup files. In order to use 8-bit characters (such as German umlauts), the Meta key needs to be disabled via the “meta-key-mode” command.