Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vim] Start new terminal for nvim in Windows #882

Closed
wants to merge 7 commits into from

Conversation

janlazo
Copy link
Contributor

@janlazo janlazo commented Mar 24, 2017

This PR starts allows the vim plugin to work for Neovim in Windows by starting a new and separate terminal via cmd.exe and the start command. This is a workaround for the missing :terminal support.

I used jobstart() and on_exit to mimic s:execute() for Vim in Windows.

Tested only in Windows 8.1 and a recent March build of Neovim for Windows.

@junegunn
Copy link
Owner

Thanks. As far as I know, Windows support of Neovim is experimental and is not officially announced yet. I'm not quite sure if I want to add code for it at this point.

I used jobstart() and on_exit to mimic s:execute() for Vim in Windows.

So Neovim for Windows will not have :terminal? Then can't we just unset use_term and use the same code for ordinary Vim on Windows? Any reason s:execute can't run on Neovim?

@justinmk
Copy link
Contributor

So Neovim for Windows will not have :terminal ?

It's planned, and was working at one point, but no timeframe on it.

@janlazo
Copy link
Contributor Author

janlazo commented Mar 25, 2017

:!some_shell_command is non-interactive and is shellescaped by Neovim. :!fzf works but the UI is frozen and the user cannot see fzf running. Shellquoting in Windows is not resolved yet and system() is non-interactive. jobstart(['executable', 'args', ...], callback_dict) is the only choice left to run a separate process and terminal for fzf and get around the shellquoting issue. Doing this does not freeze the Neovim UI so putting the jobstart in s:execute() would return an empty array. If we move the new code in s:execute(), would this break any assumptions in the code meant for ordinary Vim?

Nightly builds of Neovim for Windows include nvim-qt for a GUI because there's no TUI officially available yet so we can limit the scope of the new code for Neovim GUIs in Windows only.

@justinmk
Copy link
Contributor

TUI is "sort of working" in neovim, and the related PR will be merged soon.

@janlazo
Copy link
Contributor Author

janlazo commented Mar 26, 2017

:FZF C:/Program\ Files\ (x86)\ fails in Neovim for Windows. Paths with no spaces work. Toggling shellslash changes some slashes but the result is the same. Moving the code to s:execute() has no effect.

Full command:
fzf --multi --prompt 'C:/Program Files (x86)/' --expect=ctrl-v,ctrl-x,ctrl-t --no-height > C:/Users/JANEDM~1/AppData/Local/Temp/nvimzOaZXl/0

Does neovim/neovim#6359 fix this issue?

@janlazo
Copy link
Contributor Author

janlazo commented Mar 26, 2017

@junegunn How far can I go for handling the filepaths on Windows?
I need to add fzf#fnamemodify() and fzf#getcwd() for s:shortpath() since shellslash affects both the shellquoting (which depends on the slash) and the filepath slashes (forward or back). I'll need to use batch file because backslashes are shellescaped via double-quotes which breaks :! in Vim.

I'm defaulting to set noshellslash with backslash filepaths for Vim.
Paths with spaces still break on Neovim though.

@justinmk I'm using this build currently. Should I get the latest?
nvim --version
NVIM v0.2.0-828-g11b08bb0
Build type: Release
Compilation: C:/msys64/mingw64/bin/gcc.exe -Wconversion -O2 -DNDEBUG -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -D__USE_MINGW_ANSI_STDIO -D_WIN32_WINNT=0x0600 -Wvla -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -IC:/projects/neovim/build/config -IC:/projects/neovim/src -IC:/projects/neovim/.deps/usr/include -IC:/projects/neovim/.deps/usr/include -IC:/projects/neovim/.deps/usr/include -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include -IC:/projects/neovim/build/src/nvim/auto -IC:/projects/neovim/build/include
Compiled by appveyor@APPVYR-WIN

@justinmk
Copy link
Contributor

@janlazo try neovim/neovim#6359 or just wait for it to be merged.

@janlazo
Copy link
Contributor Author

janlazo commented Mar 26, 2017

