12 ms·
A minimalist guide to tmux
- NelsonMinar 9y agoSomehow I've never made the jump from screen to tmux. 20+ year old habits die hard. This guide is nice but doesn't really show anything you couldn't do with screen too.
- mhd 9y agoSure, I think the initial reason was a cleaner codebase and BSD licensing. Feature-wise I doubt that it would matter for 90% of the users, but then again, probably a lot for 1% (who really like one particular feature a lot). I generally set up both the same way and sometimes even forget what I'm currently using.
- vostok 9y agoI agree on the cleaner code, but I actually prefer the screen license.
- mhd 9y agoI meant it was one of the reasons why tmux was written, not why I (partially) switched. Not that I see a big difference in the first place, but if the BSD folks want to play the GPL cleanup game, good for them, at least we're getting some software out of it and it doesn't just mean that Apache 1.3 will never die…
- karmakaze 9y agoI would also have preferred just enough more to be using tmux rather than a screen alternative. It got me using it tho, Thanks. And a semi-random link to more plus what I'd wish I'd seen: C-a " split vertically (top/bottom) C-a % split horizontally (left/right) C-a left go to the next pane on the left C-a right (or one of these other directions) C-a ; go to the ‘last’ (previously used) pane C-a M-left resize by 5 columns C-a M-right https://gist.github.com/andreyvit/2921703 https://gist.github.com/andreyvit/2921703
- arca_vorago 9y agoIts worth noting I've made a conscious choice to gplize my tool stack, so despite tmuxs lower learning curve, I still think screen is the way to go.
- dotancohen 9y agoI've done the same, but I do allow for MIT-licensed tools as they have no more risk of disappearing than GPL tools. In fact, you could fork your MIT tools and share them on Github under the GPL if need be. The Tmux license is ISC, which for all intents and purposes is identical to MIT. I do make a few exceptions, though. I stay proficient in VIM and use it for personal projects, but I use the Jetbrains IDEs for professional projects. It really is good enough to justify the price and license.
- arca_vorago 9y agoIf you are right you are blowing my mind right now... Is it true I could fork an MIT licensed project and make it GPL? I've tried very hard to understand licensing but perhaps I missed that.
- dotancohen 9y agoGoogling around I see some dispute on the topic, but (IANAL) to me it is clear: > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. So long as you keep the copyright notice, you are free to add additional restrictions such as those specified in the GPL (keep it open, pretty much). You might want to ask here to clarify, if you do then please post a link here in a reply: https://opensource.stackexchange.com/ https://opensource.stackexchange.com/
- zipperhead 9y agoWith tmux being more client/server based, it's more scriptable. You can run tmux commands inside or outside of tmux session which is really useful - for example you can use send-keys to perform actions within a session. You can pretty easily script things like initial session/window/pane configuration. I'm not sure you can do that with screen.
- Izkata 9y agoscreen has "-X" for sending commands to remote sessions, and there's a command "stuff" for inserting text: screen -S Testing # Create a named screen for examples: screen -S Testing -X screen watch date # Run "watch date" in a new window on the remote session screen -S Testing -X next # Switch back to the initial bash session screen -S Testing -X stuff "cd /\n" # Type "cd /" and hit enter
- aorth 9y agoI used GNU screen for ten years or so and then switched to tmux in 2013. My tmux config to mimics screen's in most places, (prefix key, copy mode, etc). As others have pointed out, tmux has a newer code base, support for newer terminal features, less security vulnerabilities, etc. I've never looked back. https://github.com/alanorth/dotfiles/blob/master/.tmux.conf https://github.com/alanorth/dotfiles/blob/master/.tmux.conf
- marktangotango 9y agoI’ve never found a solution for this, so I’ll ask here; I always have a problem where vim in a screen session fails to display syntax highlihting, and TERM is xterm in both, any idea? Specifically I’ll ssh to a remote and vim an Apache config is highlighted, start screen, vim the same file and no highlighting.
- u801e 9y agoI haven't had that problem. I start screen using the -T parameter with a value of xterm-256color. Do you get color output with ls or grep outside of screen, but not within a screen session? That may narrow down the problem to vim rather than screen.
- tfmatt 9y agoTwo things to try after opening a new screen window: 1) Enter "bash" then vim file.java (some file) 2) Enter :syntax on
- pfranz 9y agoI picked up tmux instead of screen years ago and wish I had stuck with screen. screen has more ubiquity. Even if tmux is installed, it might be too old and not contain the features I need. Hopefully, those problems solve themselves, but it might take a decade or two.
- colordrops 9y agoChange the tmux key binding from ctrl-b to ctrl-a and you are most of the way there. Just do it.
- girishso 9y agoif only tmux could scroll through the screen using mouse. Keyboard scrolling is a big no for me.
- erezyehuda 9y agoPretty sure C-b,[ will do that.
- TechHermit 9y ago`set -g mouse on` should be all that's necessary to enable mouse-wheel scrolling for tmux version 2.1 and up. This works for me. https://superuser.com/questions/209437/how-do-i-scroll-in-tmux https://superuser.com/questions/209437/how-do-i-scroll-in-tm...
- supermdguy 9y agoWow, thanks! I've been using tmux for about a month now to connect to my server, and I never knew this was possible.
- misnome 9y agoJust to add a note that I updated recently and the mousewheel scrolling behaviour stopped and sent up/down terminal history commands instead. If this happens, there is a thread on the tmux github issues with some workarounds. I’m pretty new to using tmux as more than a basic screen replacement, but it seems flexible enough that almost anything you want can be configured.
- rhinoceraptor 9y agoset -g mouse on will do that. And it is smart enough to know if you're using an interactive program such as vim, it will let vim scroll.
- tempay 9y agoIf you're on macOS, iTerm2 has support for using control mode in tmux so the tabs/panels are real tabs and panels and can be scrolled normally. I don't know if any alternatives exist for Linux/Windows. https://gitlab.com/gnachman/iterm2/wikis/TmuxIntegration https://gitlab.com/gnachman/iterm2/wikis/TmuxIntegration
- mxuribe 9y agoNice guide; short and to the point!
- riazrizvi 9y agoAlso the all important ‘C-b D’ for when your tmux session is frozen. That’s upper case d. When the wireless connection on your machine changes, tmux freezes. Attempting to detach other clients with this command, immediately restores responsiveness.
- elldoubleyew 9y agoGreat tip. Did not know this command, I've been killing my terminal and opening a new one to reattach for the last two years.
- crispinb 9y agoI’ve never had this happen, and I’m in a rural area with often unstable connectivity. I do use mosh though, who perhaps that’s obviating this.
- a_t48 9y agoThanks for the tip - because I have differing MTUs across my systems (the stuff I do at work requires jumbo frames for adequate network performane and getting it right between a windows box and two Linux boxes is hard) I sometimes get a network hang. I'll be sure to try this next time it happens.
- sls 9y agoBest thing I ever did for tmux was change the command key prefix to "C-\". With caps lock mapped to control, this makes tmux commands available with almost no hand motion, just a slight reaching out with the pinkies. It also restores access to C-b for "back one character" in emacs and all programs using emacs key bindings, which is hardwired into my fingers at this point. (You're blocking emacs' function "toggle-input-method" - "Enable or disable multilingual text input method for the current buffer". For some users that would probably be an issue, but hasn't been for me.) Another useful thing is to "bind-key C-\ last-window". That makes C-\ C-\ jump back to the last window you visited, which facilitates creating short-lived windows for specific tasks. Final small tweak I like is "set -g base-index 1" so that C-\ 1 is the first window, 2 is the next, etc. instead of having the first window way over on 0. My other tweaks are probably more idiosyncratic to my workflow.
- jwr 9y agoGood heavens, how do you send SIGQUIT to your programs then?
- c256 9y agoGiven that the context means that there’s always a shell available, presumably ‘with kill -QUIT’. I got into this habit myself many years ago, when varied access methods made it uncomfortable to rely on having a full range of key-bindings.
- sls 9y agoAs c256 surmised, I use kill to send signals other than SIGKILL. I don't think I've ever even known about the C-\ or C-y bindings for SIGQUIT. I also hardly ever use shell job control, to the extent that I have an alias fg that does something unrelated, so I would need to say \fg to get the shell foreground command. But if for some reason I wanted to do that, I would use C-\ : send-prefix. That sends the prefix character to the process running in tmux, in this case the shell. It's also super useful if you ever find yourself running a nested tmux (i.e. in an ssh session) with the same prefix character. You can just send-prefix d to disconnect the remote shell from the remote tmux session, then open a new local shell outside of your local tmux session, log in and reconnect to the remote tmux.
- rmetzler 9y agoAdd mosh [0] to connect to the server and tmux on the server and you can close your laptop lid, travel, open it again and your processes still run on the server and you're connected. [0] https://mosh.org/ https://mosh.org/
- mhd 9y agoYeah, if only I could have the same thing for ssh tunnels, I'd be in suspended heaven.
- yjftsjthsd-h 9y agoDoes autossh help?
- nirv 9y agoThere's an open bug bounty[1] for that feature[2]. Just in case. [1] https://www.bountysource.com/issues/4471419-ssh-port-forwarding-doesn-t-work https://www.bountysource.com/issues/4471419-ssh-port-forward... [2] https://github.com/mobile-shell/mosh/issues/337 https://github.com/mobile-shell/mosh/issues/337
- joatmon-snoo 9y agoQuestion: what do people use as their prefix? I started using tmux last week, and although it's mostly been a good experience, I still haven't been able to settle on a good prefix. I find C-a to be a terrible choice because I actually use that for command line navigation, and so in the meantime I've tried settling on C-q, but it just feels awkward at times. (Note that I've remapped Caps Lock to Ctrl.)
- 6ak74rfy 9y agoI have been using C-q for many months now, and it works fine for me.
- webreac 9y agoI find also C-a to be a terrible choice. At work, we have screen instead of tmux. I have configured screen to use C-b like tmux default.
- vowelless 9y agoKind of related, I actually use tmux-modality to add vim style modality to tmux. For this reason, I don't often use the prefix. I switch to "command mode" to do certain operations (resize panes, change windows, etc).
- auvrw 9y agohere's the config to use an emacs-like C-x prefix and xmonad-like joker/klown pane selection https://github.com/ransomw/dotfiles/blob/master/tmux.conf https://github.com/ransomw/dotfiles/blob/master/tmux.conf along with a rant about what terminal multiplexers are in the first place https://github.com/ransomw/dotfiles#tmux https://github.com/ransomw/dotfiles#tmux ... both are wip, suggestions welcome
- hetman 9y agoI've always used C-f. Very comfortable for me but I haven't seen anyone else use it. Importantly it keeps my fingers on the home row keys. I tend to use VIM navigation in my terminal so I don't miss that binding (although there's plenty of other keys in the general vicinity).
- 9y ago
- softinio 9y agoi use iterm2 and neovim. Is it worth using/adding tmux for local development? As Iterm2 has split panels and some level of saving your session and neovim built in termnial I feel tmux may not be needed for local development or am I missing something?
- crispinb 9y agoI use tmux for doing stuff on servers, but rarely bother locally. The main reason I can think of to do so is if you routinely use a specific multiple shell setup for some particular project —- eg. a tail, an editor and a ready prompt. Otherwise I don’t see much point (though it’s not an issue I’ve explored much). Btw as you’re an iTerm user you might want to read up on its tmux integration, which is quite cute.
- jfoutz 9y agofor a little while i used #!/bin/bash tmux split-pane -b -p 30 -d; tmux send-keys -t {up-of} 'nyancat^M' "$@" tmux send-keys -t {up-of} '^C' tmux kill-pane -t {up-of} to pop up an obvious animation for longer running processes. like vm startup. When the animation disappears the thing is ready to go. Haven't been bothering with tmux local lately though.
- crispinb 9y ago`nyancat` (as a shell command) puzzled me briefly. Now I see. Not available on macOS, except for unfortunates with a new macbook 'appointed' with a fake keyboard: https://github.com/avatsaev/touchbar_nyancat https://github.com/avatsaev/touchbar_nyancat
- jfoutz 9y agoBrew has a terminal animation. It’s cute. http://brewformulas.org/Nyancat http://brewformulas.org/Nyancat
- padthai 9y ago
- cf 9y agoWhat are people doing to cycle through windows on nested tmuxes? I often hide the outer tmux captures keybindings before the inner one can see them.
- nine_k 9y agoType the prefix more times?
- sls 9y agoAs I noted above, the tmux command send-prefix will send the command prefix character to the process tmux is managing. So if you open a connection to a remote system and run/connect to a tmux session there, and you have the same command prefix for both systems, you can <command prefix>:send-prefix<enter> to e.g. disconnect and reconnect from a shell that's not running tmux. If you're going to be doing this on purpose and fairly often, you might consider binding a key for send-prefix. I would prefer not to have to remember which tmux I was talking to all the time and so I would just connect from a normal shell, but ymmv of course.
- Bromskloss 9y ago> Keeps windows and panes in a session (which stays alive even when the internet disconnects) Does that mean that tmux eliminates the need for mosh [0]? [0] https://en.wikipedia.org/wiki/Mosh_(software) https://en.wikipedia.org/wiki/Mosh_(software)
- zbentley 9y agoNo. Mosh handles automatic reconnection (and a bunch of other stuff, like predictive typing so you don't notice flickering or slow connections, and performance improvements); tmux runs a persistent process on the remote side that preserves the state of your sessions. Using mosh + tmux allows you to have both a) state persisted on the remote side, and b) automatic reconnects if your internet drops, or if you change connections. It's a very good combination, if you can handle some of the drawbacks of mosh (no in-terminal scrolling, mostly, but you can outsource that to tmux as well at the cost of a little lag). A good additional piece of the puzzle is tmux-resurrect [1], which saves and automatically restores a lot of your tmux state to the filesystem so it's proof against power loss and system restarts/relogins. It persists window arrangements and similar, though it obviously can't save everything--the state of programs that were open can't be programmatically preserved (though that's getting closer and closer to seamless with the advent of things like CRIU). The combination of mosh + tmux + tmux-resurrect is a very popular one and creates a very resilient system for "don't make me think; just log me in to my usual environment"-type systems, or environments where internet connectivity is spotty or the tmux server environment is unreliable or prone to rebooting. [1] https://github.com/tmux-plugins/tmux-resurrect https://github.com/tmux-plugins/tmux-resurrect
- ekianjo 9y agoThis article a useless. It's like telling you that you can live with knowing 0.1% of Tmux's functionalities. Does not even tell you how to create panes, resize them, move them around... which should be in the basic stuff you describe to any user.
- Cyberdog 9y agoIt's a start. That 0.1% will be enough or some people, and once they get that much down, learning about the other functionality will be simple should they desire to seek it out.
- ekianjo 9y agoIt would not have taken much more time to explain panes at least. This just sounds like a lazy article.
- markbnj 9y agoPeople who haven't used it need to start somewhere, and the author specifically says why panes were not addressed. "Useless" is a pretty harsh write-off.
- neals 9y agoI read a lot of you are really customizing the configuration. How do you manage that? I work on dozens of servers and spawn and destroy a few everyweek. Do you run some kind of sync tool to get your personal config up and running? Where do you store that?
- tga 9y agoTake a look here for several good options: https://news.ycombinator.com/item?id=15196141 https://news.ycombinator.com/item?id=15196141.
- zhann_dc 9y agoIf you use your terminal all day, do yourself a favor and learn readline shortcuts [1]. Once you have you might stop overwriting these, because imho C-a is a terrible prefix and very handy to move to the beginning of a line. [1] http://www.bigsmoke.us/readline/shortcuts http://www.bigsmoke.us/readline/shortcuts
- justsid 9y agoThis is why I love macOS so much! With the command key, there is no overlap for things like copy and paste and ctrl + c/v. Also Cocoa implements things like ctrl + a/e etc for every native textfield and textview, so I‘ve gotten really used to it. Too bad now I‘m mostly on Windows and miss all these shortcuts. In programs where I can edit the keymapping, I usually change ctrl + a from Select All to jump to beginning of line. I barely use Select All anyway.
- Graziano_M 9y agoI use a mac, but sometimes have to use office tools. They don't use readline shortcuts and it drives me absolutely mad when I hit Ctrl-H (backspace) and the help window pops up.
- guitarbill 9y ago`C-a, a` sends `C-a` to muxed terminal. Sure is a bit harder to remember, but not much. IMO the biggest mistake tmux made was not using C-a by default. I don't know anybody who doesn't remap it - it's far more convenient keyboard-wise, and it sets you up for using `screen` on servers where tmux isn't installed. So go ahead and remap it.
- jug5 9y agoOr you know just set vi mode
- Graziano_M 9y agoI used Ctrl-A for years. I've since switched to Ctrl-o so I can use Ctrl-A for its readline behaviour (which is where `;` is on most keyboards), and I have Ctrl on capslock, so my prefix is a quick tap with both my pinkies.