Emacs in Termux – A Simple Terminal Text Editor

Emacs is a simple and customizable text editor that you can use in the Termux terminal. It gives you many useful tools for writing and editing files. You can use it to create new files, edit code, search text, and more, while its keyboard shortcuts make editing faster. It is useful for working with different types of files in Termux.

Here’s what you can do with Emacs in Termux:

  • Create and edit text files.
  • Write and edit programming code.
  • Jump to a specific line and column.
  • Search and work with large text files.
  • Insert the contents of another file.
  • Run Emacs Lisp expressions.
  • Load Emacs Lisp files.
  • Customize Emacs for your workflow.

Install Emacs in Termux

You can install it in Termux with a single command. Open Termux and run the command below to start the installation.

First, update the Termux packages.

pkg update && pkg upgrade -y

Install Emacs.

pkg install emacs -y

Check the installed version.

emacs --version

That’s it! Emacs is now installed on Termux and you can start using it in the terminal.

Use Emacs in Termux

You can use Emacs with different commands for editing files and changing how the editor starts. Here are some useful commands and shortcuts that are easy to use in Termux.

Run Emacs normally.

emacs

Emacs will open in your Termux terminal.

To open an existing file:

emacs filename.txt

For example:

emacs notes.txt

Create a new file by opening a filename that does not exist:

emacs newfile.txt

Open a file and start at a specific line:

emacs +10 filename.txt

Open a file at a specific line and column:

emacs +10:5 filename.txt

Open Emacs without loading your normal configuration files:

emacs -Q

Change to a directory before starting Emacs:

emacs --chdir ~/Documents

Open a file using the --file option:

emacs --file filename.txt

Insert the contents of a file into the current buffer:

emacs --insert filename.txt

Evaluate an Emacs Lisp expression:

emacs --eval '(message "Hello from Emacs")'

Load an Emacs Lisp file:

emacs --load filename.el

Call an Emacs Lisp function:

emacs --funcall function-name

Show the Emacs help:

emacs --help

Show the installed Emacs version:

emacs --version

You can also use the following common keyboard shortcuts inside Emacs:

  • Ctrl + x, Ctrl + f — Open a file.
  • Ctrl + x, Ctrl + s — Save the current file.
  • Ctrl + x, Ctrl + w — Save the file with a new name.
  • Ctrl + x, Ctrl + c — Exit Emacs.
  • Ctrl + x, Ctrl + e — Evaluate the Emacs Lisp expression before the cursor.
  • Ctrl + g — Cancel the current command.
  • Ctrl + s — Search forward.
  • Ctrl + r — Search backward.
  • Ctrl + a — Move to the beginning of the line.
  • Ctrl + e — Move to the end of the line.
  • Alt + x — Run an Emacs command.

For more information about Emacs command-line options, use:

emacs --help

End Note

Emacs is a simple editor that gives you many useful options for working with files in the Termux terminal. You can use its commands and shortcuts to edit files, write code, and manage your work easily. It can be a helpful editor for your daily file and coding tasks in Termux.

SHARE THIS POST: