Sohliloquies

Logo

I'm a security engineer with a lot of side projects, most of which find their way here. I like to center my research around computer security, cryptography, Python, math, hard problems with simple answers, and systems that uphold their users' values.

You can also find me on Twitter.

12 February 2015

Cheat Sheet: Windowing in Screen & Vim

As a lazy computer science student, I find myself working on programs over SSH a lot. This tends to pose some challenges. Unless you want to mess around with -X and -Y flags, all you get is one terminal to do all your work in. Having to work in this environment has taught me one lesson: When all you have is a terminal, everything looks like a window manager. Or something. Anyway. There are lots of ways to split up a terminal session, and this post covers some common commands involved.


My current modus operandi involves using GNU screen for terminal multiplexing so I can juggle an editor, man pages, a terminal, etc, without going completely insane, using Vim for editing because well ok let's not get started there, and using Emacs every now and then to play Tetris. This works well, but it involves a whole lot of hotkeys, and it's not easy to remember every single one. This post is the reference I keep wishing someone would write. It covers all the commands for each of these programs relevant to the task at hand.




 screen

Note: Screen prefixes all its commands with Ctrl-a to distinguish them from commands within any of its windows. This is written below as C-a. If you want to send C-a to a window, use C-a a.

Note also: Screen uses some possibly confusing nomenclature: the window-like areas displayed onscreen are called "regions", and the word "window" is reserved for the actual terminal sessions which a region may display. You can have no more than one window showing in any region, but you can have multiple regions showing the same window.


ActionCommand
Begin sessionscreen [-S <session name>]
End sessionC-a \
create a horizontal splitC-a S
create a vertical splitC-a |
close current regionC-a X
close all regions except currentC-a Q
switch focus to next regionC-a <tab>
switch window displayed in regionC-a C-a
choose window to display from menuC-a "
create and display a new terminalC-a c
shift current region's right borderC-a :resize -h [+n|-n]
shift current region's bottom borderC-a :resize -v [+n|-n]
Note: -h and -v may be omitted if only horizontal or only vertical splits are in use.






 vim

Note: Vim, unlike screen, uses the completely reasonable convention of referring to regions on screen as windows, and to the things windows display as buffers. This convention is followed here.

ActionCommand
create horizontal split:sp
create vertical split:vsp
change height of window by n:res [+n|-n]
change width of window by n:vert res [+n|-n]
move cursor to adjacent window
(in normal mode)

C-w [h|j|k|l]
open file buffer in window:e <file>
select file to open from interactive menu:E





Emacs

Note: You want your .emacs file to contain the following line:
(setq initial-major-mode 'tetris)


ActionCommand
Start Tetrisemacs
Exit TetrisC-x C-c

Here's hoping you find this as useful as I do!   :-)