Monday, March 31, 2014

Tips for beginners

Tips for beginners

In the event of an emergency…

Here's what to do if you've accidentally pressed a wrong key:
  • If you executed a command and Emacs has modified your buffer, use C-/ to undo that change.
  • If you pressed a prefix key (e.g. C-x) or you invoked a command which is now prompting you for input (e.g. Find file: …), type C-g, repeatedly if necessary, to cancel.
C-g also cancels a long-running operation if it appears that Emacs has frozen.

Keyboard and terminal setup

  • Some Emacs users remap their Caps Lock key to act as an additional Ctrl key, because it is easier to reach. See instructions for moving Ctrl.
  • Due to your keyboard or terminal configuration, you may find that some keys seem to do the wrong thing:
  • If your DEL key is not working (sometimes, typing DEL brings up a help screen, as if you typed C-h), try M-x normal-erase-is-backspace-mode.
  • If your meta key is not working, in order to type a key that contains meta, you can instead type ESC, then the remaining keys. For example, ESC x is the same as M-x, and ESC C-s is the same as C-M-s.

Exiting Emacs,Fixing Mistakes and other Important Stuff

 Exiting Emacs,Fixing Mistakes and other Important Stuff


C-x C-c

Save-buffers-kill-emacs: when you are finished
 editing, and to return you to the UNIX prompt.
C – g


Keyboard-quit: if while typing a command you
 make a mistake and want to stop, this aborts a 
command in progress.
C- u



Universal- argument: if you want to do a command
 several times, type this command followed by a 
number ( for the number of times) folllowed by the command you wish repeated.




C – x  u

Undo: undoes the last command typed, in case you
 made a mistake.
Esc  x



Execute-extended-command: prompts for the name
 of an emacs command; allows you to execute a 
command if you know roughly what it is called but
 cannot remember the key strokes for it.

Window and buffer commands

 
                             Window and buffer commands

C – x    0
Zero-window: deletes current window
C – x    2
Double-window: Splits current window into
 two parts, allowing you to edit at two different locations in the same file or permitting you to view different files at the 
same time.
C – x    b
Switch-to-buffer: display a different buffer on
 the screen.
