Emacs introduction By Oliver Pfaff


 
Thread Tools Search this Thread
Operating Systems Linux Emacs introduction By Oliver Pfaff
# 1  
Old 02-26-2006
Emacs introduction By Oliver Pfaff

hi to all friends

iam new member and i would like to joine you

and would like to post my first post

really even i dont know if this the right place to post over here

cuz its ' first time


This is a short tutorial intended to provide a person with the necessary knowledge to perform basic editing tasks.

Emacs and Vi (Vim) have long been the two most popular editors on the Linux platform but this has changed in recent times with the advance of the Linux GUI. As a result many people have never used a command line based editor on Linux and find themselves unable to come to grips when something goes wrong. For a new user an attempt to make a simple change in a config file can quickly end in frustration.
This is because like Vi, the keyboard shortcuts are nothing at all like the ones people may be used to from Windows or a Linux GUI, where Ctrl-c copy's, Ctrl-v pastes and Ctrl-s saves.
Emacs itself can seem very complicated and difficult to use and it takes a while to learn but getting the basics is very easy and features like infinite undo give you a lot of room to make or correct mistakes.


Starting Emacs


If you're using a GUI like Gnome or KDE, open a terminal and type emacs. You may be able to open it from an application menu but remember that this may not be available when something goes wrong. If you're already on the command line simply type emacs. If you're currently using a GUI, Emacs may start in a separate window from the terminal. We don't want this because it again defeats the purpose of the tutorial. Type emacs -nw to start it in the terminal.


Emacs command format
As mentioned before Emacs commands are a little different from what you may be used to. The following command can be used to exit Emacs:
C-x C-c
This means hold down the Control(Ctrl) key, press x and then hold the Ctrl key and press c. You can hold down the Ctrl key through the entire operation or let go after C-x and treat C-c as a separate command - it makes no difference.

Most other basic Emacs commands run along the same fashion. We will cover them as we move along.


Files
To open a file in Emacs do C-x C-f. You will be prompted for the name of the file to open. Note that you will need to specify the exact name and path of the file for emacs to open it - no fancy Browse buttons here. If you specify a file name that doesn't exist, Emacs will create it in the current directory. Probably the easiest way to open a file is to specify it when starting Emacs.
For example $emacs -nw myfile opens the file called myfile in the current folder. Again, if the file doesn't exist Emacs will create it. If you open a file and find the content has disappeared since you last looked at it, don't panic, you probably mistyped the name!

Navigation
As with most other text editors you can navigate around a file using the arrow and page up / page down keys. However you should know that it is also possible to do this with Emacs command, which often provide much finer grained control and can save you a lot of key bashing to get around:

C-f Move forward a character
C-b Move backward a character

M-f Move forward a word
M-b Move backward a word

M-a Move to beginning of sentence
M-e Move to end of sentence

C-n Move to next line
C-p Move to previous line
C-a Move to beginning of line
C-e Move to end of line


Other important commands
To save the file you are currently working on do C-x C-s.
To undo your last move do C-x u
Another important command for beginners is C-g. Sometimes you may accidentally enter some command or emacs prompts you for something you don't understand or want to know about emacs will just drop whatever it was asking you about or doing and let you get on with it.

To delete a word do M-d and to delete a line do C-k. Both of these commands can save a lot of key bashing. They will however only delete text to the right of the cursor.


Summary
Knowing how to find your way around Emacs can save you a lot of grief when trouble strikes and its definitely worth it to use emacs for a while even if other easier to use editors are available. When just starting with emacs it can be a good idea to keep a short list of essential commands handy until you know them off:


C-x C-c Exit Emacs
C-x C-f Open a file
C-x C-s Save the file
C-x u Undo

C-g Cancel command/get rid of prompt
M-d Delete word
C-k Delete line

C-f Move forward a character
C-b Move backward a character
M-f Move forward a word
M-b Move backward a word
M-a Move to beginning of sentence
M-e Move to end of sentence
C-n Move to next line
C-p Move to previous line
C-a Move to beginning of line
C-e Move to end of line
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. What is on Your Mind?

Introduction

Hi everyone. I am not really a new member i was once a member using the handle despiragado. I now wish to be identified with my new handle. It's been a while i have last visited the forum to see whats happening. I guess a lot has happened. I will try to read up and keep up to date. I am a... (3 Replies)
Discussion started by: split_func0
3 Replies

2. What is on Your Mind?

Introduction

Hello, I couldn't find an actual introduction thread, so I decided to just put this here. I go by d0wngrade online. I have been programming in multiple languages for about 15+ years. I started with standard web design languages like HTML and CSS, but I then advanced from design to development... (2 Replies)
Discussion started by: d0wngrade
2 Replies

3. UNIX for Dummies Questions & Answers

How to use emacs? Also how to open existing emacs files with .cgi format?

Hi All, I am new to this forum and a beginner in unix. Please correct me if I put the question in a wrong way.. How to use emacs editor? Also how to open existing emacs files with .cgi format? I have the following link :- http link i.e. url and path : /abc/xyz.dev/xyz/documents What... (7 Replies)
Discussion started by: swathi123
7 Replies

4. Shell Programming and Scripting

Introduction

Hi, I am new here. Recently I have started working on Unix Shell Scripting. So may I know from where to start... Regards, Darshak Raut (3 Replies)
Discussion started by: darshakraut
3 Replies
Login or Register to Ask a Question