Launching notepad as a text editor in PowerShell is ' notepad README.txt ' but if I wish to use a different text editor (due to some obvious limitations to notepad) such as Notepad++ , How would this be accomplished?
PowerShell launching alternative text editor
445 views Asked by Jonathan Kellermann At
2
There are 2 answers
0
On
Adding to above answer by @Kieth , I usually do the below to open a text file :
Invoke-Item C:\temp\test.txt
But the problem with this approach is by default .txt extension is associated to be opened by notepad.exe
One can set the default editor for a specific type (e.g .txt) type of files via the Explorer, CMD or PowerShell
Via Explorer
Right click on .txt file > Open With > Choose Default program > select Editor of choice.
Via PowerShell/ CMD
One can use the command line utility named assoc and ftype together for mapping the extension to a default program. First run assoc to get the file association
PS> cmd /c assoc .txt
.txt=txtfile
Now we can set the default application (open commandstrings) for that filetype association.
PS>cmd /c Ftype txtfile"C:\Program Files\Sublime Text 3\sublime_text.exe" %1
Once the file associations are made. Simply do the below:
PS> ii C:\Temp\test.txt # ii alias for Invoke-Item
It depends on whether Notepad++ is in your path or not. If it is in your path then just execute:
Be aware that if you are in the same dir as notepad++ you must execute it like so (security feature):
If not then you need to specify the path to notepad++ e.g.:
If you do this a lot you may want to create an alias in your profile script e.g.:
Use whatever you want for the alias: ed, edit, etc.