You are on page 1of 8

emacs command in Linux

Introduction to Emacs Editor in Linux/Unix Systems

 The Emacs is referred to a family of editors, which means it has many


versions or flavors or iterations.
 The most commonly used version of Emacs editor is GNU Emacs and
was created by Richard Stallman.
 The main difference between text editors like vi, vim, nano, and the
Emacs is that is faster, powerful, and simple in terms of usage
because of its simple user interface.
 Unlike the vi editor, the Emacs editor does not use an insert mode,
and it is by default in editing mode, i.e., whatever you type will directly
be written to the buffer, unless you manually enter command mode by
using keyboard shortcuts.

Installing the Emacs Editor:


 Ubuntu / Debian:
sudo apt-get install emacs
 Redhat / CentOS and Derivatives:
yum install emacs

If the above method doesn’t work for you or you want to manually compile
emacs, follow these steps:
 STEP 1: Download the latest version (26.1) of source code from the gnu
server with following command:
curl https://ftp.gnu.org/pub/gnu/emacs/emacs-26.1.tar.gz
/emacs/emacs-26.1.tar.gz
 STEP 2: Extract the tar.gz file.
tar -zxvf emacs-26.1.tar.gz
 STEP 3: Install Prerequisites.
 sudo apt-get update
 sudo apt-get install build-essential libgnutls28-dev libncurses-
dev
 STEP 4: Install Emacs.
 cd /emacs/emacs-26.1/
 ./configure #Configure Emacs
 make #build components using makefile
 sudo make install #Install Emacs
The above steps will install Emacs into your system. To confirm the install,
you can check using terminal using the following command:
emacs --version

Using Emacs Editor


To use emacs editor, use command – emacs [-option] [file name]

Example:
emacs new.txt
Explanation: This command creates a file called new.txt if it doesn’t already
exist.
If the file with that name already exists, it’s content is copied to the memory
buffer and shown at the editing buffer area.

Note: Using the emacs command with no filename opens the default


interface of the emacs editor, as shown in the below image.
This screen is user-friendly and you can navigate using the link options
highlighted in the screen, like the option visit new file creates a new file
buffer for you to start writing.
Emacs Common Options:
1. –file file_name, –find-file file_name, –visit file_name
This option is used to provide file name to edit. However, in most cases,
this is not required and directly file name can be mentioned.
2. +number
The number here specifies the line number in the file which is followed in
the command, and the cursor is moved to that line. There should be no
space between the number and the + sign.
3. +line:column
Here line represents the line number or row and the column represents
the number of characters. The cursor is automatically placed to this
position in the file that is followed.
4. -q, –no-init-file
This option prevents Emacs from loading an initialization or init file.
5. –no-splash
This option prevents Emacs from showing splash screen at startup.
6. -u user, –user user
Load user’s init file.
7. –version
To display version and license information.
8. –help
Display help.
Note: For more options, you can type “ man emacs” or “emacs --help” without
the quotation marks.
Emacs – Common Keyboard Shortcuts
1. General Shortcuts:
 ctrl-x ctrl-f : Find file or Open a file. This command prompts for a file
name and opens it in buffer for editing. Also, it creates a new file if it
doesn’t already exist.
 ctrl-x ctrl-s : Save File. This saves the current buffer content to the
file.
 ctrl-x ctrl-w : Write to file. This command prompts for a file name to
save buffer.
2. Copy, cut and paste shortcuts:
 ctrl-d : Cut the character at the position of cursor.
 ESC d : Cut the word till next blank space from the current position.
 ctrl-k : Cut till end of the line from current position.
 ctrl-@ : Mark the current position as beginning for copy.
 ESC w : copy area between mark and cursor to paste.
 ctrl-y : Yank or Paste the recently copied or cut characters at the
current position of cursor.
3. Search and Replace:
 ctrl-s : Search forward- prompts for a search terms and search it in the
buffer from current cursor position to the end of the buffer.
 ctrl-r : Search backwards/reverse- prompts for a search term and
search from current position to the beginning of the buffer.
 ESC % : Replace- prompts for a search term and a replacement term
and replaces the first occurrence of the word in buffer after cursor.
4. Moving cursor:
 ctrl-a : Beginning of the line.
 ctrl-e : End of line.
 ctrl-f : Move forward by one character.
 ctrl-b : Move back by one character.
 ctrl-n : Move cursor to next line.
 ctrl-p : Cursor to previous line.
 ESC > : End of the buffer.
 ESC < : Starting of the buffer.
 ESC f : Move forward by one word.
 ESC b : Move back by one word.
