0

I have a directory with multiple files. There is one main file and other ones in subdirectories (including in a virtual environment directory) all of which I want to open with one click in the same instance of PyCharm. Is there a way to do this? Is there a native PyCharm way? Is there a way to do it using a Bash script. For the latter I have managed using pycharm.sh (see Open files from the command line). However, the different files are opened in different PyCharm instances which is not what I want.

Kvothe
  • 233
  • 1
  • 8
  • I added the Windows tag because the answer solves the question for that OS. Differences in shell/OS should be minor and the same thread can be used for the different systems. – bad_coder May 18 '21 at 05:45
  • I should have included a tag, but I removed Windows since I am not interested in that and added Linux. I would have thought that bash and the command line would have implied at least Unix, but I guess that Windows can have access to those too nowadays. – Kvothe May 18 '21 at 07:46
  • The answer will also work for bash if you change `pycharm64.exe` for `pycharm.sh` - try it!! The main question is about opening PyCharm with multiple files passed as individual command line arguments, if the only change is the executable name that doesn't justify different questions for it - any other questions would be closed as duplicate regardless of the OS. What is usual in such cases is having 1 question with the solutions for the different OS/shells. If there is any relevant difference at all... – bad_coder May 18 '21 at 12:43

1 Answers1

0

I just tried this on Windows running from CMD. Simply listing the paths to the files separated by a space opens them in a single editor instance. (Although the documentation doesn't clearly mention this possibility, suggesting only 1 single file/project as argument). For example executing the following:

pycharm64.exe C:\test_file1.txt C:\test_file2.txt

Opens like this:

enter image description here

This means PyCharm does accept a list of individual files as command line arguments to open them in a single instance.

all of which I want to open with one click in the same instance of PyCharm.

If the above example works on your shell you should be able to create a shell script that can be clicked.

However, the different files are opened in different PyCharm instances which is not what I want.

I don't know if depending on the shell any special rule applies that might cause each file to be opened in a different PyCharm instance/window, but if that's the case there's also likely to be a shell specific syntax rule to launch a single instance of the application passing multiple arguments.

Is there a native PyCharm way?

It seems PyCharm is naturally geared to working with projects. Looking closely at some functionalities like open/close/search in the PyCharm IDE their logic is entirely "project oriented" not like the usual concept of opening a set of unrelated files as in some other editors. (This is actually really smart, it doesn't clutter the UI with marginal functionalities and it forces users to set up a project - see this thread for a similar example about using search with individual unrelated files in PyCharm).

If you look at the screenshot, it's noteworthy that only 1 file is listed in the Project Tool Window although several files are opened in the editor.

bad_coder
  • 11,289
  • 20
  • 44
  • 72