Emacs

Emacs, which has been under development from the 1970’s, is a basic text editor and hugely popular on Unix systems. It is an immensely powerful text editor and is available on all TACC login nodes along with it’s main contender for favorite programmers editor vi. For editing files at TACC we will be using this editor.

The following are how to start emacs from the terminal:

  1. To start the emacs application with no file loaded:

emacs
  1. To start the emacs application with some file named filename located in the current directory opened in the editor:

emacs filename

Once inside emacs, you are in a mode similar to INSERT in vi. You can use up, and sideways keys to move the cursor around the characters of the file. There are a number of options available to you through use of either the <Control> key or the <Escape> key that perform certain common file editor operations. Emacs has over 10,000 built in commands! Only a dozen or so commands are needed for most editing purposes. The following is a list of my most used commands. This short list are more than sufficient for most editing purposes.

  1. Quit application (will prompt to save files):

    <Control> x <Control> c
    
  2. Save current file:

    <Control> x <Control> s
    

    Note

    1. For basic editing you probbaly only need these 2 commands.

    2. For commands that have two similar special keys, i.e. <Control> a <Control> b, you can hold the <Control> key down with one finger and hit a b with another finger.

    3. <Control> means the control key on your keyboard, don’t type <Control>. Same goes for <Esc> or <Escape>

  3. Open a file:

    <Control> x <Control> f
    
  4. Delete from current cursor to end of line (copies to clipboard). Will append to clipboard if lines follow one another.

    <Control> k
    
  5. Delete from current cursor to end of line and delete next n-1 lines. note n is a number.

    <Escape> n <Control> k
    
  6. Paste clipboard to current cursor location

    <Control> y
    
  7. Undo last command

    <Control> x u
    
  8. Move cursor to start of line

    <Control> a
    
  9. Move cursor to end of line

    <Control> e
    
  10. Move cursor to start of file

    <Escape> <
    
  11. Move cursor to end of file

    <Escape> >
    
  12. Search for text blah in file forwards from current cursor

    <Control> s blah
    
  13. Search for text blah in file backwards from current cursor

    <Control> r blah
    
  14. Find and replace text from current cursor location. It will prompt for confirmation at each occurance. Accept with a y, reject with a n.

    <Escape> %
    
  15. Find and replace all occurances of text from current cursor location to end of file.

    <Escape> x replace-string <RET>
    
  16. To split the terminal window into multiple screens so that multiple files can be viewed at the same time use one of the following:

    <Control> x 2
    
    <Control> x 3
    
    <Control> x 1
    

    The 2 splits the current screen into two horizontal screens, the 3 into two vertical screens. As you will discover, you can have many screens viewable in the one terminal windows ddepending on how many splits you make. The last 1 option will result in only one, the current screen, being showed in the terminal window.

  17. To move from one split screen to the next use the <Control> lowercase o option, i.e.:

    <Control> x o
    

There are of course more commands available (over 10,000!). But those are some basic ones and enough to get you merrily editing files!