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

fzf on gvim windows without WSL? #1093

Closed
2 of 14 tasks
ghost opened this issue Oct 18, 2017 · 66 comments
Closed
2 of 14 tasks

fzf on gvim windows without WSL? #1093

ghost opened this issue Oct 18, 2017 · 66 comments

Comments

@ghost
Copy link

ghost commented Oct 18, 2017

  • Category
    • [] fzf binary
    • fzf-tmux script
    • Key bindings
    • Completion
    • Vim
    • Neovim
    • Etc.
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Windows Subsystem for Linux
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

I'm not sure that fzf can run without a shell yet. But if possible, please add this feature, the only thing that I can't try fzf on my windows is I don't have a shell except cmd.exe.

@junegunn
Copy link
Owner

It works if you have the latest version of Vim supporting :terminal. But please note that :terminal of Vim itself is a very young feature and is not known to be stable.

@junegunn
Copy link
Owner

See #1019

@ghost
Copy link
Author

ghost commented Oct 20, 2017

@junegunn: assume my givm on windows support terminal and it did.
what args should I add to gvim in cmd?
Is this correct? : gvim --enable-terminal

@junegunn
Copy link
Owner

junegunn commented Oct 20, 2017

No, it's determined at compile time.

@ghost
Copy link
Author

ghost commented Oct 22, 2017

@junegunn: If that I think I installed gvim that enabled terminal and :terminal work.
open gvim, fzf via choco, fzf.vim and try to trigger fzf from gvim only show a splashing window.

@junegunn
Copy link
Owner

Having :terminal doesn't necessarily mean that your GVim meets the version requirement. Try installing the bleeding edge version and see if it helps.

let has_vim8_term = has('terminal') && has('patch-8.0.995')

@ghost
Copy link
Author

ghost commented Oct 22, 2017

@junegunn : result from gvim --version on cmd : Included patches: 1-1184
Is this okay to run fzf?

@junegunn
Copy link
Owner

junegunn commented Oct 22, 2017

only show a splashing window

What exactly do you mean by this? Can you post a screenshot/screencast of what happens?

@ghost
Copy link
Author

ghost commented Oct 22, 2017

@junegunn : I mean it open a window very fast and then disappear immediately when i try :Files or :FZF. All I can see is a line contain cmd.exe like it try to open command from cmd then destroy right after that.
all components installed:
repos: fzf, fzf.vim
binary: choco install fzf

@junegunn
Copy link
Owner

A new window or a split window inside GVim? If former, make sure that you have the latest version of the main vim plugin. You should see two files in the output of :echo globpath(&runtimepath, 'plugin/fzf.vim'), for example,

/Users/jg/.vim/plugged/fzf/plugin/fzf.vim
/Users/jg/.vim/plugged/fzf.vim/plugin/fzf.vim

and the former — vim plugin from the main repo — should be identical to https://github.com/junegunn/fzf/blob/master/plugin/fzf.vim.

@junegunn
Copy link
Owner

By the way, even if you have an older version of vim plugin that does not support :terminal and uses an external cmd.exe window, it shouldn't exit immediately. Make sure that you don't have any FZF_DEFAULT_COMMAND or FZF_DEFAULT_OPTS defined that might affect the behavior.

@ghost
Copy link
Author

ghost commented Oct 23, 2017

@junegunn : I have output after run the echo command:

C:\Users\YYYY\vimfiles\pack\plugins\start\fzf.vim\plugin\fzf.vim
C:\Users\YYYY\vimfiles\pack\plugins\start\fzf\plugin\fzf.vim 

I use native plugin manager so it's not different.
Yes, a new split window inside gvim. I've just installed plugins and aslo the lastest gvim (just couple days ago).

Make sure that you don't have any FZF_DEFAULT_COMMAND or FZF_DEFAULT_OPTS defined that might affect the behavior.

Yes, I don't have any kind of those variables in my bashrc, bash_profile or something similar.
Please follow this short video that I upload for issue's demo:
https://drive.google.com/file/d/0BzNBUeqn5ZK5X1hqMldLdWF1WFE/view?usp=sharing

@junegunn junegunn reopened this Oct 23, 2017
@junegunn
Copy link
Owner

