43

I am trying to figure out how to change iTerm function when CMD+Clicking on a file in an iTerm window to have it open in my default editor, Atom.

Currently, the CMD+click function in iTerm opens files in Sublime. I have the function CMD+Click set to open with the default app (within iTerm preferences). I have also ensured that this file type is configured to always open with Atom (in the file's info screen from Finder).

If I click the file from finder, it opens with Atom, not sublime text. The only clue I have is that maybe iTerm won't recognize Atom as an editor. If I go to iTerm Preferences > Profiles > Advanced and change the CMD+Click to open with what Editor, only sublime 3 is available in the list of editors to choose from.

Any help would be appreciated!

Insane
  • 2,892
  • 6
  • 26
  • 49
rylectro
  • 533
  • 1
  • 4
  • 7
  • 2
    Note: iTerm2's new release of Build 3.0.0 adds "Atom" to the list of options for the "Open with editor..." dropdown as pictured above. You'll find it now in Preferences under Profiles -> Advanced -> Semantic History. – pdobb Jun 03 '16 at 13:21

2 Answers2

26

Inside Atom, go to the Atom menu and choose Install Shell Commands. This ensures you can call Atom from iTerm.

In that same iTerm preferences screen, change the first select list to Run command... and paste the following into the text field that appears: /usr/local/bin/atom -n \1:\2. That tells the atom command line tool to open the clicked file (\1) at the line number specified (\2).

tjmcewan
  • 408
  • 6
  • 9
  • 6
    Hi! Leaving the "-n" out from your suggestion makes it open in an existing window (which is what I prefer). Unfortunately this makes atom fail to recognize the column number (it goes to the correct line though). Any ideas on this? – Cyberwiz Feb 29 '16 at 15:17
  • Any chance you can add the solution for iTerm2 to your answer please!? Thanks! – Matthew Herbst Feb 03 '17 at 01:58
  • 1
    @MatthewHerbst Atom is an option in the 'Open with editor...' select list now. This answer is no longer useful. – tjmcewan Feb 03 '17 at 04:20
  • I've tried this for Android Studio (which isn't included in the list of editors) but it did not work. I get a "can not open file" error, despite setting up shell commands for the right path in the IDE. Anyone got that working before? – Chucky Jan 24 '22 at 17:18
24

(I use this one. For some reason the iTerm option "Open with default app" doesn't work, but the command "$ open whatever" works like a charm, so I've just set that command.

enter image description here

karel
  • 13,390
  • 26
  • 45
  • 52
Rene Weteling
  • 341
  • 2
  • 2
  • This seems to work well especially if one has multiple versions of same application installed. For eg: VS Code and VS Code Insider. Thanks for sharing! – Kalpesh Panchal May 16 '20 at 00:47
  • 4
    There is also an "Open with editor" option now where one can select VS Code – Yo Ludke Jul 30 '20 at 12:33