~/.mg
normal startup file
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.
-b file
Turn on batch mode and execute the mg commands found in the specified file and then terminate.
-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.
-R
Files specified on the command line will be opened read-only.
-u file
Use file as the startup file, instead of the default ~/.mg.
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.
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 command 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.
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.
set-mark-command
beginning-of-line
backward-char
cscope-find-functions-calling-this-function
cscope-find-global-definition
cscope-find-egrep-pattern
cscope-find-this-file
cscope-find-files-including-file
cscope-next-symbol
cscope-prev-symbol
cscope-find-this-symbol
cscope-find-this-text-string
delete-char
end-of-line
forward-char
keyboard-quit
help-help
apropos
describe-bindings
describe-key-briefly
newline-and-indent
kill-line
recenter
newline
next-line
open-line
previous-line
quoted-insert
isearch-backward
isearch-forward
transpose-chars
universal-argument
scroll-up
kill-region
list-buffers
save-buffers-kill-emacs
find-file
dired-jump
keyboard-quit
downcase-region
delete-blank-lines
toggle-read-only
find-file-read-only
save-buffer
upcase-region
find-alternate-file
write-file
exchange-point-and-mark
start-kbd-macro
end-kbd-macro
delete-window
delete-other-windows
split-window-vertically
find-file-other-window
keyboard-quit
switch-to-buffer-other-window
find-file-other-window
what-cursor-position
enlarge-window
next-error
switch-to-buffer
dired
call-last-kbd-macro
set-fill-column
goto-line
mark-whole-buffer
insert-file
kill-buffer
other-window
other-window
previous-window
save-some-buffers
undo
yank
suspend-emacs
scroll-other-window
just-one-space
shell-command
find-tag
pop-tag-mark
query-replace
beginning-of-buffer
end-of-buffer
delete-horizontal-space
join-line
backward-word
capitalize-word
kill-word
forward-word
mark-paragraph
downcase-word
back-to-indentation
fill-paragraph
search-backward
search-forward
transpose-words
upcase-word
scroll-down
copy-region-as-kill
execute-extended-command
zap-to-char
backward-paragraph
shell-command-on-region
forward-paragraph
not-modified
backward-kill-word
undo
blink-and-insert
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”.
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.
aproposHelp Apropos. Prompt the user for a string, open the *help* buffer, and list all mg commands that contain that string.
audible-bellToggle the audible system bell.
auto-executeRegister 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-modeToggle 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.
auto-indent-modeToggle indent mode in the current buffer, where indentation is preserved after a newline. Can be set globally with set-default-mode.
back-to-indentationMove the dot to the first non-whitespace character on the current line.
backup-to-home-directorySave backup copies to a ~/.mg.d directory instead of working directory. Requires make-backup-files to be on.
backward-charMove cursor backwards one character.
backward-kill-wordKill text backwards by n words.
backward-paragraphMove cursor backwards n paragraphs. Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>.
backward-wordMove cursor backwards by the specified number of words.
beginning-of-bufferMove 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.
beginning-of-lineMove cursor to the beginning of the line.
blink-and-insertSelf-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.
bsmap-modeToggle bsmap mode, where DEL and C-h are swapped.
c-modeToggle a KNF-compliant mode for editing C program files.
call-last-kbd-macroInvoke the keyboard macro.
capitalize-wordCapitalize n words; i.e. convert the first character of the word to upper case, and subsequent letters to lower case.
cdChange the global working directory. See also global-wd-mode.
column-number-modeToggle whether the column number is displayed in the modeline.
copy-region-as-killCopy 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-matchesCount the number of lines matching the supplied regular expression.
count-non-matchesCount the number of lines not matching the supplied regular expression.
cscope-find-this-symbolList the matches for the given symbol.
cscope-find-global-definitionList global definitions for the given literal.
cscope-find-called-functionsList functions called from the given function.
cscope-find-functions-calling-this-functionList functions calling the given function.
cscope-find-this-text-stringList locations matching the given text string.
cscope-find-egrep-patternList locations matching the given extended regular expression pattern.
cscope-find-this-fileList filenames matching the given filename.
cscope-find-files-including-fileList files that #include the given filename.
cscope-next-symbolNavigate to the next match.
cscope-prev-symbolNavigate to the previous match.
cscope-next-fileNavigate to the next file.
cscope-prev-fileNavigate to the previous file.
cscope-create-list-of-files-to-indexCreate cscope's List and Index in the given directory.
define-keyPrompts the user for a named keymap (mode), a key, and an mg command, then creates a keybinding in the appropriate map.
delete-backward-charDelete backwards n characters. Like delete-char, this actually does a kill if presented with an argument.
delete-blank-linesDelete 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-charDelete n characters forward. If any argument is present, it kills rather than deletes, saving the result in the kill buffer.
delete-horizontal-spaceDelete any whitespace around the dot.
delete-leading-spaceDelete leading whitespace on the current line.
delete-trailing-spaceDelete trailing whitespace on the current line.
delete-matching-linesDelete all lines after dot that contain a string matching the supplied regular expression.
delete-non-matching-linesDelete all lines after dot that don't contain a string matching the supplied regular expression.
delete-other-windowsMake the current window the only window visible on the screen.
delete-windowDelete current window.
describe-bindingsList all global and local keybindings, putting the result in the *help* buffer.
describe-key-brieflyRead a key from the keyboard, and look it up in the keymap. Display the name of the function currently bound to the key.
diff-buffer-with-fileView the differences between buffer and its associated file.
digit-argumentProcess a numerical argument for keyboard-invoked functions.
dired-jumpOpen a dired buffer containing the current buffer's directory location.
downcase-regionSet all characters in the region to lower case.
downcase-wordSet characters to lower case, starting at the dot, and ending n words away.
emacs-versionReturn an mg version string.
end-kbd-macroStop defining a keyboard macro.
end-of-bufferMove 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.
end-of-lineMove cursor to the end of the line.
enlarge-windowEnlarge the current window by shrinking either the window above or below it.
eval-current-bufferEvaluate the current buffer as a series of mg commands. Useful for testing mg startup files.
eval-expressionGet one line from the user, and run it. Useful for testing expressions in mg startup files.
exchange-point-and-markSwap the values of "dot" and "mark" in the current window. Return an error if no mark is set.
execute-extended-commandInvoke 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-paragraphJustify a paragraph, wrapping text at the current fill column.
find-fileSelect 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-onlySame as find-file, except the new buffer is set to read-only.
find-alternate-fileReplace 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-windowOpens the specified file in a second buffer. Splits the current window if necessary.
find-tagJump to definition of tag at dot.
forward-charMove cursor forwards (or backwards, if n is negative) n characters. Returns an error if the end of buffer is reached.
forward-paragraphMove forward n paragraphs. Paragraphs are delimited by <NL><NL> or <NL><TAB> or <NL><SPACE>.
forward-wordMove the cursor forward by the specified number of words.
global-set-keyBind a key in the global (fundamental) key map.
global-unset-keyUnbind a key from the global (fundamental) key map; i.e. set it to 'rescan'.
global-wd-modeToggle 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-lineGo to a specific line. If an argument is present, then it is the line number, else prompt for a line number to use.
help-helpPrompts for one of (a)propos, (b)indings, des(c)ribe key briefly.
insertInsert a string, mainly for use from macros.
insert-bufferInsert the contents of another buffer at dot.
insert-fileInsert a file into the current buffer at dot.
insert-with-wrapInsert the bound character with word wrap. Check to see if we're past the fill column, and if so, justify this line.
isearch-backwardUse 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-forwardUse 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-lineJoin the current line to the previous. If called with an argument, join the next line to the current one.
just-one-spaceDelete any whitespace around dot, then insert a space.
keyboard-quitAbort the current action.
kill-bufferDispose 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-lineKill 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-paragraphDelete n paragraphs starting with the current one.
kill-regionKill the currently defined region.
kill-wordDelete forward n words.
leave-tmpdir-backupsModifies 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.
line-number-modeToggle whether the line number is displayed in the modeline.
list-buffersDisplay 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.
loadPrompt the user for a filename, and then execute commands from that file.
local-set-keyBind a key mapping in the local (topmost) mode.
local-unset-keyUnbind a key mapping in the local (topmost) mode.
make-backup-filesToggle generation of backup files. Enabled by default.
make-directoryPrompt the user for a path or directory name which is then created.
mark-paragraphMark n paragraphs.
mark-whole-bufferMarks whole buffer as a region by putting dot at the beginning and mark at the end of buffer.
meta-key-modeWhen disabled, the meta key can be used to insert extended-ascii (8-bit) characters. When enabled, the meta key acts as usual.
negative-argumentProcess a negative argument for keyboard-invoked functions.
newlineInsert a newline into the current buffer.
newline-and-indentInsert a newline, then enough tabs and spaces to duplicate the indentation of the previous line, respecting no-tab-mode and the buffer tab width.
next-lineMove forward n lines.
no-tab-modeToggle notab mode. In this mode, spaces are inserted rather than tabs. Can be set globally with set-default-mode.
not-modifiedTurn off the modified flag in the current buffer.
open-lineOpen up some blank space. Essentially, insert n newlines, then back up over them.
other-windowThe 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-modeToggle overwrite mode in the current buffer, where typing overwrites existing characters rather than inserting them. Can be set globally with set-default-mode.
prefix-regionInserts a prefix string before each line of a region. The prefix string is settable by using set-prefix-string or by invoking this command with a prefix argument.
previous-lineMove backwards n lines.
previous-windowThis 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.
pop-tag-markReturn to position where find-tag was previously invoked.
push-shellSuspend mg and switch to alternate screen, if available.
pwdDisplay current (global) working directory in the status area.
query-replaceQuery Replace. Search and replace strings selectively, prompting after each match.
replace-regexpReplace regular expression globally without individual prompting.
replace-stringReplace string globally without individual prompting.
query-replace-regexpReplace strings selectively. Does a search and replace operation using regular expressions for both patterns.
quoted-insertInsert the next character verbatim into the current buffer; i.e. ignore any function bound to that key.
re-search-againPerform a regular expression search again, using the same search string and direction as the last search command.
re-search-backwardSearch 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-forwardSearch 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.
recenterReposition 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-displayRefresh the display. Recomputes all window sizes in case something has changed.
revert-bufferRevert the current buffer to the latest file on disk.
save-bufferSave the contents of the current buffer if it has been changed, optionally creating a backup copy.
save-buffers-kill-emacsOffer to save modified buffers and quit mg.
save-some-buffersLook 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-downScroll backwards n pages. A two-line overlap between pages is assumed. If given a repeat argument, scrolls back lines, not pages.
scroll-one-line-downScroll the display down n lines without changing the cursor position.
scroll-one-line-upScroll the display n lines up without moving the cursor position.
scroll-other-windowScroll the next window in the window list window forward n pages.
scroll-upScroll forward one page. A two-line overlap between pages is assumed. If given a repeat argument, scrolls back lines, not pages.
search-againSearch again, using the same search string and direction as the last search command.
search-backwardReverse 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-forwardSearch 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-commandInsert a character.
sentence-end-double-spaceToggle double or single spaces for end of sentences. Double is the default. Currently only affects fill-paragraph.
set-case-fold-searchSet case-fold searching, causing case not to matter in regular expression searches. This is the default.
set-case-replacePreserve the case of the replaced string. This is the default.
set-default-modeAppend the supplied mode to the list of default modes used by subsequent buffer creation. Built in modes include: fill, indent, notab and overwrite.
set-fill-columnPrompt the user for a fill column. Used by auto-fill-mode.
set-mark-commandSets the mark in the current window to the current dot location.
set-prefix-stringSets the prefix string to be used by the prefix-region command.
set-tab-widthSet the tab width for the current buffer, or the default for new buffers if called with a prefix argument or from the startup file.
shell-commandExecute external command from mini-buffer. With a universal argument it inserts the command output into the current buffer.
shell-command-on-regionProvide the text in region to the shell command as input. With a universal argument it replaces the region with the command output.
shrink-windowShrink 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-tabstopInsert enough spaces to reach the next tab-stop position. By default, tab-stops occur every 8 characters.
split-window-verticallySplit the current window. A window smaller than 3 lines cannot be split.
start-kbd-macroStart defining a keyboard macro. Macro definition is ended by invoking end-kbd-macro.
suspend-emacsSuspend mg and switch back to alternate screen, if in use.
switch-to-bufferPrompt and switch to a new buffer in the current window.
switch-to-buffer-other-windowSwitch to buffer in another window.
toggle-read-onlyToggle the read-only flag on the current buffer.
toggle-read-only-allToggle the read-only flag on all non-ephemeral buffers. A simple toggle that switches a global read-only flag either on or off.
transpose-charsTranspose the two characters in front of and under dot, then move forward one character. Treat newline characters the same as any other.
transpose-paragraphsTranspose adjacent paragraphs. If multiple iterations are requested, the current paragraph will be moved n paragraphs forward.
transpose-wordsTranspose adjacent words.
undoUndo the most recent action. If invoked again without an intervening command, move the undo pointer to the previous action and undo it.
undo-boundaryAdd an undo boundary. This is not usually done interactively.
undo-boundary-toggleToggle whether undo boundaries are generated. Undo boundaries are often disabled before operations that should be considered atomically undoable.
undo-enableToggle whether undo information is kept.
undo-listShow the undo records for the current buffer in a new buffer.
universal-argumentRepeat 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-regionUpper case region. Change all of the lower case characters in the region to upper case.
upcase-wordMove the cursor forward by the specified number of words. As it moves, convert any characters to upper case.
visible-bellToggle the visible bell. If this toggle is on, the modeline will flash.
visit-tags-tableLoad tags file to be used for subsequent find-tag.
what-cursor-positionDisplay 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-fileAsk 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.
yankYank text from kill-buffer. Unlike emacs, the mg kill buffer consists only of the most recent kill. It is not a ring.
zap-to-charAsk for a character and delete text from the current cursor position until the next instance of that character, including it.
zap-up-to-charLike zap-to-char but doesn't delete the target character.
Specific key bindings are available in dired mode.
dired-unmark-backward
dired-find-file
dired-next-line
dired-shell-command
dired-create-directory
dired-up-directory
dired-find-alternate-file
dired-do-copy
dired-flag-file-deletion
dired-revert
dired-goto-file
dired-find-file-other-window
dired-previous-line
quit-window
dired-do-rename
dired-unmark
dired-do-flagged-delete
dired-scroll-down
dired-scroll-up
The following are a list of the commands specific to dired mode:
dired-create-directoryCreate a directory.
dired-do-copyCopy the file listed on the current line of the dired buffer.
dired-do-flagged-deleteDelete the files that have been flagged for deletion.
dired-do-renameRename the file listed on the current line of the dired buffer.
dired-find-alternate-fileReplace the current dired buffer with an alternate one as specified by the position of the cursor in the dired buffer.
dired-find-fileOpen the file on the current line of the dired buffer. If the cursor is on a directory, it will be opened in dired mode.
dired-flag-file-deletionFlag 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.
dired-find-file-other-windowOpen the file on the current line of the dired buffer in a different window.
dired-goto-fileMove the cursor to a file name in the dired buffer.
dired-next-lineMove the cursor to the next line.
dired-other-windowThis function works just like dired, except that it puts the dired buffer in another window.
dired-previous-lineMove the cursor to the previous line.
dired-revertRefresh the dired buffer while retaining any flags.
dired-scroll-downScroll down the dired buffer.
dired-scroll-upScroll up the dired buffer.
dired-shell-commandPipe the file under the current cursor position through a shell command.
dired-unmarkRemove the deletion flag for the file on the current line.
dired-unmark-backwardRemove the deletion flag from the file listed on the previous line of the dired buffer, then move up to that line.
dired-up-directoryOpen a dired buffer in the parent directory.
quit-windowClose 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 ")" 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
Comments can be added to the startup files by placing ‘;’ or ‘#’ as the first character of a line.
~/.mg
normal startup file
~/.mg-TERM
terminal-specific startup file
~/.mg.d
alternative backup file location
/usr/share/doc/mg/tutorial
concise tutorial
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.
11 releases since Debian 4.0 (Etch); the text changed 9 times.
-R since Debian 9 (Stretch);
-b since Debian 12 (Bookworm);
-u since Debian 12 (Bookworm).