This config aims to make tmux comfortable for vim users. Below are some highlights and possible workflows.
Notation: We'll use C-spc
to mean "hold control, and tap the spacebar".
Most of the time in tmux, you're in normal mode. When you type things, they go into your shell, and your shell can run them. You can also run the following commands.
C-spc c
-- create a new windowC-spc 1
-- switch to window 1C-spc 9
-- switch to window 9C-spc C-spc
-- switch to most recent other windowC-spc ,
-- rename this windowC-spc |
-- split window vertically (creates a new "pane")C-spc -
-- split window vertically (creates a new "pane")C-spc h
-- switch keyboard focus to the pane to the leftC-spc j
-- switch keyboard focus to the pane belowC-spc k
-- switch keyboard focus to the pane aboveC-spc l
-- switch keyboard focus to the pane to the rightC-spc z
-- Zoom!
bash
you can close them with exit
or C-d
.C-spc [
-- enter movement modeC-spc ]
-- paste text that you previously copied in movement modeMovement mode is like being in vim. You can move around using vim movement keys. You can highlight things. You can copy things to a clipboard, for pasting later (in normal mode).
h
-- go leftj
-- go downk
-- go upl
-- go right0
-- go to the beginning of the line$
-- go to the end of the linew
-- go foreword by one Wordb
-- go Backward by one wordfx
-- go Foreword until you hit the next x
character. Also works for any
other character instead of x
.Fx
-- go backward until you hit the next x
character. Also works for any
other character instead of x
.tx
-- go foreword unTil just before you hit the next x
character. Also
works for any other character instead of x
.Tx
-- go backward unTil just before you hit the next x
character. Also
works for any other character instead of x
./
-- search forwards?
-- search backwardsn
-- jump to the next thing that matches your last search (in whatever
direction you were already searching)N
-- jump to the previous thing that matches your last search (in whatever
direction you were already searching)v
-- start highlighting character-by-character (you can continue to highlight by moving around)V
-- start highlighting line-by-line (you can continue to highlight by moving around)y
-- copy whatever is highlighted to the clipboard (so you can paste later
in normal mode). This also puts you immediately back into normal mode.ESC
stop highlighting or searchingq
stop being in movement mode -- go back to normal mode.I'm in tmux, and I have a single terminal in a single pane in a single window.
I have a list of handy commands in a file called handy-bash-commands.txt
. I
want to use one of them. I'm going to cat the file, copy the appropriate command
to clipboard, paste it into my shell, and see the results of my cool command.
Let's break that into steps:
First I cat the file:
$ cat handy-bash-commands.txt
handy-command 1
handy-command 2
super cool command
sudo super cool command
another command
more stuff
$
Now my cursor is at the shell prompt as I would expect. I hit C-spc [
to get
into movement mode, then hit kkkk0
to move my cursor to the beginning of the
line that reads sudo super cool command
. To highlight the whole line, I hit
V
. To copy it to clipboard, I hit y
. This also kicks me back into normal
mode, with my cursor at the shell prompt again. To paste and run the command, I
hit C-spc ]
. Note that the reason the command runs as soon as I paste is is
because I copied a newline to clipboard when I highlighted and copied the whole
line earlier.
Here's the result:
$ cat handy-bash-commands.txt
handy-command 1
handy-command 2
super cool command
sudo super cool command
another command
more stuff
$ sudo super cool command
SUPER COOL OUTPUT!
$
Now I want to run something similar to handy-command 2
, but with a slight
difference.
My cursor is at the shell prompt as I would expect. I hit C-spc [
to get
into movement mode, then hit ?handy<ENTER>
to move my cursor to the beginning of the
line that reads handy-command 2
. I'm only interested in the beginning of this
command, so I hit v
to start highlighting character-by-character. I hit ww
to highlight the words handy-command
. I hit y
to copy those words to the
clipboard. This also kicks me back into normal mode, with my cursor at the shell
prompt again. To paste the command, I hit C-spc ]
. Because I didn't copy any
newlines, the command doesn't run immediately, and I can edit it.
Here's what my terminal looks like now:
$ cat handy-bash-commands.txt
handy-command 1
handy-command 2
super cool command
sudo super cool command
another command
more stuff
$ sudo super cool command
SUPER COOL OUTPUT!
$ handy-command
Now I'm free to complete the command as I wish, and run it as normal:
$ cat handy-bash-commands.txt
handy-command 1
handy-command 2
super cool command
sudo super cool command
another command
more stuff
$ sudo super cool command
SUPER COOL OUTPUT!
$ handy-command 65537
Wow, that's a really cool number. Are you a big fan of regular polygons?
$