kien / ctrlp.vim

Fuzzy file, buffer, mru, tag, etc finder.
kien.github.com/ctrlp.vim
7.26k stars 677 forks source link

How to use CtrlP in WSL (Windows Subsystem for Linux) #770

Open eduardoarandah opened 5 years ago

eduardoarandah commented 5 years ago

Hi!

I'm trying to use the new Windows Subsystem for Linux with gvim (windows 10, ubuntu console)

So far, all works great using this configuration:

set shell=C:\Windows\Sysnative\wsl.exe
set shellpipe=|
set shellredir=>
set shellcmdflag=--
set shellslash

Using that, I can do :!ls or any linux command and it works great.

Problem is, now CtrlP executes user command with wsl.

if you press Ctrl+p, nothing happens

This configuration doesn't work:

    let g:ctrlp_user_command = 'rg --files %s'
    let g:ctrlp_use_caching = 1
    let g:ctrlp_working_path_mode = 'ra'
    let g:ctrlp_switch_buffer = 'et'

BUT WAIT... this other configuration works!!

(all I did was adding any dummy command before, like pwd && )

    let g:ctrlp_user_command = 'pwd && rg --files %s'
    let g:ctrlp_use_caching = 1
    let g:ctrlp_working_path_mode = 'ra'
    let g:ctrlp_switch_buffer = 'et'

I have no idea how to debug that, I tried logging everything with: gvim -V9vimlog.txt but it doesn't tell me exactly what is happening when I click Ctrl + P

All I want is GVim to use the linux console in windows for everything, but I can't help myself to debug the commands run by CtrlP,

any ideas?

eduardoarandah commented 5 years ago

I've managed to list all files properly with this config:

let g:ctrlp_user_command = 'rg --files "`wslpath %s`"'

wslpath converts windows paths into linux paths

BUT when you open a file, it's opened with the "linux" path, so "/mnt/c/users/lalo/file.txt" is opened as "C:/mnt/c/users/lalo/file.txt" which is incorrect.

So... I guess there's two options:

1) given that I've changed the shell globally to use linux paths, open results with windows paths, executing wslpath function reversed, to transform it

2) not use WSL shell with ctrlp, instead of that, use native windows shell, ignoring global shell

A hint with why this config could be working: let g:ctrlp_user_command = 'pwd && rg --files %s'

MAYBE... pwd is executed with wsl shell and the second command is executed with native windows shell....