FreeOS.com logo

FreeOS Most Popular
* Most Read stories
* Commented Stories
* Active Categories
* Non Linux Section
* User Submitters
* Top Polls
* Top Authors
* Top Reviews
* Top Rated
* Top Search Terms

Top Articles
* Writing a Linux device driver
* The Linux filesystem explained
* Samba NT Domain Controller
* Setting up Squid as your caching HTTP/FTP proxy
* Web server tutorial - Part 1

FreeOS Highlights
* Howtos (72)
* Reviews (20)
* Opinions (18)
* Interviews (8)
* News (3)

My FreeOS

Nick:
Pass:
Register

Forgot your password?

Contact Us
Contact Us

       

Project: Linux triangle Howtos triangle

Emacs: The programmer's editor

By Vans Information <content@vansinfo.com>
Posted: ( 2001-03-29 07:23:25 EST by )

Emacs, although quite popular among the Linux community, can be a bit intimidating for the new user. This article explores its various features and commands and helps you get going with it.

Emacs is one of the most preferred editors under Linux. This full-featured screen-based editor has gained enormous popularity due to its ease of use and extensibility. One can be sure that while using emacs, one won't end up in a nightmare situation, as is usually the case with an editor like 'vi'. Although used more often on a Unix-based system, emacs has been ported on a wide variety of Unices as well as DOS and Windows. On the GNU-Linux-based system, it is available in text mode and as an X application.

You can invoke emacs from the command prompt by the following command:

$ emacs

The above command name may be followed by a list of one or more filename(s) that are to be opened.

As soon as emacs starts up, it takes over your screen. Usually you see a Scratch-pad available for you. This brings us to the structure of the emacs editor, which usually comprises in-memory buffers. The Scratch-pad is a buffer where you can key in text and later convert it to a named document. Just like other editors emacs allows you to open multiple files at a time. Also it provides support for many programming languages including C, C++, Java, SGML, TeX, etc. It has modes for various languages, where it undertakes syntax checks like checking for braces and parentheses. Whenever you open a text file containing program code, emacs detects the programming language, and initiates the appropriate mode. Given below are some of the basic commands.

Opening a file

In order to open a file from within emacs, you need to use the command Ctrl-X F. Here the X & F need to be pressed in succession. This is the way most of the commands are entered. Upon issuing the above command, the cursor moves to the bottom of the screen.

The last line of the screen is called the Mini-buffer. This is the area where all commands are issued and messages are displayed. Here, enter the name of the file you want to open. If the file is non-existent, then a new file with the given name is created. Now the cursor moves over to the top-left of the emacs screen. Here you can type in your text as in a normal editor using arrow keys for movement and the usual backspace and Del keys. Later in this article, we look at some of the more advanced commands.

Saving a file

The command to save a file is Ctrl-X S. Emacs saves the contents of the modified file in memory to disk. In effect, emacs only does a buffer write. The rest of the buffers that can be holding contents of other files are not updated on disk. To save the file under some other name use the 'Save As' command which is given as Ctrl-X W. After issuing this command, emacs will you to specify the new name for the current file.

Quitting emacs

To quit emacs, the command usually given is Ctrl-X C. This command finishes the current emacs session and returns you to the shell prompt. If files opened in their respective buffers have not been saved, emacs gives a prompt for each file asking the user whether he/she wishes to save the file. You can also suspend emacs operation so that it temporarily spawns a shell where you can issue commands to the operating system. Issuing the Ctrl Z command can do this. You can return to emacs by typing 'fg' at the command prompt.

Given below are some basic commands to help you start off.

* Cursor movement keys

Ctrl A beginning of the line.
Ctrl E end of the line.
Alt A beginning of the sentence
Ctrl P previous line.
Ctrl N next line.
Ctrl B one position to the left.
Ctrl F one position to the right.
Alt F one word to the right.
Alt B one word to the left.
Alt < beginning of file.
Alt > end of file.


* Scrolling screens

Ctrl V Scrolls forward by one screen.
Alt V Scrolls backward by one screen.

Sometimes, it may so happen that the text display gets garbled due to unwanted kernel messages or 'wall's (write alls) from other users. Issuing the command Ctrl-L can set the screen right.


Buffers

In case you have opened multiple files in emacs, you need different buffers to store them as one buffer can hold only one file. At any time, only one buffer is active. To switch to another buffer, we can issue the command Ctrl B, where denotes the name of the file opened in the other buffer. Whenever a file is opened and loaded in a buffer by emacs, the buffer gets the name of the file. Thus, you can assume the buffer name to be the same as the filename.


Delete operations

The following `delete’ operations can be performed.

Del deletes the character just before the cursor
Ctrl-d deletes the next character after the cursor
Alt-Del kills the word immediately before the cursor
Alt-d kills the next word after the cursor
Ctrl-k kills from the cursor position to end of line
Alt-k kills to the end of the current sentence


Killing & Yanking

The word 'kill', instead of deleting, is used to signify that the set of characters thus `killed’ have been saved into a special 'clipboard' area. They can be 'yanked’ meaning that they can be pasted to the current position using Ctrl Y. This operation is similar to the Cut-&-Paste, as we see in most MS-Windows systems.

Emacs, however, is a lot more than what we have just seen. We hope this article will encourage you to use it.

Other articles by Vans Information

Current Rating: [ 5.83 / 10 ] Number of Times Rated: [ 35 ]

More Howtos
* Kernel Compilation & Avoiding ‘Unresolved Symbol’
* Configuring CVS and CVSUP on Linux
* Knoppix installation tips
* Maximum Mount
* A WebServer Guide -- Help Using Apache

Contents
Articles
  Howtos
  Interviews
  News
  Opinions
  Reviews
Comparison
Links
  Articles
  Howtos
  Interviews
  Opinions
  Reviews
  Websites
News

Linux
About Linux

Print It!
Printer Friendly Version