Thursday, February 12, 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.


Action Command
Begin session screen [-S <session name>]
End session C-a \
create a horizontal split C-a S
create a vertical split C-a |
close current region C-a X
close all regions except current C-a Q
switch focus to next region C-a <tab>
switch window displayed in region C-a C-a
choose window to display from menu C-a "
create and display a new terminal C-a c
shift current region's right border C-a :resize -h [+n|-n]
shift current region's bottom border C-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.

Action Command
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)


Action Command
Start Tetris emacs
Exit Tetris C-x C-c

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

No comments:

Post a Comment