Presentation is loading. Please wait.

Presentation is loading. Please wait.

By Justin Higgins. What is a text editor? If you’ve ever used Microsoft word you know what a text editor is (albeit a bloated one). When you write a program.

Similar presentations


Presentation on theme: "By Justin Higgins. What is a text editor? If you’ve ever used Microsoft word you know what a text editor is (albeit a bloated one). When you write a program."— Presentation transcript:

1 By Justin Higgins

2 What is a text editor? If you’ve ever used Microsoft word you know what a text editor is (albeit a bloated one). When you write a program in this class you will use a text editor to write the file. In this file you will write a series of commands which upon execution will be performed. In our case: we will use the text editor to write IDL programs. Naturally the file you create will have a series of IDL commands (these ARE different from UNIX commands)

3 Emacs vs VIM There are primarily two text editors programmers use: Emacs and VIM Both have incredible functionality with VIM focusing more on fewer keystrokes and Emacs focusing on customization. We will teach you Emacs, although it makes no difference in the future if you become proficient in one or the other. Beware! You are choosing a side in the holiest of holy geek wars.

4 Open Emacs To open emacs in a terminal simply type emacs. To directly open a file with emacs from the terminal type emacs file_name If you do this on the ugastro server a new window will open up with the GUI emacs. If you have a Mac you can open Emacs in terminal the same way, but you will not get the same GUI (it will be built in the terminal).

5 Emacs basics Most emacs commands use a Ctrl-x plus some characters to perform a command: Examples: To open a file: Ctrl-x Ctrl-f (then type the file path) To save a file: Ctrl-x Ctrl-s To close a file: Ctrl-x Ctrl-c

6 Editing To edit a file simply type in the main window. Search forward: Ctrl-s (type the search string) type Ctrl-s repeatedly to step through searches Search reverse: Ctrl-r Beginning of line: Ctrl-a End of line: Ctrl-e Beginning of file: Esc-< End of file: Esc->

7 Ooops! I made a poopsy! To undo an action: Ctrl-_ (or Ctrl-x u) To cancel a command you are typing: Ctrl-g Example: (I want to save a file but I accidentally typed: Ctrl-x Ctrl-c which will close it if I hit enter!) Ctrl-g Type multiply times if not stopping. this will work anywhere within emacs

8 Intermediate Goal: Once you are comfortable you should very seldom use your mouse/track pad or have to type the arrow key repeatedly. Go to a line: M-x goto-line Query replace: Esc-% (type search string…enter…type replace string….enter, skip a change with ‘n’ and execute one with spacebar)

9 Markers You can set a marker where you would like some text operations executed. Do this by typing: Ctrl-space (you will see ‘mark set’ on the bottom) Now wherever you move you’re the cursor next, will define the mark up region (the region you want to edit).

10 Using markers (don’t inhale) Remove or ‘kill’ a line: Ctrl-k Remove a region of text: Set marker Move cursor to bottom of remove region Ctrl-w IMPORTANT: After you remove a line or region that text is temporarily stored and can be pasted by typing Ctrl-y (for yank)

11 Buffers You can have multiple buffers within one window of emacs. That is OS will only show that one terminal window of emacs is open, but in that window can be MANY files. Say you open a file (file1) and then want to open up another file (file2) whilst leaving file1 open. Simply type Ctrl-x Ctrl-f and the path for file2 and you’ve now opened up file2 in a new buffer. To switch back to file1, type Ctrl-x b file1. If you forget which files are open in buffers: Ctrl-x Ctrl-b displays available buffers

12 Viewing multiple buffers simultaneously This is perhaps one of the most useful tricks you will use in emacs. You will often want to compare two or more of your programs. Instead of opening up multiple emacs windows you split one emacs window into many. In each of these windows you can display a buffer. To split the window horizontally: Ctrl-x 2 To split the window vertically: Ctrl-x 3 To close the window (YOU ARE IN): Ctrl-x 0 To close all the windows EXCEPT the one you are in: Ctrl-x 1 To switch between windows: Ctrl-x o

13 Advanced: Macros Eventually you become so 1337, so Super Saiyan that even the shortcuts aren’t fast enough for you. Luckily you may define your own shortcuts with macros. Begin defining a macro: Ctrl-x ( Define one iteration of the operation End macro definition: Ctrl-x ) Execute the macro: Ctrl-x e

14 Iterative operations To execute a command iteratively: Ctrl-u # command (where # is the number of executions) Example: To indent a region 4 spaces: Define region. Ctrl-u 4 Ctrl-x

15 Last remarks You will only master these by practice. If you take the time to learn the commands the programming bottleneck is simply the execution of your code (and not your typing speed). Of course, it is easy to get distracted with emacs shortcuts. Remember they are there to simplify a task—that is, if it is too much work to use a shortcut DON’T USE IT!


Download ppt "By Justin Higgins. What is a text editor? If you’ve ever used Microsoft word you know what a text editor is (albeit a bloated one). When you write a program."

Similar presentations


Ads by Google