MG(1) BSD General Commands Manual MG(1)
mg — emacs-like text editor
mg [−nR] [−b file] [−f mode] [−u file] [+number] [file ...]
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:
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.
Turn on batch mode and execute the mg commands found in the specified file and then terminate.
Run the mode command for all buffers created from arguments on the command line, including the scratch buffer and all files.
Turn off backup file generation.
Files specified on the command line will be opened read-only.
Use file as the startup file, instead of the default ~/.mg.
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 file is changed outside mg and its buffer is about to be changed, mg prompts if the change should go ahead (y), not go ahead (n) or if the buffer should be reverted (r) to the latest file on disk.
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.
Backup files have a ‘~’ character appended to the file name and are created in the current working directory by default. Whether to create backup files or not can be toggled with the make-backup-files command. The backup file location can either be in the current working directory, or all backups can be moved to a ~/.mg.d directory where files retain their path name to retain uniqueness. Use the backup-to-home-directory to alternate between these two locations. Further, if any application creates backup files in /tmp, these can be left with the leave-tmpdir-backups command.
mg supports tag files created by ctags(1), allowing the user to quickly locate various object definitions. Note though that emacs uses etags, not ctags.
mg supports navigating source code using cscope. However, mg requires cscope and cscope-indexer executables to be present in PATH for it to work.
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-c s c
C-c s d
C-c s e
C-c s f
C-c s i
C-c s n
C-c s p
C-c s s
C-c s t
C-x 4 C-f
C-x 4 C-g
C-x 4 b
C-x 4 f
For a complete description of mg commands, see MG COMMANDS. To see the active keybindings at any time, type “M-x describe-bindings”.
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.
Help Apropos. Prompt the user for a string, open the *help* buffer, and list all mg commands that contain that string.
Toggle the audible system bell.
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.
Toggle auto-fill mode (sometimes called mail-mode) in the current buffer, where text inserted past the fill column is automatically wrapped to a new line. Can be set globally with set-default-mode.
Toggle indent mode in the current buffer, where indentation is preserved after a newline. Can be set globally with set-default-mode.
Move the dot to the first non-whitespace character on the current line.
Save backup copies to a ~/.mg.d directory instead of working directory. Requires make-backup-files to be on.
Move cursor backwards one character.
Kill text backwards by n words.
Move cursor backwards n paragraphs. Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>.
Move cursor backwards by the specified number of words.
Move cursor to the top of the buffer. If set, keep mark’s position, otherwise set at current position. A numeric argument n will move n/10th of the way from the top.
Move cursor to the beginning of the line.
Self-insert a character, then search backwards and blink its matching delimiter. For delimiters other than parenthesis, brackets, and braces, the character itself is used as its own match. Can be used in the startup file with the global-set-key command.
Toggle bsmap mode, where DEL and C-h are swapped.
Toggle a KNF-compliant mode for editing C program files.
Invoke the keyboard macro.
Capitalize n words; i.e. convert the first character of the word to upper case, and subsequent letters to lower case.
Change the global working directory. See also global-wd-mode.
Toggle whether the column number is displayed in the modeline.
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 the number of lines matching the supplied regular expression.
Count the number of lines not matching the supplied regular expression.
List the matches for the given symbol.
List global definitions for the given literal.
List functions called from the given function.
List functions calling the given function.
List locations matching the given text string.
List locations matching the given extended regular expression pattern.
List filenames matching the given filename.
List files that #include the given filename.
Navigate to the next match.
Navigate to the previous match.
Navigate to the next file.
Navigate to the previous file.
Create cscope’s List and Index in the given directory.
Prompts the user for a named keymap (mode), a key, and an mg command, then creates a keybinding in the appropriate map.
Delete backwards n characters. Like delete-char, this actually does a kill if presented with an argument.
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 n characters forward. If any argument is present, it kills rather than deletes, saving the result in the kill buffer.
Delete any whitespace around the dot.
Delete leading whitespace on the current line.
Delete trailing whitespace on the current line.
Delete all lines after dot that contain a string matching the supplied regular expression.
Delete all lines after dot that don’t contain a string matching the supplied regular expression.
Make the current window the only window visible on the screen.
Delete current window.
List all global and local keybindings, putting the result in the *help* buffer.
Read a key from the keyboard, and look it up in the keymap. Display the name of the function currently bound to the key.
View the differences between buffer and its associated file.
Process a numerical argument for keyboard-invoked functions.
Open a dired buffer containing the current buffer’s directory location.
Set all characters in the region to lower case.
Set characters to lower case, starting at the dot, and ending n words away.
Return an mg version string.
Stop defining a keyboard macro.
Move cursor to the end of the buffer. If set, keep mark’s position, otherwise set at current position. A numeric argument n will move n/10th of the way from the end.
Move cursor to the end of the line.
Enlarge the current window by shrinking either the window above or below it.
Evaluate the current buffer as a series of mg commands. Useful for testing mg startup files.
Get one line from the user, and run it. Useful for testing expressions in mg startup files.
Swap the values of "dot" and "mark" in the current window. Return an error if no mark is set.
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.
Justify a paragraph, wrapping text at the current fill column.
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.
Same as find-file, except the new buffer is set to read-only.
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.
Opens the specified file in a second buffer. Splits the current window if necessary.
Jump to definition of tag at dot.
Move cursor forwards (or backwards, if n is negative) n characters. Returns an error if the end of buffer is reached.
Move forward n paragraphs. Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>.
Move the cursor forward by the specified number of words.
Bind a key in the global (fundamental) key map.
Unbind a key from the global (fundamental) key map; i.e. set it to ’rescan’.
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.
Go to a specific line. If an argument is present, then it is the line number, else prompt for a line number to use.
Prompts for one of (a)propos, (b)indings, des(c)ribe key briefly.
Insert a string, mainly for use from macros.
Insert the contents of another buffer at dot.
Insert a file into the current buffer at dot.
Insert the bound character with word wrap. Check to see if we’re past the fill column, and if so, justify this line.
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.
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 the current line to the previous. If called with an argument, join the next line to the current one.
Delete any whitespace around dot, then insert a space.
Abort the current action.
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. 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.
Delete n paragraphs starting with the current one.
Kill the currently defined region.
Delete forward n words.
Modifies the behaviour of backup-to-home-directory. Backup files that would normally reside in /tmp are left there and not moved to the ~/.mg.d directory.
Toggle whether the line number is displayed in the modeline.
Display the list of available buffers. The first column in the output indicates which buffer is active with a ’>’ character. The second column indicates which buffers are modified. The third column indicates which buffers are read-only. The remaining columns are self-explanatory.
Prompt the user for a filename, and then execute commands from that file.
Bind a key mapping in the local (topmost) mode.
Unbind a key mapping in the local (topmost) mode.
Toggle generation of backup files. Enabled by default.
Prompt the user for a path or directory name which is then created.
Mark n paragraphs.
Marks whole buffer as a region by putting dot at the beginning and mark at the end of buffer.
When disabled, the meta key can be used to insert extended-ascii (8-bit) characters. When enabled, the meta key acts as usual.
Process a negative argument for keyboard-invoked functions.
Insert a newline into the current buffer.
Insert a newline, then enough tabs and spaces to duplicate the indentation of the previous line. Assumes tabs are every eight characters.
Move forward n lines.
Turn off the modified flag in the current buffer.
Open up some blank space. Essentially, insert n newlines, then back up over them.
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.
Toggle overwrite mode in the current buffer, where typing overwrites existing characters rather than inserting them. Can be set globally with set-default-mode.
Inserts a prefix string before each line of a region. The prefix string is settable by using ’set-prefix-string’.
Move backwards n lines.
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.
Return to position where find-tag was previously invoked.
Suspend mg and switch to alternate screen, if available.
Display current (global) working directory in the status area.
Query Replace. Search and replace strings selectively, prompting after each match.
Replace regular expression globally without individual prompting.
Replace string globally without individual prompting.
Replace strings selectively. Does a search and replace operation using regular expressions for both patterns.
Insert the next character verbatim into the current buffer; i.e. ignore any function bound to that key.
Perform a regular expression search again, using the same search string and direction as the last search command.
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].
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.
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.
Refresh the display. Recomputes all window sizes in case something has changed.
Revert the current buffer to the latest file on disk.
Save the contents of the current buffer if it has been changed, optionally creating a backup copy.
Offer to save modified buffers and quit mg.
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 backwards n pages. A two-line overlap between pages is assumed. If given a repeat argument, scrolls back lines, not pages.
Scroll the display down n lines without changing the cursor position.
Scroll the display n lines up without moving the cursor position.
Scroll the next window in the window list window forward n pages.
Scroll forward one page. A two-line overlap between pages is assumed. If given a repeat argument, scrolls back lines, not pages.
Search again, using the same search string and direction as the last search command.
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. 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.
Insert a character.
Toggle double or single spaces for end of sentences. Double is the default. Currently only affects fill-paragraph.
Set case-fold searching, causing case not to matter in regular expression searches. This is the default.
Preserve the case of the replaced string. This is the default.
Append the supplied mode to the list of default modes used by subsequent buffer creation. Built in modes include: fill, indent and overwrite.
Prompt the user for a fill column. Used by auto-fill-mode.
Sets the mark in the current window to the current dot location.
Sets the prefix string to be used by the ’prefix-region’ command.
Execute external command from mini-buffer.
Provide the text in region to the shell command as input.
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.
Split the current window. A window smaller than 3 lines cannot be split.
Start defining a keyboard macro. Macro definition is ended by invoking end-kbd-macro.
Suspend mg and switch back to alternate screen, if in use.
Prompt and switch to a new buffer in the current window.
Switch to buffer in another window.
Toggle the read-only flag on the current buffer.
Toggle the read-only flag on all non-ephemeral buffers. A simple toggle that switches a global read-only flag either on or off.
Transpose the two characters in front of and under dot, then move forward one character. Treat newline characters the same as any other.
Transpose adjacent paragraphs. If multiple iterations are requested, the current paragraph will be moved n paragraphs forward.
Transpose adjacent words.
Undo the most recent action. If invoked again without an intervening command, move the undo pointer to the previous action and undo it.
Add an undo boundary. This is not usually done interactively.
Toggle whether undo boundaries are generated. Undo boundaries are often disabled before operations that should be considered atomically undoable.
Toggle whether undo information is kept.
Show the undo records for the current buffer in a new buffer.
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.
Upper case region. Change all of the lower case characters in the region to upper case.
Move the cursor forward by the specified number of words. As it moves, convert any characters to upper case.
Toggle the visible bell. If this toggle is on, the modeline will flash.
Record name of the tags file to be used for subsequent find-tag.
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.
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 text from kill-buffer. Unlike emacs, the mg kill buffer consists only of the most recent kill. It is not a ring.
Ask for a character and delete text from the current cursor position until the next instance of that character, including it.
Like zap-to-char but doesn’t delete the target character.
MG DIRED KEY BINDINGS
Specific key bindings are available in dired mode.
RET, e, f and C-m
d and C-d
MG DIRED COMMANDS
The following are a list of the commands specific to dired mode:
Create a directory.
Copy the file listed on the current line of the dired buffer.
Delete the files that have been flagged for deletion.
Rename the file listed on the current line of the dired buffer.
Replace the current dired buffer with an alternate one as specified by the position of the cursor in the dired buffer.
Open the file on the current line of the dired buffer. If the cursor is on a directory, it will be opened in dired mode.
Flag the file listed on the current line for deletion. This is indicated in the buffer by putting a D at the left margin. No files are actually deleted until the function dired-do-flagged-delete is executed.
Open the file on the current line of the dired buffer in a different window.
Move the cursor to a file name in the dired buffer.
Move the cursor to the next line.
This function works just like dired, except that it puts the dired buffer in another window.
Move the cursor to the previous line.
Refresh the dired buffer while retaining any flags.
Scroll down the dired buffer.
Scroll up the dired buffer.
Pipe the file under the current cursor position through a shell command.
Remove the deletion flag for the file on the current line.
Remove the deletion flag from the file listed on the previous line of the dired buffer, then move up to that line.
Close the current dired buffer.
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 "\^x\^f" find-file
global-set-key "\e[Z" backward-char
auto-execute *.c c-mode
Comments can be added to the startup files by placing ‘;’ or ‘#’ as the first character of a line.
normal startup file
terminal-specific startup file
alternative backup file location
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.
Multi-byte character sets, such as UTF-8, are not supported.
BSD October 20, 2022 BSD