18 ms·
Using tmux properly
- dllthomas 10y agoA big thing I've done is use my multiplexer segregate contexts. When I spin up screen (tmux would work the same, just never switched) I set an environment variable noting the particular context I'm working in, and I adjust my PATH, HISTFILE, and more based on this variable.
- greyskull 10y agoI create new sessions and name them appropriately. My one wish is to be able to do "PREFIX ls" and then just hit enter on the session to switch to. I may be missing something, but I always have to do "PREFIX a -t [session name]".
- jamestomasino 10y agoYou don't use PREFIX s ? Just select by name and hit enter.
- elpocko 10y agoThere is one thing I want from my terminal multiplexer: working scroll functionality with Shift+PgUp/PgDn, even in split screens, just like in a plain console, without messing everything up. Is that possible?
- hbogert 10y agoByobu does this in my case with default settings, just with alt+pg-up/down
- elpocko 10y agoHey, I just tried that and it's pretty close to what I want. Thank you. edit: close, but no cigar. It enters "scrollback mode", which you have to exit before you can type again. It's just like screen's copy mode with different key bindings.
- CaptSpify 10y agoKind of. I use bind-key -t vi-copy "J" page-down bind-key -t vi-copy "K" page-up Then I can just enter tmux's vi mode, and scroll up and down with shift-J/K. I don't know of a way to bind shift-PgUp/PgDn though, which sounds like what you are looking for.
- rhinoceraptor 10y agoYou do one better - tmux's mouse mode allows you to scroll with your mouse wheel. Just add 'set -g mouse on' to your ~/.tmux.conf. You can configure the history size limit by setting 'set-option -g history-limit <lines>'. When you scroll the mouse wheel, tmux will enter copy mode and scroll.
- elpocko 10y agoThat is absolutely not 'better', sorry. Taking your hands off the keyboard to do something basic is never better.
- coldtea 10y agoI disagree. I want to select with the mouse and touch type with the keyboard. And "doing it faster" is never a concern. As a programmer I write about 5% of what I could type in the same time as a secretary or accountant. Most of the work is thinking. Plus, the occasional chance to get your hands off of the rigid (and carpal tunnel inducing) pose on the keyboard and move them to the mouse, or vice versa, is welcome. I don't want to replicate things the mouse does better with keyboard shortcuts, or suffer "modal" input-modes in my programs.
- elpocko 10y agok I still prefer not using the mouse for a basic operation like scrolling, thank you.
- pmoriarty 10y agoI myself prefer to scroll with the keyboard in tmux, but for moving the cursor and selecting text, tmux has a very, very long way to go before being optimally efficient and useful in this regard. The kings of keyboard-based cursor movement and text selection are vim and emacs, both of which have a very rich and powerful toolbox of techniques and plugins that help the user do that quickly and efficiently. For example, emacs has plugins like ace-jump-mode which lets you jump the cursor to any precise position on the screen by typing just one or two keystrokes. vim has similar plugins, like easy-motion and precisejump. vim and emacs also have quick ways to select words, sentences, paragraphs, functions, lines, logical and visual blocks, the entire document, etc. This includes having full access to rich and powerful regex text matching, which can be used for selection. In contrast to emacs and vim, when I try to move my cursor and select text in tmux, I feel crippled. So sometimes I do succumb to the temptation of using the mouse to select text in tmux, despite being quite comfortable and satisfied in using the keyboard exclusively in vim and emacs.
- pmoriarty 10y agoDoes it absolutely have to be a combination of Shift and PgUp/PgDn? With tmux, you can type your prefix key followed by PgUp and it will scroll up, even in split screens. For example, if your prefix key is Control-b, you would type Control-b PgUp and get the effect you want.
- elpocko 10y agoI'd like to use the same key combination, no matter if I'm in screen/tmux or not.
- williamdclt 10y agothe bind -n command allow to bind keys without the prefix. For example, I use the following to resize panes without using the prefix : bind -n M-h resize-pane -L 5 bind -n M-j resize-pane -D 5 bind -n M-k resize-pane -U 5 bind -n M-l resize-pane -R 5
- destructionator 10y agoI wrote my own terminal emulator and screen-like program to get there... I made mine send the code for shift+pageup/down when the application is in alternative screen mode, so I could forward the keypress all the way down to the server...
- CaptSpify 10y agoI basically use tmux as my window manager. I only typically open two programs: a browser, and a terminal. Both are always in full-screen mode. It makes things nice and simple. No matter if I'm working on a laptop or a desktop, all my terminal windows end up in the same place and have the same settings. It's great!
- a3n 10y agoYou and I have almost exactly the same setup. I also usually only have a browser and terminal/tmux running. If I'm reading the general web then I max the browser (which also maxes the terminal, since I'm running awesome-wm tiling window manager). If I'm writing code or anything else terminal-focused, then they're unmaxed, side by side.
- hyperhopper 10y agoIf you are already going that far, why not just switch to a tiling window manager?
- colordrops 10y agoThey are not mutually exclusive. I use xmonad, tmux, and vim together. Tmux adds some niceties on top of xmonad like shared keybinds with vim making moving across vim panes and terminals seamless. Also, I can jump on my macbook and login to my desktop using mosh and re-attach to the tmux session and continue working where I left off.
- CaptSpify 10y agoI do, but... If I'm on my laptop, then switch to my desktop, a twm doesn't save my sessions. Tmux on a remote machine does.
- XtalJ 10y agoMe too, and it's great and even works on Windows with Babun :-) If I use tmux as window manager, I don't have the problem with installing fluxbox etc. on Windows :-)
- baby 10y ago
- gbrown_ 10y agoSo "properly" means customizing to user preference?
- a3n 10y agoIf that means in contrast to the default configuration, then probably yes. tmux default is not bad, but each person would probably do better with a few common adjustments, and maybe a bit more for their local needs and focus.
- rhinoceraptor 10y agoI have my tmux/vim set up so that C-(h,j,k,l) navigates vim splits and tmux panes seamlessly. The only downside was that I had to rebind C-l to C-o to clear my shell. But it makes it a lot more productive when using multiple shell panes along with my vim session in one terminal window.
- autoreleasepool 10y agoWhat's the advantage of tmux over something like terminator with pane splitting?
- paulddraper 10y agoI can SSH to a machine and connect to a tmux session. Tmux's competition is not terminator, but screen.
- dozzie 10y agoscreen + dvtm, as I hear tmux has sensible way to manage split windows, while screen's way is atrocious.
- paulddraper 10y agoHm, true.
- bigtunacan 10y agoTerminator is an alternative to something like iTerm. Tmux is server based so the sessions persist after disconnecting from ssh for example and allow multiple users to connect to the same terminal
- bostand 10y agoOut of curiosity, would you still use terminator/iterm if you used tmux in every shell? I understand term* provides some additional functions, but would you still consider it worthwhile?
- rocqua 10y agoI personally would, because learning less tools is great. I've had some problem applying this principle when using tmux locally on a system with i3. You kinda need to be consistent in which of the 2 you use to create new shell windows.
- arca_vorago 10y agoecho "alias tmux='screen'" >> ~/.bashrc && source ~/.bashrc But in all seriousness, I do sometimes find myself using tmux, but I try hard not to fragment myself over tools too much, especially with screen finally having vert split, and tmux being BSD, this is one of those cases where I think screen while it has some quirks and may have a bit of a learning curve is worth the effort. edit: Since I didn't provide much value and my comment was a bit snarky, here is a truly useful tmux shortcuts and cheatsheet link: https://gist.github.com/mischapeters/462c6f383bfd9b2f9eea3fb7e6e5b79d https://gist.github.com/mischapeters/462c6f383bfd9b2f9eea3fb...
- babygetoboy 10y agoThe big problem I always have with tmux is that is messes up all of the colors in my Vim.
- colordrops 10y agoThis is easily fixed by setting the appropriate terminal color settings in your bashrc. A quick google search will provide the answer.
- williamdclt 10y agoTry aliasing tmux to 'TERM=screen-256color tmux -2', I made my vim colors work. Just in case, excerpt from my vimrc : set background=dark set t_Co=16 let g:solarized_termcolors=16 colorscheme solarized
- barrkel 10y agoWhatever TERM is set for you outside tmux needs to have a full ncurses terminfo with all the extended ncurses-specific codes. Assuming that screen and screen-256color on your system is similarly fully-featured with respect to ncurses, then you'll be in a good position. If you're lucky, TERM=screen-256color inside tmux and you're good to go. Without that, there are a variety of hacks at different levels of the processing stack you can use to fix things. You could set TERM to screen.<your-terminal> if your system has the right settings for screen.<your-terminal>; or you could try setting it to <your-terminal> if <your-terminal> is sufficiently xterm-like.
- JeremyNT 10y agoYou need to set your tmux.conf to use the correct term type. For modern distributions it should be set -g default-terminal "tmux-256color" You also need to make sure tmux understands that your terminal supports true color mode. Set the following if e.g. using gnome terminal (which calls itself xterm-256color in $TERM) set-option -ga terminal-overrides ",256col:Tc" You'll need to reset $TERM to something more standard if you plan to SSH to older systems, though. I have a shell function that wraps SSH and sets the term type to screen for when I log into old systems.
- pkaye 10y agoDoes mouse copy and paste work correctly with tmux? I find that it selects spans across multiple panes. Is there a way to fix this or Windows or Linux?
- chris_st 10y agoI use the "PREFIX z" command to "maximize" the current pane, that is, it hides all the other panes and makes the current one the only visible pane, filling the whole terminal. Then I copy, and "PREFIX z" again to go back.
- bostand 10y agoClever! You just solved my main issue with tmux!
- williamdclt 10y agoPanes in tmux are only logical, not physical, you can't avoid it. You can either maximize your pane (which is the best feature of tmux for me :)) or use the copy-mode (so, not the mouse)
- rocqua 10y agoCopy mode works with the mouse simply by using mouse-enable. It'll still copy to the tmux buffer, not any system clipboard.
- steffan 10y agoAnother option is to write the tmux buffer to pbcopy on a Mac or xclip or something similar in Linux
- GrinningFool 10y agoIf you don't enable mouse support (set -g mouse on) then the terminal process handles mouse and does what you're describing* . When you enable mouse support tmux handles selections within panes and doesn't span. * the other possibility also is that your term emulator is configured to grab mouse control without passing it through.
- rnhmjoj 10y agoYesterday I was helping a friend setting a box with no graphical session: I fired up tmux in the linux virtual terminal and then proceeded to realize without my tmux.conf I couldn't do a thing because I have always been using entirely different keybindings from the default. This is the problem with too much customization. Learning to use the default configuration may be difficult but it's probably worth the effort, for vim it has definitely been in my experience.
- williamdclt 10y agoI agree a lot with this, for two reasons: the one you gave, and the fact that customizing too much your tools makes them unusable by anyone else. I don't know about you, but at my work we're often working on someone else computer (debugging, pair programming...). Always keep the default config available!
- rocqua 10y agoThe thing about tmux bindings is that, as far as I know, very few people like the defaults. I've taken the approach of 'learn the defaults' for vim, but on tmux that simply won't stand because the defaults have so much room for improvement. Pretty much everything I've read on tmux suggests the - and | bindings for window splits, same goes for hjkl bindings for movement. Adding these bindings would go a long way towards standardizing tmux.
- mmagin 10y agoYeah, I learned screen defaults, so ^A is far too strong of a habit to change.
- williamdclt 10y agoIt still sounds like a very shallow (naive?) use of tmux to me, I'm in no way a real power user of tmux and I use a lot more feature than that. You could talk about binds without prefix, sessions, customized status bar, pane swapping, bind keys to script launching, plugins, pane highlighting... And the best feature of all for me: maximized pane toggle. I use that ALL the time. I never could find all features I needed from an emulator (plus, I want a drop-down terminal), Tmux have them all and more and I'm not dependent of a specific emulator.
- pinnbert 10y agoYou sound very smart. I think you are a power user, and a smart person.
- rocqua 10y agoI agree, I'm less of a power user than you and still had the same feeling.
- hyperhopper 10y agoDo you have any better recommendations on what to read in this case? If you do, I would love to read them! If not, you could do a great thing and use your knowledge to help the rest of us out.
- oconnor663 10y agoMy favorite tip: add bindings with the control key. So if you use "Ctrl-b n" to go to the next pane, add a binding for "Ctrl-b Ctrl-n". It's easier to keep the Ctrl key pressed than to lift it.
- rocqua 10y agoHere I've been letting go and re-pressing the Ctrl key. Thanks for the tip :D
- 3JPLW 10y agoI use tmux constantly but I barely know three tmux commands. Get all the benefit with none of the cognitive overhead with `tmux -CC` in a supported terminal (like iTerm). It allows the GUI program to take charge of the windowing and paneling in its own native way. It's lovely.
- KaiserPro 10y agoSo this may mark me out as different, but apart from persistent remote connections, I've never really felt the need for screen/tmux. I've been trying to figure out what the fuss is about, and I still really don't understand (apart from persistence and screen sharing.) When I want multiple terminals, I just fire up another terminal window and hey presto, jobs a goodun. I have a fairly high res screen and small fonts, so I can fit many terminals on one screen. If I run out, I hop over to a new virtual screen. Perhaps this is a by product of working in linux/unix so long? I can imagine that if I was forced to use putty, where connection setup is costly and screen space scarce, I'd want tmux to make things quicker. What am I missing?
- vr46 10y agoI have a heavily-tweaked Tmux that uses a lot of custom bindings but also incorporates Powerline to make the status bar helpful and homely. I spend so much time in the terminal and only Tmux can really personalize it. It looks good, and it feels like a good place to work. It's no big deal, having the time, date, current song, weather etc all there to see, but it is a pleasure to have. A terminal that be made to feel like /home? Oh yes!
- mod 10y agoYou probably meant comely. At least, I think powerline is beautiful!
- colordrops 10y agoVim + tmux with custom bindings makes moving between vim and a terminal seamless. The same keystrokes for moving between panes in vim can be used to move to tmux panes. Also, as a vim user I loathe to reach for the mouse, so having quick and easy keybindings for launching and arranging tmux panes is great and preferred to the imperfect and slow arrangement using a mouse. Lastly, I can have tabs and window panes that are named and in consistent locations and persisted across sessions, so I can immediately jump around a dozen projects without much cognitive load. Try having 15 terminals open and remembering which is which and you'll find there is a high context switch cost, so you constantly have to close and open terminals. This isn't the case with tmux.
- mcbuilder 10y agoI used to be an extensive user of tmux, basically I'd have a sprawling set of sessions, all backed up with the continuum and resurrection plugins. It allowed me to armory seemlessly work remote on my main dev box or through SSH. Of course the biggest pain was consolidating the X11 clipboard and tmux's internal one. Since I switched to Emacs though I've gradually peeled away the tmux layer. I still run without X11 version of Emacs so I can remote in, but Emacs itself does an equal or better job at pane management and session persistence, especially using daemon mode. ANSI term inside Emacs, something that has really improved in the past few years, has cinched the deal for me. Tmux had become bloat at this point for me.
- zls 10y agoFunny, I'm going the other way. I used ansi-term (well, multiterm) with a daemon emacs for years, but in the end, a few things ended up being too much: * some programs didn't render properly in ansi-term * opening really large log files was dubious * hanging a buffer by, say, accidentally running a long macro would wipe out all my terminal sessions and open files * lingering suspicion that modal editing makes a lot of sense These days I'm picking up tmux and kakoune and loving it. I guess everyone likes to change it up now and then. :)
- gcb0 10y ago> uses gnu screen on all servers. > uses tmux on dev box > advocates tmux but do not mention a single feature not on gnu screen. why on earth would someone be that impractical?! just get a single gnu screenrc file that does all that and call it a day on every single environment you work on.
- skratlo 10y agoMost people use tmux locally, because their terminal emulator doesn't do what they need it to do, or the window manager doesn't do it. Using tmux locally merely supplements the window manager. I stopped using tmux locally after switching to i3 (and I believe any other tiling / proper wm would do). Now my only use case for tmux is on the server where I'm running weechat. When sysadmining, it's eaiser for me launch few terminals in my window manager and ssh to the same server, then running tmux remotely. It's simply a question of ergonomics, how many sets of keyboard shortcuts do you need to remember to handle a multiplex... eh, window manager running inside a window manager?
- Morantron 10y agoYou are not using tmux properly if you don't have tmux-fingers ( https://github.com/morantron/tmux-fingers https://github.com/morantron/tmux-fingers ) installed B) </shameless-plug>
- GrinningFool 10y agoThanks for the shameless plug, I was getting ready to write something like this myself.
- Morantron 10y agoAwesome! I'll publish a roadmap on GitHub on pending things that can be implemented, so maybe you can contribute :B I wonder how I could improve the visibility of the plugin, since it's a little bit difficult to find/explain. What kind of keywords where you using? Thanks!
- vlunkr 10y agoMy biggest question is why are they still using screen when sshing?
- jph 10y agoTmux dot files with annotations-- may be helpful for people here. https://news.ycombinator.com/item?id=13570010 https://news.ycombinator.com/item?id=13570010 Direct link to the tmux dot files repo on GitHub: https://github.com/SixArm/sixarm_tmux_dotfiles https://github.com/SixArm/sixarm_tmux_dotfiles
- Zaheer 10y agoAfter experimenting with mosh, tmux, screen, etc I've finally found my ideal ssh setup. At work I do development on my Mac and run builds on a cloud desktop. My Setup: 1. Unison for file-sync (https://www.cis.upenn.edu/~bcpierce/unison/ https://www.cis.upenn.edu/~bcpierce/unison/) 2. iTerm on Mac 3. AutoSSH for more durable SSH sessions (ex. close laptop & reopen at home) - http://www.harding.motd.ca/autossh/ http://www.harding.motd.ca/autossh/ 4. tmux -CC command to attach to tmux session with iTerm Tmux integration. This is the killer feature, it treats a tmux session as a native iTerm window. This means all of the 'learning' you previously had to do with Tmux is nearly non-existent (copy / paste, switching tabs, etc). My biggest annoyance with TMux was the copy / paste special handling. Huge productivity loss. All-together it looks something like this: Open iTerm. autossh -t myRemoteHost "tmux -CC -A" Instantly have a _fairly_ durable terminal session on my remote desktop.
- schemathings 10y agoIronically, you got me interested in trying out Unison, but the download links are broken :(
- trengrj 10y agoI'd argue that using a terminal multiplexer like tmux or screen on a production server (as this article implied) often means you are doing things wrong. It is better to set up a service (systemd or other) and configure it to start correctly rather than relying on a tmux session to manage long running processes. By going this route you get logging, auto restarting, starting on boot, monitoring etc for free.
- njharman 10y agoThere's difference to daemons and Kong running process. Long process might be tar up all these files, or copy all these. Things that takes 10 s of minutes to hours. Things you don't want to bomb out just cause network died. Things that are one off and variable enough it doesn't make sense to write a server for them. And of course any you don't want to be interiors part way. Like upgrade or deployment
- enobrev 10y agoI just now went through this, which makes this post perfectly apt for my morning. 4-day running process. SSH disconnects on day 3.5. Reconnected; Started tmux; Started the process; 4 days to go... I generally know better. Some lessons need to be relearned.
- oblio 10y agoMaybe I'm missing something, but why not nohup?
- ausjke 10y agoI used the default all the time and it worked fine for me. by the way what is PREFIX meaning? ctrl-b?
- teach 10y agoYes, CTRL-b is the default prefix. The default prefix in screen is CTRL-a, so a LOT of tmux users remap the prefix to match. Also, CTRL-a is much easier to press, since B is a long way away. tmux only uses CTRL-b so it won't conflict with screen's shortcut in case you find yourself in a screen session inside a tmux session.
- base698 10y agoI never understood that since ctrl+a jumps to beginning of line. Ctrl-o is what I use, but probably in the minority.
- git-pull 10y agoI am author of The Tao of tmux, a book I just finished a few weeks ago. You can read it publicly at https://leanpub.com/the-tao-of-tmux/read https://leanpub.com/the-tao-of-tmux/read. One of the things I stress in my book is that there is no "correct" way to use tmux. The approach I take to teaching tmux is separating it into its objects: The server, sessions, windows and panes. Then where they stand in relation to one another, how configurations work, and then leave some examples of usage available to the user so they can pick out work flows they may like. I'm sort of against the approach of just throwing a config / toolkit at someone a la oh-my-zsh and spf13-vim (even though I think they're ok after you've learned to customize yourself). The gift of allowing someone to wrap their brain around something will let the rest come to them.
- whsheet 10y agoOut of curiosity: Why do you write a book and let it be read publicly if you sell it as well? Why should somebody buy a book when all the content is available for free? Is this done to create some awareness for the book and thus to improve SEO (e.g. generating good backlinks, etc.). And later you restrict the public available content once SEO backlink power is generated? Our of curiosity 2: Are you happy with the sales, how many books could you sell already (if you don't mind to tell us)? Would you write again a book about a console-based app? Out of curiosity 3: Are you happy with Leanpub? Thanks!
- adventist 10y agoI love Tmux, I just can't seem to wrap my head on how to COPY and PASTE something lol. Anyone have any step, by step tutorial for how to copy and paste like VIM? I would like to be able to see what is being copied just like in VIM's visual mode. Like If I can copy some code in VIM and then go to paste in another REPL pane in TMUX then that would be my ideal goal!
- drieddust 10y agoCopy mode is your friend and article does have a section o that so i think you should be using those settings.
- merlincorey 10y agoBy default it's: C-b [ Start copy mode C stands for CTRL, by the way. This allows you to scroll up in the window and place the cursor where you want to start copying, then: C-SPACE Set mark This sets the mark for copying, then you can move around and what will be copied will be hilighted with a background color. M-w Copy selection This copies the selection. Incidentally, M stands for "meta" and is nearly always usable with ESC, but often ALT will work in many terminals (some need a setting to enable it). To paste, go to the buffer you want to paste into and then: C-b ] Paste!
- drieddust 10y agobind | split-window -h bind - split-window -v Binding vertical bar to horizontal and visa versa seems weird. Shouldn't it be otherway around.
- zump 10y agocan someone eli5 how to copy to the clipboard using this thing without spending 100 calories in my upper torso
- arc_of_descent 10y agoWow! PREFIX t displays the time!
- philippeback 10y agoIn my config, some better mouse support, 256color, history saving, config reload, and emoji-weather (temp + icon) in the status bar. https://github.com/philippeback/dotfiles/blob/master/.tmux.conf https://github.com/philippeback/dotfiles/blob/master/.tmux.c... Emoji-weather is to be taken from https://github.com/justincampbell/emoji-weather https://github.com/justincampbell/emoji-weather Got this from Justin Campbell on LiveCodingTV. He has pretty good dotfiles https://github.com/justincampbell/.dotfiles https://github.com/justincampbell/.dotfiles His Vim one pretty much takes the cake: https://github.com/justincampbell/.dotfiles/blob/master/.vimrc https://github.com/justincampbell/.dotfiles/blob/master/.vim... and this tmux-pomodoro is sweet. https://github.com/justincampbell/tmux-pomodoro https://github.com/justincampbell/tmux-pomodoro definitely more stuff than in mine https://github.com/philippeback/dotfiles/blob/master/.vimrc https://github.com/philippeback/dotfiles/blob/master/.vimrc
- owenww 10y agoGreat read - prompted me to actually learn tmux, has been worth it! Also thanks for the link to the book, I ended up buying https://pragprog.com/book/bhtmux2/tmux-2 https://pragprog.com/book/bhtmux2/tmux-2
- vegabook 10y agoHonestly, tmux is not hard to use. It has some contorted key bindings, sure, but its benefits are so immediately huge that the motivation to learn its quirks is huge too. And, unlike say, vim, it only has 3 things you really need to know: panes, windows, detach. Most people who use tmux, even casually, will inevitably be using it 'properly', within a week, and fluidly within a month. So this blog post is quite redundant.
- blfr 10y agoI use ... Screen on production servers. ... Screen has the lightest footprint dtach, which is what I use on production servers even though it usually doesn't come standard, probably has the lightest footprint if you just want to return to some screen later. It doesn't maintain history, however, the screen is redrawn, if possible, on reattach. Otherwise, yes. Both tmux and the book are great (if you don't mind getting drawn into wasting time on customizing the status bar and such).