I am on Windows 10 but I am using Bash on Ubuntu on Windows (WSL) to familiarize myself with the Linux command line.
I am trying to take full advantage of its capabilities and was thinking it would be awesome to be able to open, say, index.html
from the CLI in Notepad++. Is this possible? If so, how would I go about setting it up?
I am pretty new to the command line in general, much less Linux commands.
It is absolutely possible to use Notepad++ in WSL. In fact, you can use it in precisely the same way as if working in a normal Windows environment.
You need to create a bash alias to allow for easier use of the following command:
<path_to_textEditor> <path_to_textfile>
To create an alias for Notepad++, do the following in WSL bash:
Open your
.bashrc
startup script (runs when bash is started):vim ~/.bashrc
Add the alias defintion to the script:
alias np='<path_to_textEditor>'
For Notepad++ it would be:
alias np='/mnt/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe'
You might have to adjust the path if you didn't install Notepad++ in the default directory.
Make sure to escape any special characters, like whitespaces, with the escape chatacter
\
(backslash).
Now, use it like you would normally:
To open Notepad++, do np
To open a specific file in Notepad++, do np <text_file>
As suggested by user @ericpeters, there are several useful Notepad++ startup options that you might want to add to your alias.
These startup options are appended to the end of the alias string and separated by whitespaces.
alias np='<path_to_textEditor> <startup_option_1> <startup_option_2> ...'
Here are some examples:
-multiInst
: Open an new Notepad++ instance that is separate from the currently opened Notepad++ session (if it exists).-nosession
: Don't load the previous session and don't save the session tosession.xml
.-notabbar
: Turn off the tab interface.
Here's an example with startup options:
alias np='/mnt/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe -multiInst -notabbar -nosession'
Personally, I have two separate aliases, one without startup options and one with the three startup options above. This allows me to choose if I want to:
- Quickly edit individual files when I don't want to use VIM (and return to the CLI when exiting). Useful for writing git commit messages.
- Open up files into my 'always open' standard Notepad++ session (with tabs).
I usually put all work files in Windows directory
/mnt/d/ubuntu/
Then in WSL Ubuntu shell, I create a symbolic link to the directory
ln -s /mnt/d/ubuntu ~/win
Whatever files I work with in WSL, I put them in this directory except for the linux specific files, which usually have no need to be opened with Windows applications.
Now, when you want to use Windows applications for the files, you simply browse the app to
D:/ubuntu/.../your/files
来源:https://stackoverflow.com/questions/40231568/is-there-a-way-to-open-files-with-notepad-in-bash-on-ubuntu-on-windows