Published 2015-09-14.
Time to read: 3 minutes.
Tmux is a console window pane manager that is very effective for Scala programming if you are familiar with vi or emacs.
tmux is a terminal multiplexer.
It lets us use a single environment to launch multiple terminals, or windows, each running its own process or program.
tmux
is quick, flexible and sessions can be made to be persistent.
You might be interested in the book entitled , by Brian Hogan.
Tmux does not require vim
or emacs
, but you should either use vim
or emacs
with
tmux
in order to get full benefit.
I use vim
.
Here are some video tutorials on vim.
Practical
is a good book.
Installation
Mac
$ scala> brew install tmux
Install iTerm as discussed in the Installing Scala lecture
and use iTerm to launch tmux
.
Ubuntu
tmux
is installed by default.
Windows
I’ve tried running tmux
on ConEmu and Cmder.
That was not a pleasant experience.
The new Windows Terminal and Console API should show usable results in the early fall of 2019.
All OSes
To start tmux
on every shell login, or connect to the default session if
it exists, add the following at the end of ~/.bashrc
, ~/.bash_profile
or ~/.profile
.
# If running ConEmu do not run tmux [[ "$(set |grep -i conemu)" ]] && return # Only run tmux if running interactively [[ $- != *i* ]] && return [[ -z "$TMUX" ]] && tmux attach || tmux
Settings
These settings work on all operating systems.
Store the contents of the gist shown below in ~/.tmux.conf
.
Here is what the settings do.
- Changes the key binding prefix that you need to type before issuing a
tmux
command from Ctrl-b to Ctrl-a. - Enables mouse control of window panes.
- Creates new panes with the same current directory as the previously active pane.
- Changes vertical and horizontal window split key bindings to the
tmux
prefix followed by \ and -, respectively. - Uses the default enter copy mode key binding:
tmux
prefix Ctrl-[. - Uses the default paste buffer key binding:
tmux
prefix Ctrl-]. - Launches the
bash
man
command with the key binding:tmux
prefix /. - Reload
tmux
configuration file (~/.tmux.conf
) with the key binding:tmux
prefix r.
Key Bindings
Key bindings used in the remainder of this lecture are.
tmux
- Ctrl-a \ split the current pane vertically.
- Ctrl-a - split the current pane horizontally.
- Ctrl-a d detach the
tmux
session. Reconnect withtmux attach
(this is done automatically when you log in if you follow the installation instructions in this lecture). - Ctrl-a left-arrow make the pane to the left active.
- Ctrl-a right-arrow make the pane to the right active.
- Ctrl-a up-arrow make the upper pane active.
- Ctrl-a down-arrow make the lower pane active.
vi
- : Explore open file using file browser.
- : w write (save) file in buffer.
- : b w close file in buffer without exiting
vi
. - : help tutor run built-in vi tutorial.
Sample Session
- Start a new session in the
courseNotes/
directory:Scala REPL$ scala> tmux
- Create a new vertical pane: Ctrl-a \
- Make the original (left-most) pane active: Ctrl-a left-arrow
- Open
vi
in the currently active pane:Scala REPL$ scala> vi
- Browse to a Scala source file: : Ex tab (expands to
Explore
) Enter
- Use arrow keys and Enter to navigate to the
src/main/scala
directory. SelectTypeHierarchy.scala
and pressEnter
.
- Make the right-most pane active: Ctrl-a right-arrow.
- Cause the project to be compiled and run the
DogHog
console application any time that a file in thecourseNotes/
directory tree is modified (we discussed how SBT tasks can be triggered when the source tree changes in the SBT Tasks and Settings lecture):Scala REPL$ scala> sbt ~"runMain DogHog"
- Go back to the edited file, add a new blank line at the top, and save it: shift-O (that is capital "o")
Esc : w.
Notice that the project recompiles in the rightmost pane and
DogHog
runs there.
-
Delete the blank line you inserted and save the project: d d : w. Notice that the project recompiles in the rightmost pane and
DogHog
runs.
- Reattach to the
tmux
session:Scala REPL$ scala> tmux attach
Everything appears just as you left it.
- Make the right-most pane active and create a new pane under it: Ctrl-a right-arrow Ctrl-a -
- Open an SBT console in the new pane and enter a Scala expression:
Scala REPL
$ scala> sbt console ... lots of output ...scala> scala>scala> 2+3 res0: Int = 5
- Grab pane borders with the mouse and resize them.
- Rotate the panes: Ctrl-a Ctrl-o
- Rotate the panes twice more so they go back to how they were: Ctrl-a Ctrl-o Ctrl-a Ctrl-o
- Make the top right pane active: Ctrl-a up-arrow
- Make the left-most pane active: Ctrl-a left-arrow
- Close the file that you are editing without exiting vi: : b w Enter
- Detach from the
tmux
session: Ctrl-a d
Deeper Integration of Scala with vi
(This section is in process)
Now whenever you start
vi
:
$ scala> mkdir -p ~/.vim/autoload ~/.vim/bundle
$ scala> curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
$ scala> echo "execute pathogen#infect()" >> ~/.vimrc
$ scala> git clone https://github.com/adinapoli/staircase.git ~/.vim/bundle/staircase
vi
from an SBT project, Staircase will automatically run SBT console.
git clone https://github.com/scrooloose/syntastic.git .vim/bundle/syntastic
cat >> ~/.vimrc <<EOF
" Sysastic settings from https://github.com/scrooloose/syntastic#3-recommended-settings
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
EOF
© Copyright 1994-2024 Michael Slinn. All rights reserved.
If you would like to request to use this copyright-protected work in any manner,
please send an email.
This website was made using Jekyll and Mike Slinn’s Jekyll Plugins.