9 ms·
Tmux – The Essentials (2019)
- eu 2y agoit's missing changing Ctrl+B to Ctrl+A: # ~/.tmux.conf set-option -g prefix C-a
- ravoori 2y agoYou must mean changing Ctrl-B to Ctrl-A
- anyfoo 2y agotmux changed screen's C-a prefix to a more sensible C-b. C-a is pretty universally used as "jump to beginning of line", which for screen meant that you'd have to git "C-a a" instead all the time. Seriously annoying, and therefore lots of screen configs changed the prefix away from C-a for that reason.
- yjftsjthsd-h 2y agoOkay, but C-b is "go back one char" and that's also pretty common? I'd personally lean towards saying maybe either C-z or C-s are better? Because suspending a process is a lot less useful when you've got a full multiplexer, and C-s is just... I guess somebody uses it, but I don't think I've ever used it on purpose and it's kind of annoying to accidentally freeze your terminal (and again, tmux has an actual scrollback mode which seems like it covers that use). Edit: Oh hey, https://superuser.com/questions/74492/whats-the-least-conflicting-prefix-escape-sequence-for-screen-or-tmux https://superuser.com/questions/74492/whats-the-least-confli... is a whole discussion of options
- anyfoo 2y agoGood point. Though C-s is fine unless you have software scroll control enabled, and it's used in emacs and anything that follows its key bindings very often as well for incremental search forward. (It's not used in the shell even though that typically implements emacs bindings, because there you usually want to incrementally search backward, i.e. C-r.) I think C-z is the perfect candidate for the reasons you mentioned.
- actinium226 2y agoBut, go back one char is also left arrow. Why do you need another key for that?
- reactordev 2y agoWe didn’t have arrows back then
- jwiz 2y agoLeft arrow is not where my fingers are, but ctrl-b is. I would have to move my whole hand over to the arrow keys, or I can use the edge of my right hand (on a full size keyboard, not laptop) to hit ctrl, and hit "b" with my left index finger.
- aaronbaugher 2y agoI use F2. Unlike the arrow keys, I don't have to move my hands and I can hit it reliably. I use it enough that I want it within reach, but not so often that I need it on the home row, and all Ctrl combinations there are already tied to emacs operations in my mind.
- yjftsjthsd-h 2y agoWhat, and move my entire hand to the far side of the keyboard like some sort of savage? (But seriously, I actually do prefer avoiding moving my hands for ergonomic reasons.)
- fragmede 2y agoYou should do whatever you want with your hands, but you should be aware that not moving your hands is bad for ergonomics. It promotes static posture and staying in one position for too long can cause muscle stiffness and strain. Moving around promotes blood flow and reduces fatigue. Consistent doing a small set of motions (ie never moving your hands) is what leads to RSI. Of course, a bad setup is a bad setup, and if you're moving your hands a lot because your workspace is poorly setup, you'll also have issues. For best results, you'll want to keep your hand movements natural and comfortable and your tools within easy reach. Take short breaks to move your hands, as well as your entire body.
- theshrike79 2y agoI can easily tap C-a with one hand with very minimal hand position change. C-b requires me to move my whole hand to reach both keys with my left hand. Thus: C-a wins
- ink_13 2y agoI set it to backtick (`) No need for that character 99% of the time, and hitting two in a row will still send it anyway
- ledauphin 2y agothis is the way. also works great in combination with `set -g base-index 1` so that switching between the first 9 windows can be done naturally, with `-1, `-2, etc.
- axiolite 2y agoI use backticks in shell scripts all the time. Meanwhile, I've never had a legit use for: Ctrl-y so that's my tmux escape.
- mdaniel 2y agoI don't intend this to yuck your yum, but if you haven't seen it shellcheck advises against backticks because they don't nest unlike $(basename $(dirname "...")) along with some other edge cases https://www.shellcheck.net/wiki/SC2006#rationale https://www.shellcheck.net/wiki/SC2006#rationale and https://mywiki.wooledge.org/BashFAQ/082 https://mywiki.wooledge.org/BashFAQ/082
- axiolite 2y agoI find most of shellcheck's opinions quite arbitrary. Wider shell compatibility is a good reason to use backticks. Avoiding nesting is always possible. Quoting may be a concern in more complex usage. But yes, I know well, and often also use $( ) syntax. Making a lot of noise about use of (the shellcheck author's) non-preferred syntax, which works perfectly fine in a given context, is a design flaw that renders shellcheck useless to me. I'm perfectly capable of finding an opinionated pedant on my own who will also critize the syntax I use (with little or no justification), and offer no actual help...
- tambourine_man 2y agoI use C-Space, easy to type, doesn’t conflict with other shortcuts
- _imnothere 2y agoUhh... only if you're not a CJK-language-user, C-Space is a common shortcut to switch between IME state.
- anyfoo 2y agoI like tmux a lot, but like its predecessor "screen" I mostly use it for explicitly running long-lived jobs (i.e. for its detach feature), and for very special situations where I have elaborate tmux window configurations with dedicated stuff running in each window/pane. Note that I have been using text-only terminals since the 1980s, but I've adapted my tty usage over time. The problem that tmux (or screen) brings are first and foremost: * Smooth/fast scrolling goes away. I can no longer give my trackpad a slight push to find myself tens or hundreds of lines in the scrollback history, and visually scan by slightly pushing my fingers back and forth. Instead I have to use the horrendous in-tmux scrollback using "Ctrl-b [". * My terminal app's tabs and windows are not tmux's tabs and windows. I cannot freely arrange them in space, snap them off with the mouse, easily push them to another desktop, and so on. I have to start a multiple tmux clients and do awkward keyboard interactions with them for any of the same. * tmux's terminal emulation and my terminal emulator's terminal emulation (heh) are not congruent. As a result, programs cannot make full use of my actual terminal's capabilities. For example selecting, copying, and pasting text sometimes behave weirdly, and there are other annoyances. What I'd really like to have instead is terminal session management at a higher level, i.e. involving my actual graphical terminal app itself. Attaching to a running session would mean restoring the terminal app's windows and tabs, and the entire scrollback history within (potentially with some lazy loading). tmux could likely be a major part of that, by providing the option of replacing its tty-facing frontend with a binary protocol that the graphical terminal app talks to, while keeping the backend (i.e. the part that provides the tty to anything running inside it) the same as it is today. As it is, the downsides of using tmux all the time are too high.
- callc 2y agoTry “set-option -g mouse on” in your ~/.tmux.conf. I’ve never used the copy/scroll mode, always use scroll wheel on mouse. Yeah, copying can be weird. I full screen a panel to copy multiple lines of text using the terminal emulator’s copy, not tmux’s. Works well enough.
- anyfoo 2y agoThat is a far, far cry from using kinetic scrolling. In fact, using a mouse wheel is a very far experience away from that. I basically cannot use "normal" mouses with scroll wheel anymore for that reason, I couldn't get anything done like that. I think there are/used to be some mice with a ultra-low-fricton "freerunning" scroll wheel. I guess that could be a similar experience, but of course tmux would stand in the way of that as well. And I'm very old school and had been using text-only terminal starting in the 1980s...
- Tsiklon 2y agoPersonally I find tmux’s default split keys to be a bit obtuse, personally I like to use hyphen and pipe for horizontal and vertical splits. Likewise i enable vim keybindings, mouse mode, and if you use a Mac and iTerm selecting text will automatically drop it into your clipboard ready to paste. I tend to make use of the following command - which will output the last 100000 lines of the current pane to a text file local to you; it’s useful for documenting screwups, maintenance work, and of course making notes on what you’ve done for future reference > bind-key P command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S -100000 ; save-buffer %1 ; delete-buffer'
- lemonwaterlime 2y agoI'm a fan of "How to configure tmux from scratch" [1] [1]: https://ianthehenry.com/posts/how-to-configure-tmux/ https://ianthehenry.com/posts/how-to-configure-tmux/
- remram 2y agoI tried to move to tmux, mostly because the Red hat servers at work don't have screen, but I found out I really really prefer screen. The whole server/session/window/pane thing is overly complicated and somehow still less capable than screen's session/pane/window. It's a tiny bit more scriptable, but it's not like a real API either.
- axiolite 2y ago"I tried caviar but found I really prefer hot dogs..."
- remram 2y agoThat's insulting while also lacking any arguments. Good job.
- axiolite 2y agoI was illustrating that the parent comment was "lacking any arguments."
- deleted 2y ago[deleted]
- remram 2y agoAnd you did that by removing the arguments before replacing "screen" with "hot dogs"? Neat.
- axiolite 2y agoYou included no arguments. You only hinted that something is "somehow" more complex and less capable. Analogies usually help people understand things. I don't see why you're offended and obstinate, but you can of course keep it up if you like. Have a nice day.
- 2y ago
- mdaniel 2y agoI'll toss my "works on my machine" hat in the ring with two things that I have found invaluable in combination with iTerm2's tmux integration: - env KUBECONFIG=$HOME/.kube/setup-1 tmux new -s setup1 - teamocil: https://github.com/remi/teamocil#readme https://github.com/remi/teamocil#readme (MIT) The first one I use for circumstances where I want to investigate a lot of different things in a dedicated cluster, without the hassle of having $(kubectl --kubeconfig ...) or the risk of k() { kubectl --kubeconfig ... "$@"; } and losing track of what context I'm in[1]. Because, with iTerm2's integration command-n or command-t opens a new window or tab but with retaining the credential scoping. If I need to change scopes, I can just detach from the tmux session, attach to a different one, confident that I don't have any variables to unset The second I use in "standard" setups where I want to view the same configuration every day (say: web, api, database pods). Having teamocil allows me to either have those same commands laid out in the same pattern as yesterday, or I've also had pretty good luck just generating the yaml files because their syntax is simple enough 1: related to that, if you haven't seen it, iTerm2 offers the ability to set the RGB of a tab via OSC: https://iterm2.com/documentation-escape-codes.html#:~:text=tab%20chrome%20background-,color,-To%20set%20the https://iterm2.com/documentation-escape-codes.html#:~:text=t...
- alexeldeib 2y agoyou seen kubie? `kubie ctx` is great for avoiding the first issue https://github.com/sbstp/kubie https://github.com/sbstp/kubie
- YouWhy 2y agoMy only non-truvial tip about tmux is that the only thing that one needs to do is to look for help: Ctrl+B then '?', and then figure the rest out. When I learnt tmux, I had to access multiple VMs which were de-facto ephemeral, which meant customization was not an option anyway. I kind of learnt to like the defaults as they are.
- venusenvy47 2y agoThank you for this. I'm trying to get better at vi(m) and I'm looking for something similar that I can pull up while editing a document - I struggle to remember some basic keystrokes when I need them. My favorite tmux command from the shell is: "tmux new -A -s me", which I have aliased to "tm". It creates a tmux session named "me", or attaches to a session named that if it already exists.
- g-b-r 2y agoSince no one said it yet, in case you don't already know tmux and you find it complex, zellij is a lot easier to learn
- AnonHP 2y agoI’ve heard of Zellij before but never got a chance to try it. My main use of tmux is with a Synology NAS to run some long running commands where I don’t have to retain the ssh session until completion. Unfortunately, Zellij doesn’t seem to be available as part of the community packages. [1] [1]: https://synocommunity.com/packages https://synocommunity.com/packages
- lynx97 2y agoThere are three tmux customisations that I love and use all day: 1. Set the prefix key to C-Space. Much easier to type then any letter, and (in my case) only collides with Emacs set-mark. Its easy to remember and just type C-Space C-Space in that case. 2. Set IC (insert key) as prefix2. If you have a full-size keyboard, you can now scroll up by pressing insert (on the block of 6) and pageup. Easy to type. 3. Using sessions for ssh hosts. Add ControlPersist and/or AddKeysToAgent to ~/.config/ssh and bind the following to some key. Pressing that key will prompt for a hostname, and create a new session named after that hostname. The default-command will make it such that Prefix c will open a new window which is already logged in on that host. Its not the same as running a remote tmux, as your windows/session will not persist on the remote host, but it avoids nested tmux. I use it all the time during a typical day... command-prompt -p "Secure Shell ([user@]host):" { new-session -A -s "%1" "ssh %1" ; set-option default-command "ssh %1" }
- pjs_ 2y agoFun fact the main WSGI server for prod AWS console has been running out of a detached tmux process since 2018. We are just really careful not to press Ctrl-D
- avinassh 2y agoIs there any introduction post on why one should use tmux OR what one is missing by not using them?
- noman-land 2y agoMy history went like this. Use ssh. Every time the connection blips you lose the shell. Very annoying. Look up how to prevent that. Learn about tmux. Use tmux on remote shells to keep sessions up after you log out. Neat. Apparently tmux has sessions and panes and stuff, I could have multiple projects open in different sessions. I could have different logs and commands running in different panes. Neat. Hey, this is great. I should install tmux on my personal machine. Hey, I love having multiple sessions and panes and stuff, but now when I reboot my computer, all my tmux sessions and panes are gone. Learn about tmux-resurrect and tmux-continuum which will save the sessions periodically and automatically reconstitute them after reboot. Extremely neat. ~10 years later and I still have all the "same" tmux sessions open, and they all have names, saved pane layouts, and histories intact.
- peckemys 2y agoMy story is very similar, still using tmux on servers and my workstation. But I know a lot of people or colleagues that don't use SSH in the first place, which made them miss the first step.
- throwawayqqq11 2y agoSimilar journey for me except the persisting sessions. When i encounter repetitive/manual state i need to circle back to, ill make scripts or custom configs to replicate it (nix is fantastic for that). My workflow allows sessions to close on disconnect or shutdown which brings the benefit of not relying on remote tmux installations. Chances are, you carry around alot of implicit state. How do you backup?
- noman-land 2y agotmux-resurrect/tmux-continuum + atuin for shell history saves pretty much any terminal state I've ever needed, I think, outside of .zshrc and the like.
- zvr 2y agoCan anyone provide some information on the differences between tmux and screen? Are there significant features missing from one or the other? The more "objective" (or unbiased) the better. As an analogy, I know of some features available in neovim not available on vim; they are not important for me, so I continue to use vim. On the other hand, the vim features not available in vi made me switch. I use screen, but whatever I have read till now on comparison seems to point more to personal preferences.
- Malcolmlisk 2y agoThis is a good question. Some user made a good list in superuser https://superuser.com/questions/236158/tmux-vs-screen https://superuser.com/questions/236158/tmux-vs-screen. For me, it's because it's more common to use tmux and you can find from legacy configs to modern ones. So, for me, that I have not studied IT (and now I work as a programmer) it's essential to find basic configurations all over the place to have an anchor. But, as always... Use whichever works for you. Don't think in the "best" or the "most efficient" which is just youtube propaganda. Use whichever works for you and makes you feel like home. If that's 98's microsoft word... then embrace it and be proud to have an opinion.
- sirfz 2y agothere's truecolor support (which is now available in screen 5) and the other thing is clipboard support (not sure what it's called exactly) which basically allows you to directly copy text from screen (or say, neovim) even from remote sessions. Can't think of anything else personally (oh there's undercurl support if you care about that). I find screen to be more stable than tmux but can't say I had any issues with tmux in the past couple of years (but it bothers me that tmux sessions share the initial environment the first session was launched from iirc). Right now it's the clipboard support that makes me use tmux over screen.
- somat 2y ago> but it bothers me that tmux sessions share the initial environment the first session was launched from. It does do this, but I am curious what would be better? I heard this complaint before and It baffles me. let me explain. environments are... sticky, a child process inherits it's parent processes environment. so the tmux server starts and inherits the environment from the shell that started it, then each pane inherits the environment from the tmux server. As far as I can tell you want each pane to inherit the environment from somewhere else but can't figure out why or how that would happen. My best guess is that you want tmux-attach to stash the environment it was ran in so that tmux could then use that when making new panes. my second guess is that you want tmux to use the current pane as the parent process for a new pane. both of which sounds like it would be even harder to control the tmux environment.
- azaras 2y agoI use byobu, a Tmux wrapper, as my primary terminal. I changed the Keybindings for splitting and moving around terminals to be as in Emacs, and I am very happy.
- lproven 2y agoThere are not so many console-mode windowing terminal multiplexors. I am aware of tmux, dvtm, zellij, and GNU screen. That's it: just 4. Has anyone written a comparison of them? I would be genuinely interested. I personally favour ease of use over features.
- aaplok 2y agoThere is also cy [0] which I came across the other day and am yet to try. [0] https://github.com/cfoust/cy https://github.com/cfoust/cy
- mdaniel 2y agoI dunno why their repo would choose to offload people to a separate site just to read https://cfoust.github.io/cy/why-not-tmux.html https://cfoust.github.io/cy/why-not-tmux.html IMHO <https://cfoust.github.io/cy/replay-mode.html#:~:text=make%20sure%20the%20directory%20is%20only%20readable%20by%20you https://cfoust.github.io/cy/replay-mode.html#:~:text=make%20...> is trying to drive down the risk of an Evil Operator reading my files as if it's the 90s at school but my modern risk is that some npm dependency exfiltrates the .borg files, which are readable by me, to North Korea. I was hoping to find an encryption option but did not > Configuration: cy uses a real programming language, Janet, for configuration. Man, why everybody gotta reinvent scheme? https://janet-lang.org/#Code-Example https://janet-lang.org/#Code-Example I do like any app with a command palette though https://cfoust.github.io/cy/quick-start/command-palette.html https://cfoust.github.io/cy/quick-start/command-palette.html
- tiu 2y agoWould also like to mention (tab-rs)[0] which has a much more unconventional take on multiplexing. It is sad that it has not been maintained in a while (written in rust) as I much prefer the low cognitive load approach it presents (just fuzzy find) as well as the workspace feature. Would be interested in knowing if there is something similar and maintained. P.S. Does anyone here know how to make GNU Screen start up by default on a terminal launch? [0]: https://github.com/austinjones/tab-rs https://github.com/austinjones/tab-rs
- alyandon 2y agoI've slowly been converting from screen to tmux. However, muscle memory is really hard to overcome so I've come up with this: https://gist.github.com/alyandon/b19e2634fac6505bb5bd0e0c99d856b0 https://gist.github.com/alyandon/b19e2634fac6505bb5bd0e0c99d... Yes - I'm a terrible person.