GNU Emacs Overview
GNU Emacs

GNU Emacs Overview

What is Emacs( GNU Emacs )?

GNU Emacs is a highly extensible, customizable, and powerful text editor developed by the GNU Project. It was created by Richard Stallman in the 1980s and is now maintained by the GNU Project's Emacs development team. Emacs is often hailed for its versatility, as it provides a wide range of features beyond basic text editing, such as programming environment support, email and news reading, calendar management, and more.

One of the defining features of Emacs is its extensibility, achieved through a built-in Lisp interpreter (Emacs Lisp). Users can customize virtually every aspect of Emacs, from simple key bindings to complex macros and full-fledged extensions. This flexibility has made Emacs a favorite among programmers, writers, and power users who seek a highly personalized and efficient editing environment.

"Extensibility" refers to the ability of a software system to be easily expanded or customized to meet different needs or preferences. In the context of GNU Emacs, its extensibility means that users can modify, enhance, or add new features to the editor beyond what is provided by default. This is typically achieved through programming in Emacs Lisp, the built-in scripting language of Emacs.

Who is Richard Stallman?

Richard Stallman, often known by his initials "RMS," is a prominent figure in the free software movement and a computer programmer and activist. He is perhaps best known for launching the GNU Project and for initiating the development of the GNU operating system, along with founding the Free Software Foundation (FSF).

How to open and save files in Emacs:

To start Emacs by typing emacs in the terminal.

To open a file:

you can open a file by pressing Ctrl + x followed by Ctrl + f (C-x C-f), Emacs will prompt you to enter the path to the file you want to open. You can type the full path or just the file name if it's in the current directory. Press Enter when you're done.

Saving Files:

to save buffer press Ctrl + x followed by Ctrl + s (C-x C-s).

  • If you want to save the buffer to a different location or with a different name, press Ctrl + x followed by Ctrl + w. Emacs will prompt you to enter the new file name or location.
  • You can open multiple files simultaneously in Emacs by repeating the C-x C-f command for each file. To switch between open buffers (files), you can use Ctrl + x followed by Ctrl + b (C-x C-b) to open a buffer list, then navigate and select the buffer you want to switch to.

What is a Buffer in Emacs?

In Emacs, a buffer is a fundamental unit for text editing. A buffer is essentially an area of memory where text is held temporarily while you edit it. When you open a file, Emacs creates a buffer to hold the file's contents. Buffers are not limited to files; they can also be used for other purposes, such as holding the output of commands, displaying help messages, or composing emails.

How to switch from Buffer to the other?

Using C-x b (Switch Buffer):

  • Press C-x b (Control-x followed by b).
  • Emacs will prompt you to enter the name of the buffer you want to switch to. You can start typing the buffer name, and Emacs will provide auto-completion.
  • Press Enter to switch to the selected buffer.

Using C-x C-b (List Buffers):

  • Press C-x C-b (Control-x followed by Control-b).
  • This opens a buffer list in a new window, showing all available buffers.
  • You can navigate through the list using the arrow keys or n (next) and p (previous), and press Enter to switch to the highlighted buffer.

How to use the mark and the point to set the region?

In Emacs, the "mark" and the "point" are used to define a region of text for various operations like cutting, copying, or formatting.

Point: The current position of the cursor.

Mark: A position in the text that you can set to mark one end of a region.

When you set the mark and then move the point, the text between these two positions becomes the region.

Setting the Region: Move to the Start of the Region: Place the cursor at the beginning of the text you want to select.

Set the Mark: Press C-SPC (Control-Space) or C-@ (Control-Shift-2). This sets the mark at the current cursor position.

Move to the End of the Region: Move the cursor to the end of the text you want to select using the arrow keys or any other navigation command. The text between the mark and the point will be highlighted as the region.

How to cut and paste lines and regions?

Once you have defined a region, you can perform various operations on it:

  • Cut (Kill) the Region: C-w (Control-w).
  • Copy the Region: M-w (Meta-w or Alt-w).
  • Paste (Yank) the Region: C-y (Control-y).
  • Delete the Region: C-w (Control-w) will cut the region, effectively deleting it.

How to search forward and backward?

In Emacs, you can search for text both forward and backward using incremental search commands.

Searching Forward:

  1. Start Incremental Search: Press C-s (Control-s).
  2. Enter Search String: Type the text you want to search for. Emacs will highlight the first occurrence of the search string as you type.
  3. Navigate Matches To find the next occurrence, press C-s again, To move to the previous occurrence, press C-r.
  4. Exit Search: Press Enter to leave the cursor at the current match, or C-g to cancel the search and return to the original position.

How to invoke commands by name?

you can invoke commands by their names using the M-x (Meta-x) command. This is useful when you know the name of the command you want to run but do not have it bound to a key combination.

  1. Press M-x: If your keyboard doesn't have an Alt key, you can press Esc followed by x.
  2. Type the Command Name: Start typing the name of the command you want to execute. Emacs provides auto-completion, so you can press Tab to see suggestions or auto-complete the command name.
  3. Execute the Command: Press Enter after typing the command name to execute it.

How to undo changes?

You can undo changes in your text using the undo command. Press C-/ (Control-/) or C-x u (Control-x followed by u). These key bindings are typically mapped to the undo command.

  • On some keyboards, you may need to use C-_ (Control-underscore) instead of C-/.

How to cancel half-entered commands?

In Emacs, if you start entering a command but decide you want to cancel it before completing it, you can do so by pressing C-g (Control-g). This key binding is used to cancel or quit many operations in Emacs.

How to quit Emacs?

Press C-x C-c (Control-x followed by Control-c). This command will prompt you to save any unsaved buffers before closing Emacs. If all buffers are saved or you choose not to save, Emacs will exit.

Handling Unsaved Changes:

  • Press y (yes) to save the changes.
  • Press n (no) to discard the changes.
  • Press C-g (Control-g) to cancel the quit command and stay in Emacs.

Force Quit (if needed):

If you need to quit Emacs without saving, you can use the command M-x kill-emacs.

要查看或添加评论,请登录

Muhammad Morsy的更多文章

  • Introduction to Git

    Introduction to Git

    Version control system Version control: is a system that helps to manage changes to documents, code, and other…

  • play with Vi.

    play with Vi.

    What is vi? The UNIX vi editor is a full-screen editor and has two modes of operation: Command mode: commands which…

  • Linux navigation

    Linux navigation

    What is the Shell? Simply put, the shell is a program that takes commands from the keyboard and gives them to the…

社区洞察

其他会员也浏览了