On 18/11/2010, at 11:25am, Neil Bothwick wrote: > On Thu, 18 Nov 2010 04:46:16 +0000, Stroller wrote: > >> If you're not using a GUI terminal emulator with a scrollbar, then may >> I respectfully suggest you install `tmux` (a replacement for GNU >> `screen`) and use it. It takes a little while to get familiar with it, >> and with its keybindings and stuff, and perhaps even to get into the >> habit and mindset of using it, but it really is brilliant, > > How does it differ from screen? Is it sufficiently better to relearn > keystrokes etc?
I wondered if I'd get asked this. The fundamental feature, I think, is that you can move a window from one session to another. This isn't something I've needed yet, but it seems like it could be useful if you need it. tmux has panes within windows - I'm not sure if screen has that? tmux is supposed to be more efficient, better architected and use a fraction of the resources of screen. tmux doesn't have an equivalent of `screen -Rd`, which tells screen to "start working in an existing session, or create a new one if that doesn't work". So I have `tmux a -d || tmux` in my Bash scrollback buffer, and run it as soon as I log on. You absolutely *have* to change tmux's default control key. It was set to ctrl-b to avoid collisions with screen's ctrl-a when the author was first developing it, when he was still using screen himself, and it has never changed. I originally wanted to "stay with the default bindings" so that I'd be familiar with them "just in case I ever sometime had to log on to a different system without a personalised .tmux.conf". It drove me crazy very quickly - because "b" is on the wrong side of the (qwerty) keyboard you can't activate tmux controls one-handed until you change it back to ctrl-a. Obviously it's very easy to change the bindings. I will hereafter refer to ctrl-a as the default and as if it were the default, because that's what everyone immediately changes it to. Because of tmux's architecture you can change options "on the fly" in a way that (I think) you can't with screen. If I want to change the key binding I can just type `tmux set -g prefix C-a` (or `tmux set -g prefix C-b`) and the change happens immediately. I think this is because the tmux command is not starting the tmux program, but instead talking to the existing tmux server (which was started when I ran just `tmux` with no parameters). Oh, you can apply changes only to particular sessions or windows - the "-g" before stands for global, but I think you could have different sessions as different colours, if you wanted to. Likewise, with screen you can press ctrl-a then the " key to show what windows you have open. With tmux this is `ctrl-a w`, but you can also type `tmux list-windows` (or `tmux list-w` for short) at your bash prompt and get the same thing on stdout. You could grep that if you wanted to and I think you could use that output to make functions or bash scripts that act upon it. You can do the `ctrl-a :` thing first and enter the tmux command-line if you want to - in that case it would be `ctrl-a :list-windows` without the `tmux` in front - but you don't have to, and I find it clearer and more useful to have the output on stdout. I believe the scrollback buffer on tmux is better, and that you can copy and paste from it in ways that you can't with screen. The default key binding to enter scrollback is `ctrl-a [`, instead of `ctrl-a esc` - I'm not entirely sure how I feel about that yet. Navigating in scrollback you can choose between vi and emacs keybindings (for page up, page down &c). I think what really won my heart, and did so quite quickly, is that tmux has a status bar configured by default. I'm pretty sure you can do that with screen, too, but I've never bothered, because it seemed too much effort to learn and it just seemed flashy and pointless. I realised how mistaken I was within a couple of hours of using tmux. It has absolutely changed the way I use terminal multiplexers, and so I spent several hours the next day configuring mine and getting the colours and stuff perfect. The status bar makes navigating between windows much easier because you can see at a glance which window is which, and what's going on in them. If you don't name a window then tmux will try to show something sensible for the window title, so they show "emerge" or "vi" or "sudo" or "bash" without you having to do anything. And this will change, when the command finishes and you run something else, so basically naming windows becomes redundant and less useful. tmux will also do slightly intelligent searching, so you type `ctrl-a f` then `eme` it will suggest the window in which emerge is running. But mostly I don't need to do tricks, because I have the status bar there showing me what's happening in which window, so I tend just to switch to windows numerically. I think having the status bar actually kinda gives you a better "spatial orientation" or a mental representation or something of the virtual windows, and it becomes more intuitive to know which one is "next" to another and where they are in relation to each other. tmux has `ctrl-a l` to switch between two windows, a bit like if you used `cd -` a lot in the shell; you can just `ctrl-a l` repeatedly to switch between two windows (say the one you're working in and the one you're viewing results in), then you can `ctrl-a 7` to go to a third window. tmux has `ctrl-a p` and `ctrl-a n`, of course, but in screen that tended to be my *major* way of navigating, and I think that's because I didn't know where I was; now it's less so, and I feel like I'm using tmux better than I used screen. Also, tmux has a shortcut bound by default for renumbering windows, `ctrl-a .`. So say I'm working in mostly windows 3, 4 & 5, and I start a process in one of them which is going to take a while - I just `ctrl-a .9` and the window is "thrown out of the way" and becomes window 9, which resides on the right-hand side of the status bar. I can now `ctrl-a p` and `ctrl-a n` between the two remaining windows, or I can `ctrl-a c` to create a new one, which will probably fall in the gap I just left (but if not I can renumber it easily). I've rambled on a bit here, and I guess to some people who have never used screen in the first place it'll all sound a bit WTF (if they're not familiar with the terminal-emulator virtual windows idea that screen originally introduced) and quite possibly if you're a screen power user you might be able to point out inaccuracies in what I've said, or the improvements may sound minor, or they're things that you've already configured in your own .screenrc The TL;DR, though, is that I think it's very sensible of tmux to have a status bar by default and quite an oversight of screen not to, and that tmux is generally better than screen in ways that are quite small and subtle when taken separately, but which all together make for a nicer experience. To me it feels like a *much* nicer experience and I get the feeling that I'm not alone - there's a thread about this on the Arch forums <https://bbs.archlinux.org/viewtopic.php?id=84157>. Also: <http://news.ycombinator.com/item?id=1098564>. Stroller.