Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Got it

Thanks for sharing your findings!
Kacy_Stocks

Got it

See the above steps – but replace the script used above with this:
$file=$args[0]
$file=$file.replace('\', '/')
$file=$file.replace('"', '')
$file=$file.replace('C:', '/mnt/c')
 
C:\Windows\System32\wsl.exe -u root sh -c "/usr/local/bin/nvim --server localhost:6666 --remote $file"

You can also use Python:
import subprocess

import sys

file = sys.argv[1]
print(f"\nfile begin: {file}")
file = file.replace('\\', '/')
file = file.replace('"', '')
file = file.replace('C:', '/mnt/c')
print(f"\nfile end: {file}\n")

subprocess.check_output(f"C:\\Windows\\System32\\wsl.exe -u root sh -c \"/usr/local/bin/nvim --server localhost:6666 --remote {file}\"")

With the WinSCP editor:
python.exe "C:\tools\wsl_nvim.py" !.!
Kacy_Stocks

Update

First I had to install PowerShell 7 for this to work.

Turn on Neovim's headless server:
nvim -n --headless --listen localhost:6666 &

For the Window's side, I used Neovide to house Nvim:
neovide.exe --server localhost:6666

Install from releases on GitHub somewhere on your Windows Path:
https://github.com/neovide/neovide

In WinSCP's External Editor:
pwsh.exe -ExecutionPolicy Bypass -File "C:\tools\ps_wsl_nvim.ps1" !.!

Here's the script I pieced together:
Set-Variable "nvim_path=/usr/local/bin/nvim"
Set-Variable "file=%~1"
 
# rem Replace backslashes with forward slashes and remove quotes
Set-Variable "file=%file:\=/%"
Set-Variable "file=%file:\=%"
 
# rem Extract the drive letter and the path
Set-Variable "drive=%file:~0,1%"
Set-Variable "path=%file:~2%"
 
# rem Combine them into the WSL path format
Set-Variable "wsl_path=/mnt/c%path%"
 
C:\Windows\System32\wsl.exe -u root sh -c "/usr/local/bin/nvim --server localhost:6666 --remote \"%wsl_path%\""

Saved this at C:\tools\ps_wsl_nvim.ps1

I opens up a new buffer in WSL's neovim so far – how do I get it to open up the expected file?
K_Le

Re: How wsl calls from powershell work

@Kacy_Stocks: I'd love to know how to do this as well!
Kacy_Stocks

How wsl calls from powershell work

By running the following command in PS – it opens the file on WSL's Neovim:
wsl nvim --server localhost:6666 --remote <file>
Kacy_Stocks

WinSCP Call WSL Application as Editor

I've been trying for a few hours to figure out how to use Neovim (for example) from within WSL via the external editor features in WinSCP.
Does anyone have a method to get this working?
So far I've tried:
powershell.exe -ExecutionPolicy Bypass "C:\tools\ps_wsl_nvim.ps1" !.!

With the script:
& "wsl.exe nvim --server localhost:6666 --remote"

I've also tried:
wsl.exe nvim --server localhost:6666 --remote !.!

and
<wslpath>wsl.exe nvim --server localhost:6666 --remote !.!

and
powershell.exe -ExecutionPolicy Bypass "wsl.exe nvim --server localhost:6666 --remote" /mnt/c/!.!

etc...