1

The real start command on MS Windows uses ShellExecute and can therefore open directories and documents in addition to commands. I therefore have a habit of using start . to open Explorer in the current directory.

But the special handling of :!start apparently does not support this. To get the desired behavior (no popup and can open directories or documents) I have to run :!start /b cmd /c start . I can simply use :! start . but then I still get the popup console which has to be dismissed manually. Is there any way to change the :!start command to use ShellExecute and therefore be able to handle directories and documents?

2

:help :! says:

 ...Vim redraws the screen after the command is finished,
because it may have printed any text.  This requires a
hit-enter prompt, so that you can read any messages.
To avoid this use: 
    `:silent !{cmd}`
The screen is not redrawn then, thus you have to use
CTRL-L or ":redraw!" if the command did display
something.

First method:

:silent ! start .

Note: :silent ! method works not only on Windows.

Also. :he :! says:

For Win32 also see :!start.

Let's see:

Q. How do I avoid getting a window for programs that I run asynchronously?
A. You have two possible solutions depending on what you want:
   1) You may use the /min flag in order to run program in a minimized state
      with no other changes. It will work equally for console and GUI
      applications.
   2) You can use the /b flag to run console applications without creating a
      console window for them (GUI applications are not affected). But you
      should use this flag only if the application you run doesn't require any
      input.  Otherwise it will get an EOF error because its input stream
      (stdin) would be redirected to \\.\NUL (stdout and stderr too).

Second method:

:!start /b start .

You can avoid cmd /c here.

And finally, you can alias this long line as a command of your own. It's not exactly what you asked but works as you want.

UPD. No. start . does not use ShellExecute. It just starts explorer.exe for the current path.

  • It does use ShellExecute. It opens directories in Explorer because they are associated with it. If you start a .docx file it will open MS Word, etc. Thank you, I hadn't considered using a user command. – Random832 Jun 21 '15 at 19:10
  • @Random832 Nope. start /? for explaination. When you search for an executable and there is no match on any extension, start searches directory name. If it does, start opens Explorer.exe on that path. – Alex Kroll Jun 21 '15 at 19:19
  • Ah, sorry, I didn't realize this difference because it does use association when opening files. – Random832 Jun 21 '15 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.