Some Useful Emacs Commands
CommandEffect
emacs -nw (filename)  start an emacs session with (filename) in buffer
^X^S save buffer to (filename)
^X^C quit emacs session
arrow keys move around in buffer
^K "kill" - cut from cursor to end of line, store in kill buffer
^Y "yank" - paste kill buffer at cursor
^[space] set mark - an invisible marker
^X^X exchange mark and cursor - used to see the marked location
^W "write" - cut from mark to cursor [and store in kill buffer]
^C^G go to line number [entered after command]
^S search forward in buffer
^R search backward in buffer
[Esc][Shift]% search/replace
^X i (filename) insert contents of file at cursor
^X^F (filename) read (filename) into buffer
^Q[key] Insert literal value of [key] at cursor. E.g., ^Q[Tab] inserts Tab char in file
^ = Ctrl key
See FAQ for more Emacs hints

 

Some Useful Unix Hacks
CommandEffect
grep [string] [files]   Searches files for string, displays lines found.
Example:
    >grep 'stack' *.cpp
    compound.cpp:#include <stack.t>
    constTest.cpp:#include <stack.t>
    constTestStackQueue.cpp:#include <stack.t>
    in2post.cpp:#include <stack.t>
    in2post.cpp:         // then push new operator onto stack
    
grep -r [string] [directory]   Recursively searches files for string, displays lines found.
Example (recursive):
    >grep -r 'list2c' ~cop4530p/LIB/
    /home/courses/cop4530p/LIB/proj1/list2c.api:    list2c.api
    /home/courses/cop4530p/LIB/proj1/list2c.api:#include <list2c.cpp>       // [12]
    /home/courses/cop4530p/LIB/proj1/list2c.api:#include <list2c_macro.cpp>
    /home/courses/cop4530p/LIB/proj1/flist2c.cpp:    flist2c.cpp
    /home/courses/cop4530p/LIB/proj1/flist2c.cpp:#include <list2c.h>
    /home/courses/cop4530p/LIB/proj1/deliverables.sh:FILES="name.com list2c.h list2c.cpp makefile2c log.txt"
    /home/courses/cop4530p/LIB/proj1/mlist2c.cpp:    mlist2c.cpp
    /home/courses/cop4530p/LIB/proj1/mlist2c.cpp:#include <list2c.h>
    Binary file /home/courses/cop4530p/LIB/area51/mlist2c_i.x matches
    Binary file /home/courses/cop4530p/LIB/area51/flist2c_i.x matches
    /home/courses/cop4530p/LIB/tests/flist2c.cpp:    flist2c.cpp
    /home/courses/cop4530p/LIB/tests/flist2c.cpp:#include <list2c.h>
    /home/courses/cop4530p/LIB/tests/mlist2c.cpp:    mlist2c.cpp
    /home/courses/cop4530p/LIB/tests/mlist2c.cpp:#include <list2c.h>
    
ls -l [DIR] | grep [string] Pipes a long listing of DIR through the grep filter searching for string in entry names.
Example:
    lacher@linprog1:~>ls -l ~cop3330p/LIB/area51 | grep 'stack'
    -rw-r--r-- 1 lacher 3330pi 33870 Mar 26 14:31 fstack_String_i.x
    -rw-r--r-- 1 lacher 3330pi 18775 Mar 26 14:31 fstack_char_i.x
    -rw-r--r-- 1 lacher 3330pi 18893 Mar 26 14:31 fstack_int_i.x
    lacher@linprog1:~>
    
ln -s [ACTUAL_PATH] [ALIAS_PATH]   Creates a symbolic link for the actual path.
Example:
    lacher@linprog1:~>ln -s ~cop3330p/LIB cop3330/LIB
    lacher@linprog1:~>ln -s ~cop4530p/LIB cop4530/LIB
    
The link cop3330/LIB in my files aliases the LIB directory in the cop3330p course site:
    lacher@linprog1:~>ls -l cop3330
    ...
    lrwxrwxrwx  1 lacher CS-Faculty   26 Apr  7 15:27 LIB -> /home/courses/cop3330p/LIB   
    ...
    
The link cop4530/LIB in my files aliases the LIB directory in the cop4530p course site:
    lacher@linprog1:~>ls -l cop4530
    ...
    lrwxrwxrwx  1 lacher CS-Faculty   26 Apr  7 15:27 LIB -> /home/courses/cop4530p/LIB
    ...
    

 

Emacs / g++ IDE

It is important to develop some good habits and efficiencies now, so that when the work starts piling up you are not still struggling with the peripheral/superficial issues that slow down progress. One I recommend is developing a work flow screen setup that is your own "IDE". Here's the basics for that:

Log in using the ssh facility to linprog. Immediately pop a new window by clicking on the appropriate icon in the first one. Change both these windows into the directory where you need to work. Note that you can resize these wndows. If you have the screen real estate, make one larger one beside or above the other smaller one. Or, simply make them both large (but not full screen) and "tile" them one partially over the other.

In the larger window, open an emacs session with one of the files you are working on. KEEP THIS SESSION OPEN while working. Whever you want to test compile, save the buffer [^X^S] but don't exit. Then click to the other window and issue the appropriate compile command. Note that compile errors have line numbers, so you can use the "go to line number" command in the Emacs window to go directly to that line in the buffer. Make a change, save, and then compile again. Also note that the command history in the compile window is accessed with the up arrow key, so a complicated command can be re-issued (or even edited and re-issued) without a complete re-typeing of the command.

In a multi-file project, it is often convenient to have multiple edit windows open, one for each of several files, along with the command/compile window.

 

Command Aliases

In your home directory, issue this command:

ea

Look carefully at what is on your screen. You are in an emacs session, editing a file named ".alias". This is a file that is read and sourced whenever you log in. ["source" means the file is run as a set of Unix commands. The effect is to customize your Unix interface.]

In that file notice a line that aliases "alias" to "a". Then below that "a" is used to alias other things. In particular, look at "ea", which is aliased to a sequence of three Unix commands (separated by ';'). The first is a call to emacs (this is where you are now). The second is a "source" command that will refresh your aliases. This will be issued after you save and exit emacs. The third command sends a message to screen letting you know that your aliases have been refreshed.

Please add a line in the file as follows:

a    e    emacs -nw

which will make the single letter "e" associated with the command "emacs -nw", opening an emacs session in the same window as the command is issued ("-nw" means "no window").

Then save [^X^S], exit [^X^C], and you have a new shorter way to invoke emacs:

e (filename)

Note that you can use "ea" to add other custome features, such as streamlined compile commands.