LinuxCommandLibrary

emacs

Edit text files

TLDR

Start Emacs and open a file

$ emacs [path/to/file]
copy

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

Run an Emacs Lisp file as a script
$ emacs --script [path/to/file.el]
copy

Start Emacs in console mode (without an X window)
$ emacs [[-nw|--no-window-system]]
copy

Start an Emacs server in the background (accessible via emacsclient)
$ emacs --daemon
copy

Stop a running Emacs server and all its instances, asking for confirmation on unsaved files
$ emacsclient --eval '(save-buffers-kill-emacs)'
copy

Save a file in Emacs
$ <Ctrl x><Ctrl s>
copy

Quit Emacs
$ <Ctrl x><Ctrl c>
copy

SYNOPSIS

emacs [options] [files …]

PARAMETERS

-h, --help
    Display help message and exit

-V, --version
    Display version information and exit

-Q, --quick
    Start quickly without loading init files

-q, --no-init-file
    Do not load ~/.emacs or ~/.emacs.d/init.el

-u , --user=
    Load specified user's init file

-nw, --no-window-system
    Run in terminal without GUI

-t , --terminal=
    Use specified terminal device

-batch
    Run non-interactively (scripting)

-f , --funcall=
    Execute specified Emacs Lisp function

-l , --load=
    Load specified Emacs Lisp file

-L


    Add directory to Lisp load path

--eval=
    Evaluate specified Lisp expression

-geometry=
    Set initial window geometry

DESCRIPTION

Emacs is a powerful, extensible, self-documenting text editor developed as part of the GNU project. It features a full Lisp interpreter (Emacs Lisp) allowing extensive customization and extension through scripts and packages. Emacs supports editing text files, programming in numerous languages with syntax highlighting, indentation, and refactoring tools, as well as integrated features like shells, debuggers, email clients (gnus), calendars (calendar), games, and web browsing via w3m or EWW.

Key strengths include its modal editing capabilities, multiple buffers and windows for multitasking, and vast ecosystem via package managers like MELPA. It runs on terminals (-nw), X11, Wayland, macOS, Windows, and more. Emacs is keyboard-centric with extensive keybindings (e.g., C-x C-s to save), but supports mice and GUIs. Its documentation system (C-h prefix) provides built-in help, tutorials, and info manuals.

While offering unparalleled power for power users, Emacs has a steep learning curve due to its unique interface and Lisp-based extensibility. Community packages extend it into an operating system-like environment ('It's not an editor, it's an OS'). Widely used in programming, academia, and system administration.

CAVEATS

Steep learning curve for beginners; high memory usage with many packages; keyboard-heavy interface may feel alien; potential for complex configurations to break on updates.

CUSTOMIZATION

Primarily via Emacs Lisp in ~/.emacs.d/init.el or ~/.emacs. Use M-x package-install for extensions like Magit (Git), Org-mode (notes/tasks).

KEY CONCEPTS

Buffers (documents), windows (viewports), frames (GUI windows). Modes: major (file/language-specific), minor (features). Tutorials via C-h t.

INVOCATION TIPS

For server mode: emacs --daemon, then emacsclient -t file.txt for fast editing.

HISTORY

Developed by Richard Stallman in 1976 as a set of macros for the TECO editor at MIT. GNU Emacs first released in 1985 as part of the GNU project. Maintained by the Free Software Foundation; current maintainer is Eli Zaretskii. Major versions include Emacs 21 (2001, toolkit unification), Emacs 23 (2007, image support), Emacs 24 (2012, package manager), Emacs 27 (2020, native compilation), Emacs 29 (2023, tree-sitter integration). Evolved into a platform with thousands of packages.

SEE ALSO

vi(1), vim(1), nano(1), micro(1), ne(1)

Copied to clipboard