SI 204 Spring 2017 / Resources

This is the archived website of SI 204 from the Spring 2017 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

Introduction to emacs

(Thanks to Dr. Brown for this quick-start guide.)

  1. Launching Emacs Launch emacs like this: emacs&. That's a linux thing, not an emacs thing. This way, emacs launches but the terminal comes back for more commands instead of waiting for emacs to finish. If you want to edit or create a file at the same time you're launching emacs, put the file name in before the & sign. For example: emacs foo.cpp&.
  2. Don't Panic! If things get strange in emacs, hit ctrl-g. If that doesn't clear up, try ctrl-].
  3. Insert vs. Overwrite Emacs works in either "insert" or "overwrite" mode just like most text editors and word processors. The "insert" key on your keyboard toggles between them. On the bottom of the window you'll see "Ovwrt" when you're in overwrite mode. Play with that.
  4. Moving Around Pressing ctrl and using the left or right arrows jumps you word-by word through a line. Pressing ctrl with the up or down arrows jumps you to chunks of text separated by blank lines. ctrl-a jumps you to the start of the line you're on, and ctrl-e jumps you to the end.
  5. Cutting and Pasting The GUI's cut and paste works with emacs, but emacs also has its own, separate system. ctrl-space sets a start point, move with arrows to the end point of the region you want to mark (it should highlight). Then ctrl-w cuts the highlighted region into the emacs version of the clipboard, and ctrl y "yanks" it out at whatever point you move the cursor to. If you want to copy the highlighted region to the emacs version of the clipboard without cutting it out of the text, that's esc-w.
  6. My Favorite — ctrl-k An alternative to marking a region is to use ctrl-k, which kills the line from the point of your cursor to the end of the line, adding it to the emacs version of the clipboard. You can do this multiple times to add multiple lines to the buffer. Then use ctrl-y ("yank") as before.
  7. Opening and Saving Files ctrl-x ctrl-s saves the current buffer. ctrl-x ctrl-w does "save as". ctrl-x ctrl-f lets you open a new buffer (but wants you to give it a name and directory at the same time) or an existing file.
  8. Emacs Buffers vs. Files Emacs distinguishes between "files" and "buffers". A file is something that exists in a directory somewhere. The thing that you are dealing with in emacs is a "buffer" — a copy of the file in emacs's memory. So when you type, you are changing the buffer, and only by saving the buffer to the file does the file itself change. You can have multiple buffers open in emacs at the same time. There's a "Buffers" menu you can use to switch between them, and you can split the window to show multiple buffers: ctrl-x 1 gives you a single buffer in the window, ctrl-x 2 splits the window horizontally to show two buffers, and ctrl-x 3 splits the window vertically to show two buffers