68

How can I open up a file in Notepad++ from the Powershell command line?

2
  • 2
    @martineau: Actually this question is quite helpful for opening any file in Notepad++ from PowerShell. Just sayin.. Commented Apr 14, 2015 at 15:03
  • 1
    Can we just edit this canonical question to not be Python specific? It has nothing to do with python... Commented Oct 3, 2016 at 19:48

8 Answers 8

108

Inside PowerShell I can simply use the start and get general results

to open a python file with notepad++ here is what I did.

Start notepad++ ex1.py

this will start notepad++ and load the file ex1.py assuming you are in the same directory as the .py file. You can change that by adding the full path name

start notepad++ c:\users\you\desktop\files\ex1.py
Sign up to request clarification or add additional context in comments.

4 Comments

In the greater scope Start opens any .exe program with any argument.
Any idea how to pipe it if the file is too big? I tried: Get-Content "ids_2020-02-01.jsonl" -Tail 100 | Start notepad++ to no avail
You can open a directory as workspace using notepad++ -openFoldersAsWorkspace . (This will open the current directory as workspace.. Replace . with the path to the another directory if you want)
to pass multiple arguments to notepad++, you have to use an array for the 2nd argument of Start: start notepad++ "c:\users\you\desktop\files\ex1.py","-n100" (open ex1.py on line number 100) -- OR -- more explicitly: start notepad++ @("c:\users\you\desktop\files\ex1.py","-n100")
7

Because the default path contains spaces, you have to quote the path to the exe. However because PowerShell is also a scripting language. A string by itself is simply evaluated as a string e.g.:

C:\ PS> 'Hello world'
Hello world

So you have to tell PowerShell you want to invoke the command that is named by the string. For that you use the call operator & e.g.:

C:\ PS> & 'C:\Program Files (x86)\Notepad++\notepad++.exe'

or if notepad++ is in your path:

  C:\ PS> notepad++

or if you're in the same dir as the exe:

  C:\ PS> .\notepad++

1 Comment

ALright. Say I have some py files in a directory. How can I open them in Notepad++ from PowerShell?
4

Edit your profile and add an alias

Set-Alias -name 'npp' -value 'C:\Program Files\Notepad++\notepad++.exe'

Then:

npp c:\temp\test.txt

Edit your profile:

npp $profile

etc

Comments

3

To extrapolate on the previous answers and tie them up in a tidy bow: If you want to open a file with spaces in the path or name:

. 'C:\Program Files (x86)\Notepad++\notepad++.exe' 'C:\Temp\File With Spaces.txt' 

or

& 'C:\Program Files (x86)\Notepad++\notepad++.exe' 'C:\Temp\File With Spaces.txt'

It can also be set it as an alias:

Set-Alias -Value 'C:\Program Files (x86)\Notepad++\notepad++.exe' -Name 'NotePad'
$FileWithSpaces = 'C:\T e m p\File With Spaces.txt'
NotePad $FileWithSpaces

The top line here can be copied into (one of) your $Profile .ps1 file(s) so you don't need to keep using Set-Alias in every new PS instance.

2 Comments

What if I have a filename in $variable? It doesn't seem to work the same way
I'm not entirely sure I understand the question, but this may go some way to answer it. $FileWithSpaces = 'C:\Temp\File With' $Spaces = ' Spaces.txt' . 'C:\Program Files (x86)\Notepad++\notepad++.exe' $FileWithSpaces$Spaces
3

To open Notepad++ with and create a new empty file in the current path

start notepad++ newFile.txt

To open Notepad++ with an existing file

start notepad++ apples.txt

To specify the path and open multiple files

start notepad++ fruits/apples.txt, fruits/oranges.txt, package.json

Comments

0

I know this is an old question, but I found a bit of a workaround, quite by accident, and it is extremely straightforward. If you install and maintain Notepad++ via Chocolatey (think apt-get for Windows, but built on top of NuGet), then you get a shim that can be invoked from the command line.

cinst notepad++

And even if you already have an existing installation of Notepad, you can still "install" it from Chocolatey, and it will pull in the existing installation and maintain it.

I use Chocolatey for as much as I possibly can, because you can update everything in one fell swoop.

After that, editing things from PowerShell is a snap. Like my PowerShell profile:

notepad++ $PROFILE

Hope this helps someone, or several someones!

Comments

0

In my case, I wanted to start Notepad++ with a file as an argument, and open as admin. I wanted to open one of the PowerShell profiles. I had to use the following command variation:

start-process -Verb runas -filepath "C:\Program Files (x86)\Notepad++\notepad++.exe"  "`"$($PROFILE.AllUsersAllHosts)`""

All the other variations didn't work, I think due to a space in the path of the file to be opened. So, you must escape the " as:

"He said `"This is fun.`""

Comments

0

To pass multiple arguments to Notepad++, you have to use an array for the 2nd argument of Start:

Start notepad++ "C:\Users\user\Documents\PS Scripts\script.ps1","-n100"

More explicitly:

Start notepad++ @("C:\Users\user\Documents\PS Scripts\script.ps1","-n100")

Which is equivalent to typing this in a command line directly:

notepad++ "C:\Users\user\Documents\PS Scripts\script.ps1" -n100

This will open script.ps1 file on Line Number 100.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.