Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dobogo
Copy link

@dobogo dobogo commented Mar 18, 2017

ShellExecute Win32 API enables :!start <filename> open a file with default app.
For example, :!start index.html make the default browser open index.html.

@vim-ml
Copy link

vim-ml commented Mar 18, 2017 via email

@brammool
Copy link
Contributor

Can you please write something for the help file, to explain users how this works?

Ideally we would also have a test. But that might not be so easy.

@SureshGovindachar
Copy link

SureshGovindachar commented Mar 18, 2017

  1. If :start <file> is built into Vim, what will this command do in non-MS Windows Operating Systems?

  2. It appears there are quite a few things one could do with Windows' start command -- see these two links: Use RunDll32 Utility and Using Rundll

  3. Based on the links in (2), couldn't a user on Windows create a plugin, perhaps using VimL's dictionary (associative array), to access things on his computer in all sorts of ways -- more elaborate ways than what one would want to have built-into Vim?

  1. start is a built-in MS Windows' command (open cmd window and see start /?) -- and !start has a well-defined meaning in "yesterday's" Vim -- won't this patch break this expected meaning for :!start? For example, in "yesterday's" Vim, :!start works as do the following mappings:

    nnoremap \ie :silent !start "c:\program files\internet explorer\iexplore.exe" -nohome
    nnoremap \x :silent !start rundll32 url.dll,FileProtocolHandler
    nnoremap \xp :silent !start rundll32 url.dll,FileProtocolHandler %:p:h/

and won't the proposed patch break the above -- more general and expected -- functionality? How can Vim take over a Windows' command name and apply it to a narrower use?

dobogo added 2 commits March 19, 2017 13:32
ShellExecute Win32 API enables `:!start <filename>` open a file with default app.
For example, `:!start index.html` make the default browser open index.html.
@dobogo dobogo force-pushed the start-with-shellexecute branch from 0f4cb1d to 8fce03f Compare March 19, 2017 05:03
@dobogo
Copy link
Author

dobogo commented Mar 19, 2017

I have added examples of :!start to the doc.

This patch will improve compatibility of :!start with Windows built-in "start" command.

Current Vim's :!start emulates Windows' "start" command using CreateProcess API to achieve asynchronously execution. This special behavior is enabled only on Windows. It, however, is not completely compatible with Windows' "start". Windows' "start" can be given a file name or URL, and will open it with default program while Vim's :!start cannot.

On the other hand, :! start is completely compatible because it just calls Windows' "start". So we have been able to do :! start http://www.vim.org/. This asymmetry confuses users.

This patch does not break current :!start behavior because ShellExecute will be used only when existing emulation failed. So any scripts or plugins will not be affected by this patch.

@SureshGovindachar
Copy link

The expectation is that anything after :! is provided to the system and :<without !> is handled as per Vim's specification. For example, :!grep runs whatever the system thinks it should do with grep whereas :grep has Vim do what the users has specified via 'grepprg'.

Likewise !start should be handled by the system without any interference by Vim -- for example, on Linux, if a user has something called start in his path then this is what should be executed, on Windows it should execute MS Windows' start unless the user has somehow modified his system to give start some other meaning.

Unfortunately, Vim has :startinsert with :start[insert] being a short hand. And Vim also has :!start as indicated in :help :!start. Since start is a Windows command, by providing a special meaning to :!start, there is now a conflict with the meaning for :!. This is as though Vim gave a special meaning to :!grep.

I believe Vim should never have provided a special meaning to :!start. This not only violates the meaning of :! it also puts Vim in the position of doing things differently on different operating systems. Also, doesn't Vim avoid providing features as built-in those that could be provided via plugins? And can't whatever is done with built-in :!start be done with plugins? Perhaps the built in support for :!start should be moved to a plugin?

@dobogo
Copy link
Author

dobogo commented Mar 20, 2017

@SureshGovindachar,

I agree with your believe, but changing or removing !start may break existing plugins depending on it, of course including your .vimrc. Therefore we should not remove it.

The problem that we should discuss here is that current !start command is not compatible with start command even though it is expected to emulate start command.

The objection of this patch is to solve the problem, not to add any new feature or change current !start objection.

@brammool brammool closed this in b2964f2 Mar 21, 2017
chrisbra pushed a commit to chrisbra/vim that referenced this pull request Mar 25, 2017
Problem:    On MS-Windows ":!start" does not work as expected.
Solution:   When creating a process fails try passing the argument to
            ShellExecute().  (Katsuya Hino, closes vim#1570)
chrisbra pushed a commit to chrisbra/vim that referenced this pull request Mar 28, 2017
Problem:    On MS-Windows ":!start" does not work as expected.
Solution:   When creating a process fails try passing the argument to
            ShellExecute().  (Katsuya Hino, closes vim#1570)
desvp pushed a commit to desvp/vim that referenced this pull request May 30, 2017
Problem:    On MS-Windows ":!start" does not work as expected.
Solution:   When creating a process fails try passing the argument to
            ShellExecute().  (Katsuya Hino, closes vim#1570)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants