7

I use WSL (Windows Subsystem for Linux) with Debian, which provides a simple cmd interface. I'd like to open files in Notepad++, which is installed on the Windows side of this PC.

is this possible? if not, suggest an editor more robust and accessible than Nano.

4

5 Answers 5

7

I use notepad++ with my WSL (ubuntu) as the default editor for both Windows and Linux and have setup so that it is launched from both contexts for files under either filesystem.

My setup:

Launching Notepad++

Linux

Set up an alias as follows:

alias npp="/mnt/c/Program Files/Notepad++/Notepad++.exe"

Now I can launch as npp [filename]

Windows

Add the notepad.exe to your PATH.

  1. From start menu; choose edit environment settings

Show environment settings menu

  1. Choose environment variables:

environment variables

  1. Add to the path variable the location of Notepad++. Unless you've changed defaults; it would be in:
C:\Program Files (x86)\Notepad++

Now you can launch notepad++ from any folder.

Editing Windows Files

From windows

With the path set; you can do the usual windows:

notepad++ foo.txt

From linux

These can be accessed via the /mnt mountpoints, so you would do:

npp /mnt/c/Temp/foo.txt

Linux Files

From Windows

These can be accessed via the so-called P9 filesystem WSL provides, so you would do:

Notepad++.exe \\wsl$\Ubuntu-18.04\home\user\foo.txt

(remember to rename for your WSL distro)

From Linux

With the alias set; you can do

$ npp foo.txt
1
  • 1
    Upvoted because it actually mentions \\wsl$
    – Magua
    Jul 20, 2023 at 21:57
2

You can edit files on the Windows side (C:\xxx) and access them from Debian (/mnt/c/xxx), that's no problem. You can even start Notepad++ from bash which opens in Windows as usual, but as you can't edit any linux files that doesn't make any sense.

So in order to edit files of your linux filesystem you will have to copy them to a shared windows directory /mnt/c/whatever first, edit them there and copy them back afterwards.

Another possibility would be to install samba on linux and mount your work-directories in Windows. The other way around accessing a Windows share using smbclient is also possible, but no fun using commandline linux, already tried that. You are faster copying your files.

Or you use emacs, vim, ...

1
  • 1
    "you can't edit any linux files that doesn't make any sense" It would make perfect sense to be able to edit files in either context from the other. But editing WSL files from Windows is forbidden when using WSL so can't be done. (Try Cygwin for an alternative environment where it's completely and naturally possible to share files, even.) Feb 15, 2019 at 9:05
1

You can use the Snap package and install Notepad++ in Linux without installing Wine. There's also a review of five alternatives not mentioned above.

However, all require a GUI, which WSL does not include. I'd suggest you review your options in this article before selecting a GUI and adding graphical applications.

1
1

@Colin

Quick answer to your initial question:

$ /mnt/c/Program\ Files/Notepad++/Notepad++.exe "useful.txt"

That should do it

However, despite the possibility of invoking win binaries from wsl.exe, your approach appears to be super-complicated.

I, personally, stick to nano/cat when working within WSL CLI.

But there's nothing better than Sublime Text with Terminus Package combo. Running bash/zsh on WSL inside a tab is fantastically convenient:

  1. eases up copy/pasting

  2. composing sh scripts like a boss (just remember to switch the .sh file to Unix Line Endings mode )

enter image description here

  1. super-easy sh debugging: modify the script and run it instantly enter image description here
  2. loads of other useful features and ways to handle WSL/Win interactions etc.
0

The way to do so is by using a network path:

\\wsl$\Ubuntu-20.04\home\youruser\.aws

Where Ubuntu-20.04 is the name of your WSL distribution and \home\youruser\.aws\config is an example of a path to a file you want to edit

1
  • 1
    Welcome to the site, and thank you for your contribution. Please note that this approach was already mentioned in the answer by Kelly Trinh. You may want to consider expanding your post so that the difference to that answer becomes more visible; otherwise it would be best placed as a comment to that answer (once you have sufficient reputation).
    – AdminBee
    Nov 17, 2022 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .