Not sure whether or not this is a little-known feature. iTerm2 has _fantastic_ integration with tmux (software used for persisting a terminal session across multiple logins).
Tmux can be a pretty complex piece of software, but iTerm can basically wrap it all up into a nice package. You don't need to know anything at all about tmux to use iTerm's tmux integration.
If you're SSHed into a server that has tmux installed, try running `tmux -CC` on the server. It'll pop up a new window that looks and feels just like it's running natively (complete with tab support), except it's all tunneled over SSH.
And if you disconnect, you can just reconnect later and your windows will all come back in the same state as when you left them.
I use this one-liner to SSH into a server and reconnect (or start) a tmux session:
iTerm2's tmux integration makes SSH access to remote machines feel almost as native as using your machine locally. It's really a killer feature, and it made iTerm2 worth a donation for me.
I haven’t really figured out Tmux, and I’m a little ashamed to admit it. I usually reach for screen when needed, and disconnect/reconnect/kill are the only commands of screen I know.
I’ll give the tmux -CC a go when I’m back at my machine, but what else does the integration do? I’m a heavy pane user - does the default split pane in tmux mode use tmux splitting for example?
I mean, it uses it, but it no longer feels like tmux, and you don’t have nice tmux features like zoom-pane, right? iTerm2 is absolutely fantastic and I would miss it if I moved to a linux laptop, but I still haven’t seen the attraction of the tmux integration yet!
Very true that you don't really have access to zoom-pane type features. But they're also not really applicable. The integration is more about giving you a native "tabs and GUI windows" kind of feel, so that you can have multiple terminals open without needing to mess around with panes, tmux windows, etc. And of course, that gets provided in a persistent way (so that you can disconnect and reconnect at will) just like a normal tmux experience.
I use iTerm2 with tmux every day (but I don’t ssh into machines often nowadays) and I feel oppositely — I don’t get the attraction of the tmux integration. But maybe I still haven’t understood it, so please feel free to tell me what I’m missing. For me, the purpose of using tmux on my laptop is session, window, and pane management. (Perhaps my favorite tmux feature is zoom-pane.) So I find that the iTerm2 tmux integration takes away everything I liked about tmux, and makes using tmux feel like using iTerm2 without tmux!
I love tmux just for letting me run long running sessions on remote machines. I don't like tmux's window management, I want to use my terminal, scroll back with mouse, that kind of thing. Tmux integration is therefore for those of us who love their GUI terminal :)
You can always `set -g mouse on` in your `tmux.conf`. But that has the nasty downside of stopping you from being able to right-click and copy text to your OS clipboard. It does let you pane select and scroll with a mouse though.
For someone that doesn't like or understand working with tmux windows and panes, it brings the benefit of running sessions in remote servers, being able to disconnect while still using their GUI.
- visor mode: I always have a fullscreen terminal one keypress away
- genuine fullscreen mode, not the crazy Apple thing where you try to fullscreen an app and it creates another "workspace" or "desktop" or something and you can no longer switch efficiently between fullscreened and non-fullscreened apps without seeing some sliding animation.
- Powerful keybinding support for simple and sophisticated cases. E.g. I use the "send raw bytes" feature so that I can switch panes in tmux with a single keypress, without needing to explicitly send the tmux prefix key. And all that sort of configuration can be version controlled in JSON (you certainly wouldn't want to get something like that working and then commit it to an app config dialog for safe keeping)
- settings for everything
- "dynamic profiles" You can version control your config as JSON
- configurable click behavior ("smart selection"). See other subthreads in this discussion.
- color themes and convenient color switching
Probably others.
With respect, I believe you're making a mistake. Check out some of the things I mentioned. (What does Terminal.app give you over iTerm2?)
> visor mode: I always have a fullscreen terminal one keypress away
Last time I tried this (which, admittedly was sometime back), I found that this was ugly as heck if one has multiple screens and them set to be above one another-ish (e.g. on laptop with desktop screen(s) offset above) - it turns out that iTerm was just sliding the window in from 'offscreen', which if one has windows as I do, means it appears on an upper window.
It's slick if your screens are in 'acceptable' positions for iTerm - otherwise it's an ugly mess. Which is a shame, because I quite like / want this feature.
@jimsmart Yes I can believe that might take a bit of tweaking to get right. The author (George Nachman) is very responsive though, so I'm sure he'd appreciate the report. It might be reported/fixed/discussed already?
Ease. I've been down many a custom-config-rabbit-hole but these days I find greater pleasure in paths of least resistance. I'll admit, however, that I love my hyper key and BetterTouchTool gestures.
I don't use tmux locally, but I find iTerm2+Tmux invaluable when it comes to managing my servers. for each of them I have an ssh command that automatically opens all the windows and panes for that particular server. It even persists colors I give various panes so I don't accidentally work in the wrong one.
I'm not too sure if it has this built-in by default, but I've found kitty terminal to be the nearest thing to iterm for Linux. Lots of customizability and it has fairly good docs which is always a plus.
after years of seeing tmux fly by, and still not understanding its purpose I thought okay, lets give this one liner a try and see if I really don't need to know about tmux as you wrote. :)
why do I get:
Can't open user config file <user@host-redacted>: No such file or directory
I grabbed it out of a bigger script that also generates and uses an SSH config file. Looks like I pulled out the actual file from args, but not the -F.
More of a normal tmux question, but is there a way to input the window number, or is there a fast way to open up ssh to 4 servers numbered sequentially?
When I need to do cluster ssh with tmux I do this or a variant of it:
function cluster_ssh() {
# Start a pane for every server
for server in $*; do
tmux split-window ssh $server
done;
# Same input to all panes
tmux setw synchronize-panes on;
# Init pane to background, tile layout
tmux break-pane -s 0 -d
tmux select-layout tiled
}
bash# cluster_ssh server-{01..10}.example.com
EDIT: made it a bit more complete, but you only need split and sync panes IMHO.
it pulls out windows into terminal tabs (in the UI), and handles panes like they were native iTerm panes (so same keybindings etc). Makes for a native-feeling experience while still getting the benefits of tmux.
iTerm2 will use tmux's scripting mode to give you a "tmux without tmux" kind of experience. Scrollback will work normally, and so will opening new terminal tabs and new windows.
It doesn't give you anything if you're already comfortable with tmux. But if you want your experience to "feel" more native, it's an awesome tool.
I was one of those vim users that was stuck on MacVim for years because my brain was too wired to hitting "cmd-s" for save and other dedicated app niceties. I mean, sure I can :w or bind it to another key, but there are a couple shared OS-level shortcuts like this I just like to retain. No worry, iTerm2 can capture ANYTHING, and rebind it as needed. This means I have a few remaps like "cmd-s" in iterm2 to map to obscure key combinations, which I then have vim interpret and pass along to whatever I want to bind over there. I had no idea the feature existed for years. And sure, I know you're all laughing, why would I even do such a thing... but vim is vim, and we all have our own weird version of it.
iTerm2 is amazing. I've been using it for years daily and it is 100% one of the best, most reliable pieces of software in my toolkit, right next to Alfred.
Show you love for George and contribute to his Patreon[0]. We always love to complain about how to make money with open source on HN. I'd love to see him making a lot more than he does, if for no other reason than we can get more people working full time on the project and provide some redundancy for a critical tool we all love. I wish I could pay for it, but I guess Patreon works.
This way, when on a Mac I can use cmd in place of ctrl for various commands I use all the time that are less convenient with ctrl.
In my .gvimrc, I added the following to make sure that cmd-p and cmd-l don't get incercepted:
"Disable the print key for MacVim"
if has("gui_macvim")
macmenu &File.Print key=<nop>
macmenu &Tools.List\ Errors key=<nop>
"macmenu &MacVim.Hide\ MacVim key=<nop>
set macligatures
endif
If there's any possible way to accomplish the same with iTerm, I'd give it another try!
This is essentially F6, which I then bind in vim to
nnoremap <F6> :w<CR>
imap <F6> <Esc>:w<CR>
I do this with a lot of ⌘ or otherwise unbindable settings (again, this only effects iterm2). This is how you can get iterm2 to pick up any keybinding and send it to vim as something else.
I think this is a bit different than what I wrote above. I just want to send the command key as itself.
It looks like you're changing your .vimrc itself.
How would I get iTerm to just send cmd+p as cmd+p? I tried making a keymapping in that menu with "Key Combination": "cmd+p", "Action": "Do Not Remap Modifiers". Rather than sending it to VIM, it still brings up a print screen dialogue.
Similarly, I can't get cmd+[, cmd+], cmd+h (or j, k, l, etc) to send through to VIM.
With both VS Code and MacVim, that stuff is easily configurable. My failure (thus far) to figure out how to do the same with iTerm is why I don't really use it.
I don't have karabiner-elements, but doesn't it basically just remap keys across your whole system (much like my mechanical keyboard can)?
I don't want change my cmd-keys into control keys system wide. I just want to be able to map my cmd-keys in vim (which to be honest is the lion's share of what I use any terminal for).
Karabiner-elements is good for mapping single keys to other keys. It doesn’t handle key combinations. (There is something called complex modifiers, but I can’t figure out how to edit them.)
BetterTouchTool is good for mapping key sequences. Further, it can do it selectively based on what application is active.
The complex modifiers are just a json file that’s fairly easy to edit. I have a file that has caps+hjkl to arrow keys. Caps by itself is Esc. caps with anything else is Cmd-shift-option-control+anything else. And finally right shift plus caps toggles caps lock.
Wow. That’s good know. I will poke around. Thank you.
I like KE and have contributed to the dev several times. In typical modest Japanese fashion, contributions are limited to $10 max. Mapping ‘Enter’ to ‘Caps’ and ‘right shift‘ to ‘right command‘ staved off RSI in my right pinky, so I’m happy to send him/her some cash.
Other Vim user here. I was stuck on MacVim as well, but for mouse support. That's until I discovered that `set mouse=a` in Vim and using iTerm instead of the default Terminal essentially gave me the same thing.
Then I went into the tmux rabbit hole, but I never really liked iTerm's integration so I don't use it.
I’m surprised to see that the iTerm2 dedicated hotkey window hasn’t been mentioned. It’s essentially a system-wide terminal window that you can open with a hotkey, similar to the old Visor app, and you can configure it as a floating window that appears over other apps' full screen windows. https://www.iterm2.com/documentation-hotkey.html
Yeah - I use this workflow and love it. cmd + esp (with caps lock remapped to escape) to toggle a full screen terminal from any application. Means don't have to cmd + tab and hunt for it, it's always one shortcut away.
* imgcat: you can view images without leaving your terminal. Somehow this works even across SSH connections…
* Python scripting API: basically AppleScript for iTerm except it lets you touch pretty much everything and it's not soul-crushing to write. I have mine switch between themes based on the system appearance (which changes based on the time of day).
The source code[1] is quite simple to read (as long as you know Bash) but basically imgcat prints a special OSC[2] sequence (some bytes that tell the terminal to do something special) to stdout followed by the image data which iTerm then handles specially because of the OSC sequence, as far as SSH knows they're just some bytes that it needs to send (no different than running normal cat on a text file). You can kind of think of this as the opposite of what bracketed paste[3] does, in bracketed paste the terminal tells the program to treat some data specially but with imgcat the program tells the terminal to treat some data specially.
On imgcat, those extensions to the xterm protocol[0] seem really nice. I've long thought that there needs to be a simple escape sequence for a horizontal divider that doesn't break upon resizing, they should do that next!
Also check out tiv[1] which is an alternative that works with any unicode terminal.
These iterm image extensions are almost there. It is unfortunate that it can only display files, and not image created on the fly (i.e., you dump all the pixel values into the terminal and it shows an image).
The actual extension does support images created on the fly. All that's missing is some commandline tool that'll translate from whichever format it's in to the format iterm expects. For e.g. a PNG image data you could probably get away with a single-line bash script: all it has to do is stick an escape sequence in front of the base64 encoded file contents.
that's great! I hope it will be implemented for xterm and becomes a sort of standard. Sometimes I use "sixels" but they are hopelessly slow and low-resolution.
Not much a fan of the base64 encoding here. I'd prefer if it was the pixel binary buffer data that you output directly, pinching a hole in the terminal protocol. The fact taht it is binary does not pose problems if the escape sequence contains the size of the image.
imgcat and image displaying is amazing; I use a matplotlib backend that renders plots inline in the terminal, makes remote working much nicer.
Along with imgcat there’s it2dl. Downloads a file from the remote system browser-style. It’s much more convenient than scp, especially when several sessions deep.
I've found a lot of use from cmd-shift-e, which shows timestamps for each output line in the terminal. Great for figuring out how long a process ran for.
Basically the prompt command writes the current time stamp on the right edge of the window whenever the prompt is printed. Then PS0 overwrites that time stamp right before a command is executed.
If you want the time stamp on the left you can skip the prompt command and tput usage by using the \t escape code in PS1, but PS0 will need to be modified for the new location while still using tput.
Hi, author here. What a great way to wake up, an HN love fest :) Check our the Tip of the Day feature, which is meant to help you find stuff like this.
Can it extract the correct line number from tracebacks, compiler / linter output etc? I wrote this tool, but I know George Nachman has added some features since I wtote it:
It should, I originally built it for rspec output but it should work with most common formats that put the line number attached to the path with a colon.
OK, but beyond path:line_column there are other common formats in which paths and line numbers are dumped to the terminal, e.g. stack traces. The original idea behind iterm2-dwim was to house a useful collection of regular expressions for capturing these, outside iTerm2, but maybe it would make sense to extend the functionality inside iTerm2? So far iterm2-dwim only implements a handful that I personally needed:
Compiler/Linter etc output, e.g.
a/b/c.py:18:1:
Git diff output (note the initial meaningless "a" or "b"), e.g.
This feels like a dumb question, but is the text rendering really dark for others in iTerm2? It seems like on a black background I cannot get pure white text. It’s always a middle shade of gray for me - before and after getting a Retina display.
I have messed with the colors and text rendering for literal hours over the last ten years and I genuinely cannot get it as clear and readable as Terminal.app which is a big part of the reason I always end up falling back to Terminal
There's also a setting that controls the thickness of font strokes, independent of color. I forget exactly how it's labeled (not at my Mac right now), but I remember it's a dropdown with combinations of options for using thin strokes on dark backgrounds and/or Retina displays. I believe it defaults to using thin strokes on Retina displays. I believe turning this off will make font rendering identical to Terminal. Either way, I think it looks better turned off, even on a Retina display.
iterm2-dwim is a click handler for iTerm2. The aim is that you command-click on any file path, relative or absolute, and it opens the file in your editor. If there was a line number, your editor goes to that line. So, compiler/linter output, tracebacks, git output, etc.
Currently Emacs, PyCharm and Sublime are supported.
For me, the killer feature is supporting inline plots in a shell, in a terminal-based Emacs session, etc. I have a short section in my latest book on setting it up, which you can read free online: https://leanpub.com/hy-lisp-python/read#leanpub-auto-bonus-p...
I installed it on Mac to attempt to come close to using Tilix on Ubuntu but I think I prefer Tilix overall. It comes default with Ubuntu Budgie. Tilix isnt perfect and has its weirdness but its really awesome to use.
Weird thing to say, considering both Windows and Linux-based systems are way more developer-friendly.
(Windows due to VS and the rest of MS resources/docs/tools, Linux due to its package management systems natively supporting just about anything you could ever need for development. For macOS to compete, you need a plethora of best-effort or paid tools that don’t come from Apple).
Also a weird thing to say. VS is on Mac, and not everyone uses VS to develop. Mac also has brew, which is a great package manager that can replace apt and the like.
Sounds like you have a specific use case that requires you to use Windows and are projecting that on every other use case. There is a reason why Macs are used in a lot of development shops.
I love iTerm2 and have been using it for years. Thanks to this post I've even learned a couple of new things that make me love it even more.
One thing I've been trying to get working in iTerm2 has been AWS profile badges. iTerm2 has the ability to use text "badges"[0] to give feedback about the current environment. I'm an AWS engineer and tend to switch between environments a lot, so I thought it would be great to use the badges functionality to let me know when I was in the production environment vs. say, the development environment. This seems pretty simple but I haven't been able to get it to work.
How does your shell know which environment you're in? Is it that you ssh into one environment or another one, and you want the badge to show which one you've connected to?
I cut and paste environment variables into the shell to authenticate to different accounts. Originally, I was trying to trigger an event by looking for specific words (ie. AWS_SECRET_ID) but that didn't seem to work reliably.
Consider giving yourself some bash functions with appropriate names, which set the env vars and switch the badge too. Then instead of pasting each time, you'll just use the function name in the shell.
iTerm2 is what made me finally use Emacs in the terminal, completely replacing vim for me.
You can configure Emacs when running from the terminal to respond to mouse input or to integrate with the system's clipboard. You make it run in server mode, via a Launchd config and you get instant startup times too.
iTerm2 also has built-in powerline glyphs. It was actually easier to configure Emacs's powerline package to work from the terminal than it was to work from the GUI version.
I also like iTerm2's tmux integration.
iTerm2 is one of the reasons why I won't abandon MacOS for my software development needs anytime soon.
Have you ever needed to run a long-running job over SSH? If your command is still running and SSH disconnects, your command gets terminated. You can work around this by using nohup like this: `nohup <command> &` to launch your program.
Tmux is kind of like nohup, but for the whole shell. If you SSH into a terminal and start tmux, it'll give you a shell that survives disconnect/reconnect.
Tmux can also act sort-of like a tiling window manager for your shells. So you could have a few shells open, and maybe split your screen 50/50 between two shells, or 50/25/25 or something.
It's a pretty useful program if you spend a lot of your day SSHed into external machines (or if you like to work locally in a full-screen terminal window). It's also got some esoteric keybindings and a steep learning curve and it messes around with your mouse, scrollback, and copy-paste.
iTerm2's tmux integration ignores the disconnect/reconnect stuff (although if you reconnect, your session will just "come back" in whatever state it was when you disconnected). The killer feature is that it takes tmux's window-manager functions and maps them onto tabs and windows in the GUI app. This basically makes it look and feel like you're running iTerm from whatever machine you're logged into over SSH, except that what actually happens under the hood is a bunch of tmux magic.
In short, it's a terminal multiplexer (hence the name, tmux) that allows you to run multiple terminals within one (as opposed to opening a new window for each interactive shell you want to use). I spend 90% of my time as a developer either inside tmux or a web browser, so it wouldn't be a stretch to say that I find it quite useful.
The functionality I use the most in tmux is:
- attaching and detaching from a tmux session (e.g., for running machine learning jobs over SSH)
- having multiple terminals open inside of one
- scripting the setup of windows, panes, etc. for different projects I'm working on
I basically use vim and tmux as an IDE: my usual setup consists of one large pane consisting of vim and code, while two other panes are available for running git commands, starting servers, etc. Within one tmux session I separate different projects (e.g., frontend and backend) into tmux windows, and it's very easy to switch between panes, windows and sessions using keyboard shortcuts.
If you didn't miss it until now, it's likely you won't need in much in the future, either. Three main features and their value as I judge them:
* Detach/reattach sessions. This is useful; I run a always connected IRC client on my home machine in a detached session, then reattach to it on the go or from work. Tip: http://enwp.org/Byobu_(software) / http://byobu.co has a vastly better out-of-the-box experience than plain tmux.
* Split screens. I never use it. My GUI terminal emulator software already can do that, but plain tabs or the window manager's features have always been sufficient.
* Connection multiplexing. SSH already does that for me, see `ControlMaster` and `ControlPath` in `man 5 ssh_config`.
Anyone else have any problems getting the first one to work?
I could run /usr/local/bin/hub browse -- commit abc123 without issue, but iTerm wasn't even changing to cursor when hovering over a hash and holding cmd.
Question. Do you know how to get iTerm2 to open on split into the same directory that it was in like in Terminator on Ubuntu? Currently it always open to home directory whether I do a vertical/horizontal split.
Go to Preferences->Profiles->Default and find the option over on the right for "Working Directory". Then set it to "Reuse previous session's directory".
Then for me Cmd+D and Cmd+Shift+D (split with current profile) gives the same current directory.
Depending on your workflow, you might even want the advanced configuration version of this.
I want new windows (which I rarely use) and new tabs to be my home directory, but split panes to be the directory I was in when I split. Works wonders.
I've wondered whether it's possible to setup profile-specific (or folder-specific) aliases? I understand it might be zsh feature that I'm really after, but perhaps iTerm can solve it too?
I think you'll have to look into some scripting then; what you could do is create your aliases for each profile in a separate folder, then use the 'Send text at start' profile to just do a `source ~/profiles/1/aliases.sh` or something to that effect.
I'm a little jealous of iTerm, not going to lie. The UX is pretty nice from what I've seen, but I can't find a like for like replacement for either Windows or Linux.
- ability to plug into any monitor at any resolution that monitor supports
- ability to copy and paste to/from my phone
- Transmit - I really haven't found many good s3 clients on Linux
- ScreenFlow
- Git Tower
Most of these have some sort of a work-around or close analog of course. (So I'd likely not be "giving anything up" as much as compromising or learning new techniques) However, I'm not sold on the benefits (other than ideological ones, the only thing that comes to mind is increased Docker performance) outweighing the costs. For someone with a different workflow and set of tools, a different conclusion may result.
Check out KDE Connect, it's a great piece of software for copy/paste, remote inputs and more. Will even wake your computers up when you walk in the door :)
To each their own, but yes, personally I find the UX of Mac GUI applications to be generally a lot more appealing compared to the alternatives available on Linux.
These projects were developed by volunteers and are distributed free of charge. No need to be a jerk.
Plus if there's something you don't like you can always pull the code, modify what you need and submit a pull request.
I use Linux everyday and I prefer a slightly off UI once in a while than having to deal with the frustratingly sluggish performance of macOS.
iTerm2 has (had? I stopped using it a while ago) the tendency to drop data from a large paste. No problems with the built-in Terminal.app so I just went back to that.
Tmux can be a pretty complex piece of software, but iTerm can basically wrap it all up into a nice package. You don't need to know anything at all about tmux to use iTerm's tmux integration.
If you're SSHed into a server that has tmux installed, try running `tmux -CC` on the server. It'll pop up a new window that looks and feels just like it's running natively (complete with tab support), except it's all tunneled over SSH.
And if you disconnect, you can just reconnect later and your windows will all come back in the same state as when you left them.
I use this one-liner to SSH into a server and reconnect (or start) a tmux session:
iTerm2's tmux integration makes SSH access to remote machines feel almost as native as using your machine locally. It's really a killer feature, and it made iTerm2 worth a donation for me.