set noshellslash should cause shellescape() to double-quote but it always single-quotes in Neovim.
fzf --prompt 'C:\Program Files (x86)\' fails on cmd but works on powershell. Tradeof is the startup of the new powershell process.
Using the batchfile didn't matter because the prompt issue is on cmd.

- required for jobstart() with list arguments
- meant for Neovim in Windows-only
- maintain backslash and space escaping in Vim
@janlazo
Copy link
Contributor Author

janlazo commented Mar 26, 2017

I used powershell in this commit, janlazo@7a752fb, to get around the single-quote escaping. I passed -NoProfile to speed up startup time similar to vim -u NONE.
:FZF path_with_spaces work on that commit for Neovim on Windows.

@janlazo
Copy link
Contributor Author

janlazo commented Mar 28, 2017

@junegunn This PR has a mixture of commits meant for Vim but is compatible with Neovim via powershell. I can make a separate PR for using backslashes in Windows filepaths such that, with set noshellslash, the finalized command passed to :! should use backslash for all filepaths.

@junegunn
Copy link
Owner

Thanks for your work @janlazo. To be honest, it's a little hard for me to follow this thread; what are the exact problems we are trying to solve? What are the steps to reproduce each problem and how do we validate the correctness of the fixes? Are we talking about Vim, Neovim, or both? Is this the right time for us to make changes for unannounced Neovim? Is it okay for us to proceed with the Neovim issues mentioned above unresolved? Do we have to fix the code for :FZF command? Because then we also have to fix some commands in fzf.vim repository.

So basically what I'm saying is that I'd like to see this PR broken down into smaller ones each tackling a single problem.

@janlazo
Copy link
Contributor Author

janlazo commented Mar 30, 2017

There are at least 3 separate problems we're trying to solve:

  • (Vim/Neovim) ambiguity in shellescaping when running shell commands via cmd.exe in Windows
    • shellslash affects any VIm behaviour dealing with filepaths in Windows.
      In this PR, wrapper functions are used to handle getcwd(), fnamemodify() in s:shortpath().
      We have fzf#shellescape() for shellescape() to escape the prompt but it only works with :! because the prompt filepath uses forward slash. Switching to backslashes on the prompt alongside fzf#shellescape() breaks the prompt, output redirection, and the rest of the command.
      We can use a batch file but :FZF is already working without it.
    • When using backslashes for Windows filepaths that will be used in system() or :!, fzf#shellescape() may not be necessary because cmd.exe allows C:\Program Files (x86) unquoted. Using fzf#shellescape() risks breaking the prompt because the added quotes would have to be escaped as well.
  • (Neovim) no stable workaround for missing :terminal support in Windows
    • Using your master branch, running :FZF on Neovim in Windows doesn't work because shellescape() doesn't work as expected with set noshellslash and the Vim plugins assumes that, if Neovim is used, then :terminal must be available.
      To reproduce the error, init.vim only contains set rtp+=~/.fzf for the Vim plugin and run :FZF. It should always fail no matter what filepath is used, including s:shortpath().
    • What we can do is mimic the behaviour of :FZF for Vim GUI and leave it at that. I can only provide support for the Neovim GUIs (ex. nvim-qt, nyaovim) as an end-user.
      As you suggested, we'll unset use_term and run s:execute(). I'll limit the differences to swapping :! for jobstart() for the callback when fzf exits and trivial shellescaping. If some of the common filepaths in Windows don't work, then there's no point expending effort for Neovim support in Windows until the official release.
  • (Vim/Neovim) printf format to start a new, separate terminal for the GUI. Currently, only Vim can support running the command directly on :! on the GUI to make new terminal. To be compatible with both, use :!start.
    This PR uses start /WAIT cmd /c %s (debug by replacing /c with /k).

@junegunn
Copy link
Owner

There are at least 3 separate problems we're trying to solve:

Can we have separate PR for each subproblem? I'd like to delay merging Neovim-related changes and wait for the related issues are cleared.

@janlazo
Copy link
Contributor Author

janlazo commented Apr 12, 2017

neovim/neovim#6497 is merged to master so I'll open another PR just for jobstart in Neovim. Anything else comes after #896

@janlazo janlazo closed this Apr 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants