1 / 20

4 Editing files and Emacs

4 Editing files and Emacs. Editing files The Emacs editor. Editors. Editors are used to create files of text and to modify their contents You need an editor for sending email, writing programs and many other tasks

Download Presentation

4 Editing files and Emacs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4 Editing files and Emacs Editing files The Emacs editor

  2. Editors • Editors are used to create files of text and to modify their contents • You need an editor for sending email, writing programs and many other tasks • There are many different editors - vi, ed and emacs are common UNIX examples • There are different styles of editor - e.g. line editors and text editors • They are not the same as word processors which are concerned with printed documents (fonts, sizes, etc.)

  3. The Emacs Editor • A powerful editor, available on most UNIX systems • It’s a text editor • Complex and extensible - we will only explore a fraction - see tutorial and on-line help facilities for more

  4. Emacs conventions • Frequent use of the control and meta keys • control key usually marked control or ctrl • the meta key is usually marked alt • The notation C-x means hold down the control key and simultaneously press the x key (was ^X in previous lectures) • M-y means hold down the meta (alt) key and simultaneously press the y key • If the alt-y combination is taken by the host operating system (for example Windows), you can press the escape (esc) key, release it, and then press the y key

  5. Edit window Status line Mini-buffer

  6. Starting and quitting • From the UNIX prompt type emacs or emacs filename • The emacs screen is divided into three parts • edit window - large part where the contents of the file are displayed • status line - name of file, how far through you are and whether it needs saving • minibuffer - where commands are entered • C-x C-c to quit (of course). You may be prompted to save files

  7. Moving around the file • Your current position in the file is shown by the cursor • Most basic movement is one character or line at a time • use the arrow keys or • C-b backward (left) one character • C-f forward (right) one character • C-p previous line (up one character) • C-n next line (down one character) • Scrolling happens as necessary

  8. Can also move in steps of a word, sentence, paragraphs and screen • M-f forwards one word • M-b backwards one word • C-a start of current line • C-e end of current line • M-a start of current sentence • M-e end of current sentence • C-v scroll down one screen • M-v scroll up one screen • M-< move to start of file • M-> move to end of file • C-l refreshes the screen and centers the cursor.

  9. Inserting and deleting text • To insert text, position the cursor and type • Type RETURN to enter a new line, otherwise the line will wrap around • DEL deletes the character before the cursor and C-d the character after the cursor. Hold down for repeated operation • M-del and M-d deletes whole words

  10. C-k deletes from cursor to end of line. A further C-k deletes the new line character • Mark and then delete a whole area: • C-SPACE at start and move cursor to end. • Make sure you have “Active Region Highlighting” ticked to see the marked region in color! • C-w to delete the marked out region • M-w copies the area without deleting it. • Commands that remove more than one character at a time save the text. It can be yanked back with C-y • Another C-y to yank back another copy • M-y to yank back next previously deleted text • Can use C-w and C-y to move text around

  11. File handling • Need to be able to load and save files • C-x C-f finds and loads a file • Prompts for the pathname in the minibuffer • Type the name and press RETURN • Use TAB for filename completion • File is either loaded or created

  12. Changes made on screen are not immediately made to the file, they are made to a copy called the buffer • Have to explicitly write them back by saving, C-x s (all files) C-x C-s (current file) (answer y and n to prompts) • Can have more than one file open at a time. C-x C-f also switches between buffers if we give the name of an open buffer. • C-x b swaps to the previous buffer • Save frequently - work will be lost if emacs or the system crashes • Previous version may be backed up in filename~

  13. Undoing mistakes • C-x u, C-_, and C-/ undo the previous command • Repeating the undo command takes you further back through the editing history

  14. Searching • Need to search for text in a large file • Incremental search • type C-s to search forward. • Type C-r to search backwards • Or enter command M-xisearch-forward or M-xisearch-backwards in the minibuffer (use TAB for command completion) • you can delete the last character in the search string • C-g to quit at any time (this works for any command!)

  15. Replacing strings • Change all occurrences of one string of text with another • type M-x and enter query-replace • Or type M-% • enter search and target strings • type y or n at each prompt. ! to replace all • use replace-string to avoid the prompting • M-x then spell-buffer for the spell checker

  16. Windows • Can divide the edit window into smaller sub-windows, each with a different document • C-x 2 split horizontally • C-x 3 split vertically • C-x 1 make current window the full window • C-x o move cursor to the next window

  17. Modes • Modes configure emacs for different kinds of editing, controlling wrap-around and indenting • M-x then mode name • fundamental-mode • text-mode (gives automatic text wrapping) • c++-mode • May guess mode from the filename suffix • Use TAB for autocompletion

  18. Help and the tutorial • C-h for top level help menu • C-h C-h to find out what each menu option means • C-h t for the on-line tutorial • A cheatsheet with most of the key combinations in this lecture is in the module folder

  19. Coursework 1 • Deadline: 10th April 4PM. • Covers the first three lectures (and the revision lecture) • It mentions one simple command we haven’t seen. You’ll have to find out how it works.

  20. Next Lecture • UNIX processes • How to list them • How to prioritise them • How to schedule them • Parent and Child processes • Signals • What are they for? • Types of signal

More Related