LinuxCommandLibrary

mg

Edit text files

TLDR

Open a file for editing

$ mg [path/to/file]
copy

Open a file at a specified line number
$ mg +[line_number] [path/to/file]
copy

Open files in a read-only mode
$ mg -R [path/to/file1 path/to/file2 ...]
copy

Disable ~ backup files while editing
$ mg -n [path/to/file]
copy

SYNOPSIS

mg [options] [file...]

PARAMETERS

file...
    One or more files to open upon launching the editor. If no files are specified, mg starts with an empty buffer.

-f function
    Execute the specified function immediately after startup. This is useful for running custom Emacs Lisp commands.

-l file
    Load the specified file after mg's initialization file (~/.mg or ~/.emacs) has been loaded. This allows for additional configuration or script execution.

-u user
    Use ~/.mg as the initialization file, rather than attempting to auto-detect ~/.emacs. This ensures a consistent startup behavior for mg-specific configurations.

-q
    Do not load the initialization file (~/.mg or ~/.emacs). This is useful for troubleshooting or for starting mg with a clean slate.

+N
    Start the editor with the cursor positioned at line N of the first specified file. For example, mg +10 filename will open filename at line 10.

-V, --version
    Print the version information of mg and then exit.

-h, --help
    Display a brief help message summarizing command-line options and then exit.

-nw
    Force mg to run in a non-windowed (terminal) mode, even if an X11 display is available. This ensures text-based interaction.

DESCRIPTION

The mg command is a lightweight, portable, and fast text editor designed to mimic the core functionality and keybindings of GNU Emacs. It aims to provide a comfortable Emacs-like editing experience without the overhead of a full Emacs installation. mg is particularly suitable for systems where resources are limited or where users prefer a more minimalist editor with familiar Emacs keyboard shortcuts.

It offers essential features such as buffer management, file operations, search and replace, and basic customization through an Emacs Lisp-like configuration file, typically .mg or .emacs, in the user's home directory. While not a full Emacs replacement, mg serves as an excellent alternative for developers and users who primarily need efficient text editing capabilities.

CAVEATS

mg is designed to be lightweight and therefore does not implement the full range of features found in GNU Emacs. It lacks support for many advanced Emacs Lisp packages, complex modes, and integrated tools like Dired or Org-mode. Users expecting a complete Emacs environment may find mg's capabilities limited. Its Emacs Lisp interpreter supports only a subset of functions, primarily for basic configuration and simple extensions.

CUSTOMIZATION

mg can be customized by placing a configuration file named .mg or .emacs in your home directory. This file uses a subset of Emacs Lisp syntax to define keybindings, load functions, and set variables, allowing users to tailor the editor to their preferences. Changes made in this file are applied upon mg's startup.

KEYBINDINGS

One of mg's primary strengths is its adherence to traditional Emacs keybindings. Users familiar with GNU Emacs will find most common commands, such as C-x C-s (save), C-x C-c (exit), C-s (search), and C-k (kill line), to be identical. This consistency provides a seamless transition for Emacs users seeking a lighter editor.

HISTORY

mg, short for MicroGnuEmacs, originated as a fork of MicroEmacs by Dave Conroy, aiming to create a tiny, fast, and portable editor with Emacs-like keybindings. It was later adopted and further developed, notably by the NetBSD pkgsrc project. Its primary goal has always been to provide a minimal, yet functional, Emacs-compatible editing experience for environments where a full Emacs installation might be impractical due to size or resource constraints. This focus on efficiency and portability has maintained its relevance over the years.

SEE ALSO

emacs(1), vi(1), nano(1), jed(1)

Copied to clipboard