5. Miscellaneous:
 ctrl-z : Stop Emacs and quit immediately without confirmation(All
changes in buffer are lost).
 ctrl-g : Cancel current command and revert back from command
mode.
 ctrl-x u : undo the last command.
 ctrl-x ctrl-c : Save and quit.
 ctrl-h i : Help in Emacs- describes emacs shortcuts and commands.
Help page inside emacs:
X Window System
What Does X Window System Mean?
The X Window System (X11) is an open source, cross platform, client-
server computer software system that provides a GUI in a distributed
network environment.

Used primarily on Unix variants, X versions are also available for other
operating systems.
Features of the X window system include network transparency, the
ability to link to different networks, and customizable graphical
capabilities.

The X window system was first developed in 1984, as part of project


Athena, a collaboration between Stanford University and MIT.

X.Org Foundation, an open group, manages the development and


standardization of the X window system.

The X protocol has been at version 11 (hence "X11") since September


1987.The X Window System is also known simply as X, X11 or X
Windows.

X Window System
The client/server model in X system works in reverse to typical
client/server model, where the client runs on the local machine and asks
for services from the server.

In X system, the server runs on the local machine and provides its
display and services to the client programs. The client programs may be
local or remotely exist over different networks, but appear transparently.

Architecture

X is used in networks of interconnected mainframes, minicomputers,


workstations, and X Terminals. X window system consists of a number of
interacting components, including:

 X server: Manages the display and input


hardware. It captures command-based and
graphics-based inputs from input hardware
and passes it to the client application that
requested it. It also receives inputs from the
client applications and displays the output
under guidance from windows manager. The
only component that interacts with hardware
is X server. This makes it easier to recode it
as per the requirements of different
hardware architectures.
 Windows manager: Is the client application
that manages client windows. It controls the
general operations of the window system
like geometry, appearance, coordinates, and
graphical properties of X display. Window
manager can change the size and position of
windows on the display and reshuffle
windows in a window stack.
 X client: Is an application program that communicates with X server
using X protocol. Xterm, Xclock, and Xcalc are examples of X
clients. X manages its windows in a hierarchal structure. The
shaded area that fills the entire screen is the root window. X client
application windows are displayed on top of the root window and
are often called the children of the root.

Purpose and abilities


X is an architecture-independent system for remote graphical user
interfaces and input device capabilities. Each person using a
networked terminal has the ability to interact with the display with any
type of user input device.
In its standard distribution it is a complete, though simple, display and
interface solution which delivers a standard toolkit and protocol stack for
building graphical user interfaces on most Unix-like operating systems
and OpenVMS, and has been ported to many other contemporary general
purpose operating systems.
X provides the basic framework, or primitives, for building such GUI
environments: drawing and moving windows on the display and
interacting with a mouse, keyboard or touchscreen. X does not mandate
the user interface; individual client programs handle this. Programs may
use X's graphical abilities with no user interface. As such, the visual
styling of X-based environments varies greatly; different programs may
present radically different interfaces.
Unlike most earlier display protocols, X was specifically designed to be
used over network connections rather than on an integral or attached
display device. X features network transparency, which means an X
program running on a computer somewhere on a network (such as the
Internet) can display its user interface on an X server running on some
other computer on the network. 

Limitations
The lack of design guidelines in X has resulted in several vastly different
interfaces, and in applications that have not always worked well together.
The Inter-Client Communication Conventions Manual (ICCCM), a
specification for client interoperability, has a reputation for being difficult
to implement correctly. Further standards efforts such
as Motif and CDE did not alleviate problems. This has frustrated users and
programmers.[5] Graphics programmers now generally address
consistency of application look and feel and communication by coding to a
specific desktop environment or to a specific widget toolkit, which also
avoids having to deal directly with the ICCCM.
X also lacks native support for user-defined stored procedures on the X
server, in the manner of NeWS – there is no Turing-complete scripting
facility. Various desktop environments may thus offer their own (usually
mutually incompatible) facilities.
Systems built upon X may have accessibility issues that make utilization
of a computer difficult for disabled users, including right click, double
click, middle click, mouse-over, and focus stealing. Some X11 clients deal
with accessibility issues better than others, so persons with accessibility
problems are not locked out of using X11. However, there is no
accessibility standard or accessibility guidelines for X11. Within the X11
standards process there is no working group on accessibility, however,
accessibility needs are being addressed by software projects to provide
these features on top of X.

You might also like