0

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?

2 Answers 2

2

It depends on whether Notepad++ is in your path or not. If it is in your path then just execute:

notepad++ readme.txt

Be aware that if you are in the same dir as notepad++ you must execute it like so (security feature):

.\notepad++ readme.txt

If not then you need to specify the path to notepad++ e.g.:

& 'C:\Program Files (x86)\Notepad++\notepad++.exe' readme.txt

If you do this a lot you may want to create an alias in your profile script e.g.:

New-Alias e 'C:\Program Files (x86)\Notepad++\notepad++.exe'
e readme.txt

Use whatever you want for the alias: ed, edit, etc.

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.