C – x    o
Other-window: Move the cursor to the other 
window( Assuming that you have two 
 windows/buffers open at once
C – x    c – b
List-buffers: lists those buffers currently
 loaded into emacs.


Search command

                   Search command

C- s
isearch-forward: prompts for text string and then searches
  from the current cursor position forwards in the buffer.
C – r
Isearch-backward: like isearch-forward, but searches from
 the current cursor position to end of buffer for text string.
Esc %
Query-replace: prompts for a search string and a string with
 which to replace the search string.

Copy and delete commands II


C – w
Kill-region:  delete the area of text between the mark and the
 current cursor position.
C – y
Yank:  insert at current cursor location whatever was most
 recently deleted.
Esc w
Copy-region-as-kill:  Copy area between mark and cursor
 into kill-buffer so that it can be yanked into someplace else.

Copy And delete commands

                  Copy and delete Commands
  
C – d
Delete – char : delete character under
 cursor
Esc d
Delete – word : delete from cursor to 
end of word immediately ahead of the 
cursor.
C – k
Kill – line : Delete the rest of the current line.
C - @
Set-mark-command: Mark is used to indicate the beginning of an area of text to be Yanked
                                                                 EMAC                  

—*Emacs Text editor is a popular & powerful program that is available on many platforms. Ex: UNIX, DOS, Windows 9x and NT, and  OS/2.
—*Emacs -extensible, customizable, self-documenting real-time display editor-GNU
*—Unlike vi, emacs is not an insertion mode editor, -character typed in emacs is automatically inserted into the file.
   
                                             FEATURES
 1.simpler to use than vi
2.editing and viewing multiple files at one time
3.spell checking
4.compiling programs from within Emacs
5.automatic indention of programs
6.a powerful macro language that may be used to extend the functions of Emacs
                                    Emacs-History
1. Emacs -created by Richard Stallman in 1975.
—2.GNU Emacs is the most popular version of Emacs and is directly derived from Stallman's original version.
3.The GNU (Gnu is Not UNIX) project - associated with Stallman's Free Software Foundation.
4.There are other versions of Emacs that are not free.

                                  How to Start

1.To run Emacs, type at the UNIX prompt :
            emacs  file_to_edit
2. Emacs will be run and start editing the file specified.
                   
                          BASICS   

1.         The mode line is the one that is next to the last line from  the bottom and will be highlighted.
2.—       This line divides the editing portion of the screen from the command line at the very bottom.
3.—      When a file is loaded into Emacs, it is loaded into a buffer. Buffers are edited, not files.
—4.     The mode line shows the name of the buffer.
5.—     To update the actual file, the buffer must be saved.
—6.      Emacs will prompt the user to save any modified buffers when it exits.
7.      Emacs maintains a backup file when a file is saved. The backup file is a copy of the last version of the file.
8.—       Its name is the original file name with a tilde (~) appended to the end.
9.—     One other distinction between emacs and vi is that emacs allows you to edit several files at once.
10.—   The window for emacs can be divided into several windows, each of which contains a view into a buffer.
11.—   Each buffer typically corresponds to a different file.

                         Emacs commands

The user uses special keys to send commands to Emacs.
—* Commands in emacs are either control characters (hold down the <Ctrl> key while typing another character) or are prefixed by one of a set of reserved characters: <Esc> or <Ctrl>-X.
*— The (Meta Key) <Esc> key can be typed by itself (because it really is a character) and then followed by another character;
—*The <Ctrl> key must be held down while the next character is being typed.

                       
 

         




Basic Editing commands


                         Basic editing commands

One way that Emacs lets users work quickly and efficiently is by providing high-level commands for moving around in, and manipulating, text. There are commands that operate on characters, words, lines, sentences, paragraphs, pages, function definitions, whitespace, and more. You can use them anywhere you read or edit text: source code, web pages, shells, directory listings, email messages, and so on.

                        Moving around in buffers

The most basic buffer movement commands move point (the cursor) by rows (lines) or columns (characters):
C-fForward one character
C-nNext line
C-bBack one character
C-pPrevious line   

Here are some ways to move around in larger increments:
C-aBeginning of line
M-fForward one word
M-aPrevious sentence
M-vPrevious screen
M-<Beginning of buffer
C-eEnd of line
M-bBack one word
M-eNext sentence
C-vNext screen
M->End of buffer
When you get used to these keys, they're faster than their more familiar equivalents in other applications (Home, End, Ctrl+Left, etc.) because you don't have to move your hands from the touch typing position. And these keys are far faster than using a mouse to move around in a buffer.
Emacs often provides additional commands for moving around in context-specific ways (e.g. in source code, commands to move to the previous or next function definition).
Many of the above commands move to a location relative to your current position in the buffer, so you can use them repeatedly (e.g. C-p C-p C-p to move back three lines). You can use the prefix argument to save time: C-u followed by a number and a movement command repeats that command the specified number of times. You can also use M-[digit] instead of C-u [digit]. If you use C-u without specifying a digit, the default is 4. Omitting the digit can save time when you don't know precisely how many units you want to jump anyway.
C-u 3 C-pBack 3 lines
C-u 10 C-fForward 10 characters
M-1 M-0 C-fForward 10 characters
C-u C-nForward 4 lines
C-u C-u C-nForward 16 lines
C-u C-u C-u C-nForward 64 lines
You can jump directly to a particular line number in a buffer:
M-g gJump to specified line
Searching for text is a handy way to move around in a buffer. Think of search as just another facility for movement. When you're looking for something specific, you can use incremental search to take you right there instead of scanning by lines or pages. More about search later.
C-sIncremental search forward
C-rIncremental search backward

Emacs commands

                                                   EMACS COMMANDS       
 
  • The user uses special keys to send commands to Emacs.
  • Commands in emacs are either control characters (hold down the <Ctrl>key while typing another character) or are prefixed by one of a set of reserved characters: <Esc> or <Ctrl>-X.
  • The (Meta Key) <Esc> key can be typed by itself (because it really is a character) and then followed by another character;
  • The <Ctrl> key must be held down while the next character is being typed.
            Help commands


C-h
help-command: first character in lots of useful help commands
C-h t
help-with-tutorial: command to run the tutorial
C-h i
information: describes most of the emacs commands in man style pages
C-h k
describe-key: tells you what a particular key stroke does
C-h a
command-apropos: prompts for a string and
  then searches for all emacs commands that contains that string
ESC ?
also does command-apropos
C-h ?
help-for-help: describes how to use the help facilities
File Reading and Writing Commands


C-x C-f
find-file: first prompts for a filename and
  then loads that file into a editor buffer of the same name
C-x C-s
save-buffer: saves the buffer into the associated filename
C-x C-w
write-named-file: prompts for a new filename and writes the buffer into it

Cursor/ Screen Movement Commands
 

C-a
Move cursor to beginning of line
C –e
Move cursor to end of line
C –f
Move cursor forward one character
C-b
Move cursor backward one character
C-n
Move cursor to next line
C-p
Move cursor to previous line
C-v
Scroll file forward by one screenful
 
Esc  v
Scroll file backward by one screen full
Esc  <
Go to beginning of buffer.
Esc  >
Go to end of buffer.
Esc  f
Move cursor forward one word.
Esc  b
Move cursor backward one word.