@janlazo Hi, any idea on this? :terminal windows opens and immediately closes.

@janlazo
Copy link
Contributor

janlazo commented Oct 23, 2017

Try set shellcmdflag=/k so cmd.exe doesn't exit immediately. Any errors or is it only a blank screen?
Does :terminal fzf > \%TMP\%\_fzf_tmp.txt work?

It seems cmd.exe ran (No CreateProcess error from term_start) but fzf is not in %PATH% (does it contain choco's bin/ (or similar) directory), or the shellescaping is wrong, or fzf exit early.

I use 8.0.1123 myself and there are :terminal changes from 1123-1184.

@ghost
Copy link
Author

ghost commented Oct 23, 2017

@janlazo : Yes, :terminal fzf > \%TMP\%\_fzf_tmp.txt does work.
set shellcmdflag=/k in vimrc is workaroud solution. But all plugins that require to open cmd will wait for user to exit manually.
I think fzf is in %PATH% (under C:\ProgramData\chocolatey\bin?), cmd recognize fzf command in cmd.

@janlazo
Copy link
Contributor

janlazo commented Oct 23, 2017

@tuyenpm9 Do you set any of the global variables mentioned in https://github.com/junegunn/fzf/blob/master/README-VIM.md#configuration? Also, can you check the value of s:exec? I want to know if the Vim plugin is using a different fzf binary from what you installed via choco.

@ghost
Copy link
Author

ghost commented Oct 23, 2017

@janlazo : No, I don't have any configs, just installed.

:echo s:exec
E121: Undefined variable: s:exec
E15: Invalid expression: s:exec

Does that check s:exec correctly ?

@janlazo
Copy link
Contributor

janlazo commented Oct 23, 2017

In s:fzf_exec, it sets s:exec. Can you add echom s:exec before it returns here https://github.com/junegunn/fzf/blob/master/plugin/fzf.vim#L135 and post the output displayed in :messages?

@ghost
Copy link
Author

ghost commented Oct 23, 2017

I put echom s:exec as below:

function! s:fzf_exec()
  if !exists('s:exec')
    echom s:exec
.....

Sorry about this, I tested with tagbar and ripgrep plugins, only ripgrep has problem with waiting exit cmd manually

all plugins that require to open cmd will wait for user to exit manually.

The waiting cmd windows as below:

C:\WINDOWS\system32\cmd.exe /k (rg --column --line-number --no-heading --fixed-strings --no-ignore --hidden --follow -g ^"*.{py,c,cc,cpp,rs}^" -g ^"!{.git}/*^" -g ^"!{tags}^"  is_subdir ^>C:\Users\YYYY\AppData\Local\Temp\VIe61BD.tmp 2^>^&1)

C:\Users\YYYYY\vimfiles\pack\plugins\start\fzf>\>

I have to type exit to make it work.

Either with echom s:exec or not, ripgrep still need to exit explicitly.

@janlazo
Copy link
Contributor

janlazo commented Oct 23, 2017

Running this on cmd.exe prompt directly fails too? The shellescaping looks suspicious to me even if Vim does this with sxq and sxe.

Can you give me the link for the ripgrep plugin and show me how fzf interacts with ripgrep (pipe?, stdin via temp file?, etc.)?

Edit:
Running your command in the cmd.exe prompt (or session) fails on my machine and will fail in the batch file that fzf uses if you set FZF_DEFAULT_COMMAND to that command.

@ghost
Copy link
Author

ghost commented Oct 23, 2017

Have:

function! s:fzf_exec()
  if !exists('s:exec')
    echom s:exec
.....

and comment out set shellcmdflag=/k and it works.

Should we add echom s:exec in fzf.vim?

@ghost
Copy link
Author

ghost commented Oct 23, 2017

I used vim-ripgrep plugin. and modify rg command that pass some args as shown above.

@janlazo
Copy link
Contributor

janlazo commented Oct 24, 2017

I can't reproduce the problem on gvim 8.0.1184 with my vimrc.

To recap:

  • running "fzf" works in cmd.exe terminal and Vim 8 :terminal so the problem is on the Vim plugin
  • defaults only
    • no environment variables specific to FZF
    • no global variables in vimrc
  • adding echom s:exec to delay Vim 8 terminal solves the problem (?)
    • the following snippet should fail on the initial run because s:exec is not set yet
       function! s:fzf_exec()
       if !exists('s:exec')
          echom s:exec
       ...
  • set shellcmdflag=/k doesn't close the split immediately because cmd.exe runs but no hints or errors left behind
    • gvim title should have !cmd after running :FZF

Can you reproduce the problem with a minimal vimrc or gvim -u NORC and try running it at least 3 times consecutively on a fresh start and check if there are any differences between each run?
Also, term_wait is called here https://github.com/junegunn/fzf/blob/master/plugin/fzf.vim#L705. Can you make it run in Windows by removing && !s:iswin

      " FIXME: https://github.com/vim/vim/issues/1998
      if !has('nvim')
        call term_wait(t, 20)
      endif

@ghost
Copy link
Author

ghost commented Oct 24, 2017

The issue is that I can't keep fzf's window after run :FZF or :Files under gvim on windows 10, that has workaround solution here but I'm not familiar with written source code so I have no idea how echom s:exec works and it shoud added or not to fzf.vim file.

Follow your guide, I run gvim -u NORC, I got errors below, press enter, fzf's windows is kept - if echom s:exec is not added to fzf.vim. If add echom s:exec to fzf.vim fzf's windows is destroyed immediately, I tried at least 3 times.

Error detected while processing function <SNR>22_cmd[15]..fzf#run[64]..<SNR>22_execute_term[60]..<SNR>22_wrap_cmds:
line    1:
E15: Invalid expression: 
E15: Invalid expression: ['@echo off', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] +

Now I remove && !s:iswin in fzf.vim and run gvim -u NORC, try :FZF, same errors as above, fzf's window is kept if echom s:exec is not added to fzf.vim. and the same is destroyed immediately if add echom s:exec to fzf.vim.

@janlazo
Copy link
Contributor

janlazo commented Oct 24, 2017

I get the same error with Invalid expression if I load the plugins after VimEnter if I run gvim -u NONE. I assumed gvim -u NORC would load the fzf plugins within pack/plugins/start/ by default but there are other factors in play.

@janlazo
Copy link
Contributor

janlazo commented Oct 24, 2017

Run this on cmd.exe.
Replace ~/.fzf with the path of the fzf package.
In your case, it's ~/vimfiles/pack/plugins/start/fzf.

gvim.exe -u NONE --cmd "set nocp | set rtp+=~/.fzf | runtime! plugin/fzf.vim"

Once gvim is running, try :FZF.

@janlazo
Copy link
Contributor

janlazo commented Oct 26, 2017

Is TERM set in cmd.exe and powershell?

@ghost
Copy link
Author

ghost commented Oct 26, 2017

No TERM set in Environments Variables.

@janlazo
Copy link
Contributor

janlazo commented Oct 26, 2017

if you unset $TERM as follows in vim, does it work?

let $TERM = ''
FZF

@ghost
Copy link
Author

ghost commented Oct 26, 2017

Yes, It does work. Do you have any clues?

@janlazo
Copy link
Contributor

janlazo commented Oct 26, 2017

To recap

@ghost
Copy link
Author

ghost commented Oct 26, 2017

echo $env:TERM in cmd result echo $env:TERM
echo $env:TERM in powershell result xterm-256color
TERM is not set in Environments Variables --> yes
TERM is set in Vim and this output #1093 (comment) hasn't changed --> yes
Plus echo $TERM in gvim result xterm-256color
Windows just got update yesterday.

@janlazo
Copy link
Contributor

janlazo commented Oct 27, 2017

I need more info on what parts were updated and how you did the update.

@ghost
Copy link
Author

ghost commented Oct 27, 2017

You can view list updated here

@ghost
Copy link
Author

ghost commented Oct 27, 2017

I've made a clean installation (all components removed) for vim with this installer, latest version is 8.0.1214.
After that fzf works as expected.

Another quick new question: How can I remove line that contain !cmd.exe [running] when open fzf?

@ghost ghost closed this as completed Oct 27, 2017
@ghost
Copy link
Author

ghost commented Oct 27, 2017

I still have double enter to open a file. Weird that if FZF is searching then I can open a file with just 1 enter.

@janlazo
Copy link
Contributor

janlazo commented Oct 27, 2017

How can I remove line that contain !cmd.exe [running] when open fzf?

Are you referring to the window title? The Vim plugin runs fzf runs on a special buffer/split associated with the current buffer (what you see before running :FZF). It doesn't restore the previous title immediately but I don't know why Vim behaves like this. Alternative is to disassociate the terminal buffer but it creates an extra split.

I still have double enter to open a file. Weird that if FZF is searching then I can open a file with just 1 enter.

The race condition is still there so you have to bare with the double enter issue until fzf's golang dependencies are updated.

@ghost
Copy link
Author

ghost commented Oct 27, 2017

Please refer this pic about !cmd.exe [running] line. I just open gvim then open fzf, nothing seems happend and no buffers opened.

The race condition is still there so you have to bare with the double enter issue until fzf's golang dependencies are updated.

Hope it will be soon, I moved to fzf.

@janlazo
Copy link
Contributor

janlazo commented Oct 28, 2017

!cmd.exe [running] is the "filename" of the Vim 8 terminal buffer. The Vim plugin runs fzf on the shell, either sh (Unix) or cmd.exe (Windows). ! is to give the impression it is like :! but in a buffer instead.
:terminal fzf results in !fzf because it runs fzf binary directly (no shell). [running] means the process associated with the terminal buffer is running. You can check Task Manager or tasklist in cmd.exe to confirm this new process.

@ghost
Copy link
Author

ghost commented Oct 28, 2017

@janlazo : but how to hide that tab line?, it's not useful and take a lot of space.

@ghost
Copy link
Author

ghost commented Oct 28, 2017

I've just installed fzf under Windows Subsytem Linux (WSL). So I guess I can avoid !cmd.exe bar by calling fzf via bash instead of via cmd.exe.
If I install fzf on WSL, I can call it via > bash -c 'fzf' but to pass other parameters to fzf under bash I have to put it under '' that make it difficult to instruct gvim to use fzf on bash.
Is there a way to make it work?

@janlazo
Copy link
Contributor

janlazo commented Oct 28, 2017

I don't have WSL so I can't help you there.

@ghost
Copy link
Author

ghost commented Oct 28, 2017

How about hide !cmd bar?

@ghost
Copy link
Author

ghost commented Oct 28, 2017

I've found a workaround is to disable status bar set laststatus=0
One more question, I see the cursor when open fzf is blinking and it's distract a lot. How to disbale blinking of the cursor on fzf?

@ghost
Copy link
Author

ghost commented Oct 28, 2017

So If we use this proxy to redirect fzf from windows to inside of WSL, the link is here
But I don't know how to specify fzf executable path. Do you know how?

@ghost
Copy link
Author

ghost commented Oct 28, 2017

Thanks all for your supports. I'll stop working on this.
Hope the double enter, double esc issues will be addressed soon.

@ghost ghost reopened this Oct 28, 2017
@ghost ghost closed this as completed Oct 28, 2017
@ghost
Copy link
Author

ghost commented Oct 28, 2017

Last update about blinking cursor, refer here, quick: open menu --> type blink rate change to none.

@ghost
Copy link
Author

ghost commented Oct 28, 2017

just re-install git for window , it will automatically set TERM in environment variables.

@janlazo
Copy link
Contributor

janlazo commented Oct 29, 2017

But I don't know how to specify fzf executable path. Do you know how?

This should work in cmd.exe and powershell.

where.exe fzf

just re-install git for window , it will automatically set TERM in environment variables.

I use that to install git although I use the zip instead and configure it PATH locally via my powershell profile. Only git-bash should set TERM only because of mintty. bash itself uses TERM=cygwin which should be harmless. git-cmd doesn't set TERM although, if the installer did set TERM, then that's a recent change or specific to Win 10.

@ghost
Copy link
Author

ghost commented Oct 29, 2017

where.exe fzf

I mean that we can set fzf executable file to proxy .bat file that redirect it to fzf inside WSL bash -c 'fzf'
So if we have this option we can use fzf from WSL instead of fzf on windows.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants