SSH

ssh is useful for remotely logging into the CS lab machines. If you have never used ssh before, you may need to install an ssh client to connect to the CS machines from your home computer. More details can be found on the remote access help page.

You can remotely connect to any machine by sshing in as you to lab.cs.swarthmore.edu or to a particular machine by logging in as you to a specific machinename.cs.swarthmore.edu. For example:

# log into some lab machine:
ssh yourusername@lab.cs.swarthmore.edu
# log into owl:
ssh yourusername@owl.cs.swarthmore.edu

You can find the names of lab machines here: cs lab machines

using your ssh client try connecting to the CS network using your CS username and CS password. Note that your username is probably the same as your ITS username, but your password may be different. You can always request a CS password reset online.

Learning vim (and vi)

The vi (and vim) editor is available on every Unix system. It is a very efficient and lightweight text editor that is easy to use after learning a few basic commands, which that you can learn by running though the vimtutor tutorial.

Even if you know another editor such as emacs, or atom, it will be important to know the basics of vi/vim for CS31 and other systems CS courses.

vim is particularly useful when working remotely, ssh’ed into a machine.

vim also has a lot of advanced features, and it is very configurable, often through the use of a .vimrc file. However, just a few basic commands is enough to use vim to edit files on our system.

Vim operates in two modes:

  1. insert mode: keystrokes are interpreted as inserts into the file contents at the point of the cursor.

  2. command or escape mode: keystrokes are insterpreted as vim commands, which allow a user to do such things as saving, exiting, searching, or moving around in the file.

To switch from insert mode to command mode, press the ESC key.

There are many ways to switch from command mode to insert mode. One way is to press the i key.

To learn the vim editor, run vimtutor:

  1. ssh into our system and run vimtutor. Consult the help pages on remote access and ssh if needed.

  2. After creating a cs31 subdirectory in your home directory in the section above, change into this directory with cd:

      $ cd          # go to home directory from current directory
      $ ls          # list (ls) home directory contents
      $ cd cs31     # change directories (cd) to cs31 folder
      $ pwd         # print working directory to show full path

    From within your cs31 subdirectory run the vim tutorial:

      $  cd ~/cs31    # if you aren't already in the cs31 folder
      $  pwd
      $  vimtutor     # start the vim tutorial
    home$  ssh yourusername@lab.cs.swarthmore.edu
    
    cs$  cd {coursepath}
    cs$  pwd
    cs$  vimtutor           # start the vim tutorial
  3. Go through the sections listed below of vimtutor (the other sections cover more obscure features that are not necessary). It will take about 30 minutes to run through these lessons.

    • all of Lesson 1 (moving around, x, i, A, :wq)

    • Lesson 2.6 (dd)

    • Lesson 2.7 (undo)

    • Lesson 3.1 (p) and 3.2 (r)

    • Lesson 4.1 (G) and 4.2 (searching)

    • Lesson 6.2 (a), 6.3 ( R ), and 6.4 (y and p)

It will take about 30 minutes to run through these lessons.

Configuring vim

You do not need to configure vim in any way to use it on our system. However, you may want to based on foreground and background terminal colors, and set some other options.

In your home directory you can add a configuration file for vim, named .vimrc. On start-up, vim examines this file to set different configuration options for the vim session, including setting a color scheme, and default window size.

To see if you have one already, run ls -a in your home directory to list all your dot files:

cd
ls -a

If so, you can open it in vim and edit it like any other file:

vim .vimrc

If not, it is often easiest to start with someone else’s .vimrc file and then edit what you want. From your home directory, you can copy someone else’s. Here is one you can copy over into your home directory that uses a color scheme that shows up well on dark background windows:

cd
cp ~newhall/.vimrc ./

At the bottom of this .vimrc file are some settings to give you a visual cue about not line wrapping source code in files. One sets the widowsize to 80 (or 81) chars when you start vim, others can be used to set visual reminders when a line exceeds 80 chars:

tail -20 .vimrc   # dump the last 20 lines of the file .vimrc
                  # note lines that start with double quote are comments

set colorcolumn=80
highlight ColorColumn ctermbg=darkblue
" resize to 81 to more easily see colorcolumn (set to 80 if don't use colorcolumn)
set columns=81
autocmd VimResized * if (&columns > 81) | set columns=81 | endif
set wrap
set linebreak
" visually shows +++ when go past columns limit
set showbreak=+++

You can copy this into your .vimrc file if you’d like this functionality

Vim Resources and Links

Zoom

You will receive an email with information about how to find our class zoom link before the start of class.

There are instructions for using zoom off the college’s Working Remotely page.

Zoom for partners

Set-up and try out a zoom meeting with your lab partner or project group members

  1. one of you should create a zoom meeting for your lab work:

    • Name the meeting something like labXmeeting where X is the number of your lab assignment

    • Make it a Recurring meeting with the Recurrence→No Fixed Time option.

    • Enable join before host in the Meeting options

    • Save and send your lab partner the zoom link (Join URL associated with your meeting or copy the invitation link)

  2. contact each other to find a time for a 10 minute practice zoom meeting.

  3. at the time you arranged to meet, join your zoom meeting (because "join before host" is selected any of you can start the meeting).

Slack

Slack breaks up workspace into channels, which are listed in the sidebar on the left. Some channels we will use in this course are:

  • #general for general announcements about the class, you can select pinned announcements to find links to the course zoom page

  • #office-hours for class office hours. You can send a quick message to the professor here and start a zoom session to which s/he will attach.

  • #lab-X we will often move to slack after starting each lab session on the course zoom page. Here you can get individual help on your lab work, and we will check in with each lab group. You can type in short questions, but typically we will have you start a /zoom session to which we will attach.

Start a Zoom session in Slack

First choose the slack channel for the type of session (lab or office hours), then you can start a zoom session to which the professor/lab instructor/TA/ninja will attach and help you with your specific question(s) or just check in with you. To start a zoom session just type '/zoom'. If you are working on a partnered lab one of you and your partner can start, and the other can join.

In zoom you can share your screen to display and run your code, or display your homework to your instructor.

Accessibility

The course staff is committed to making all course material accessible to you. To access Slack’s accessibility settings, start by clicking on the workspace name at the top of the navigation pane on a laptop or desktop.

Then from the dropdown menu choose “Preferences”, then select “Accessibility” from the navigation bar on the left.

Options include:

  • Content magnification (“Zoom”). Allows you to enlarge content shown in Slack

  • Animation. Please uncheck this box if you are sensitive to animated images.

  • Keyboard. Options for non-mouse navigation.

To direct message someone

By default, messages posted on Slack are visible to all members of the workspace. But for smaller conversations, you can use Slack’s direct messaging (DM) feature to start a private conversation with one person or a small group.

Code of Conduct

The course Slack workspace is accessed by a wide variety of people all working in different environments and timezones. We ask that you be respectful of the staff as well as your fellow students. We expect you to follow these general rules:

  • Do not use Slack to harass faculty, staff, or other students.

  • Do not spam any channels or direct messages with garbage. Try to make posts in academic channels concise.

  • Follow channel guidelines. E.g. do not post idle conversations in the #lab-X channel.

  • Respect others’ time. When you are in lab, or in office hours, try to respond promptly to messages directed to you.

  • Note that any messages you post in a channel will be visible to everyone in that channel. Think before you post!

If there is a problem where someone is violating the code of conduct or otherwise failing to respect others, please raise the issue to one of the class professors or instructors.

tmux

tmux (and screen) are used to start sessions on a machine that you can detach from and keep running when you log out and then re-attach to later.

tmux is particularly useful for setting up an environment for remote lab work on a particular CS lab machine. You can then detach from the tmux session and logout, and later ssh back into the machine, re-attach to the tmux session and continue from where you left off.

tmux is also handy in that it allows you to create multi-panned windows in a single tmux session. For code development is it nice to have at least two panes: one for editing the file, and another for compiling and running. The CS department help pages has some information for getting started using tmux: CS help tmux page. Here, also, are a few basics:

## tmux commands from bash shell

$ tmux        # create a tmux session
$ tmux attach # attach to an existing tmux session
$ tmux ls     # list existing tmux sessions
$ tmux attach -t sessionname # attach to tmux session named sessionname
$ tmux kill-session -t sessionname # kill tmux session named sessionname


## tmux commands from within a session CNTRL-b initiates these
## first type CNTRL-b then one of the following keys to do:

CNTRL-b d             # detach from the current session
CNTRL-b an_arrow_key  # to move to a different pane within a session
CNTRL-b :             # get tmux prompt to enter all kinds of commands
                      # (ex. to create and configure panes)

Scrolling and copy/paste within a pane is a bit weird. Here are some commands for doing both:

# to scroll within a pane:
CNTRL-b [             # then use page-up and page-down to scroll in pane

# to copy from one pane only:
CNTRL-b [             # to copy from a pane:
  space               # start copying from curser
                      # move curser to end of what you want to copy
  enter               # stop copying at curser

# to paste into same or different pane (be in insert mode if pasting in vim):
CNTRL-b ]             # paste

Creating custom tmux sessions

It is often useful to write a bash script for creating a tmux session with a regularly used tmux set-up. Professor Newhall has an example script (mytmux.sh). that sets up a tmux session with 3 panes. It is designed to be useful for code development and testing, where the left-most pane can be used to run an editor (e.g. vim) to edit a source code file, and the right panes are useful for compiling, running, debugging, and other purposes. The script, when run, produces a tmux session that looks like this:

tmux example with 3 panes

  • you can run the script directly like this to start your own tmux session using this configuration:

    ~newhall/bin/mytmux.sh
  • or you can copy it over into your home directory, and edit as you’d like, and run it to start your own custom tmux session (really 2 panes might be enough and easier to manage):

    cd
    cp ~newhall/bin/mytmux.sh .
    chmod 700 mytmux.sh    # set this to executable
    ./mytmux.sh
    
    # open in an editor (vim, emacs, ...) to edit the file to customize
    # in a different way (we find that 2-3 panes is useful, and more than
    # that starts to make the session more difficult to use):
    vim mytmux.sh
avoid leaving old tmux sessions running

When using tmux (and screen), be careful about not leaving a lot of old sessions of yours running on lab machines. If you ssh into a particular machine each time you run tmux or screen (ssh you@machinename.cs.swarthmore.edu), this is one way to avoid leaving one running on a machine that you forget about.