Skip to content

Instantly share code, notes, and snippets.

@matangover
Last active August 13, 2024 11:23
Show Gist options
  • Save matangover/96aa1a1bbc36cdc2a7cd35c52091aab1 to your computer and use it in GitHub Desktop.
Save matangover/96aa1a1bbc36cdc2a7cd35c52091aab1 to your computer and use it in GitHub Desktop.
Easily open files from Python tracebacks in iTerm2 directly in your editor
  1. In iTerm2, go to Settings -> Profiles -> Advanced -> Smart Selection -> Edit
  2. Click + to add a rule with the following values:
    • Notes: Python traceback
    • Regular Expression: File "(.+)", line ([0-9]+), in .+
    • Precision: Very High
  3. Click Edit Actions... and add an action to open in your editor. For example, if you use VS Code, add an action with the following values:
    • Title: Open in VS Code
    • Action: Run Command...
    • Parameter: /usr/local/bin/code -r -g "\1":\2
  4. Cmd+Click any location in the traceback to open the corresponding line directly in your editor. (Don't click the actual filename, click anywhere else on the same line.)
@SteveAlexander
Copy link

I found the parameter needs to be /usr/local/bin/code -r -g "\d/\1":\2 with iTerm 3.3.2

@ruohola
Copy link

ruohola commented Oct 6, 2020

Thanks! Work great with PyCharm with the parameter: /usr/local/bin/pycharm --line \2 \1

@brechtm
Copy link

brechtm commented Aug 13, 2024

To make this work for a remote SSH VS Code project:

/path/to/code --remote ssh-remote+<hostname> --reuse-window --goto "\1":\2

Replace <hostname> with the remote host's hostname.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment