How do I start Notepad++ from cmd?

96

36

I can start the regular Notepad from cmd.

C:\Windows>notepad

I can also start it from the run prompt.

  1. Win+R
  2. notepad
  3. Enter

I want to be able to do the same with the Notepad++. I can start it from the run prompt, but I can't start it from cmd.

I can also open a specific file in Notepad from cmd.

C:\Windows>notepad d:\mytext.txt

I want to be able to do the same with Notepad++.

Is this possible, and what can I do to enable this?

Samir

Posted 2013-06-13T21:08:26.037

Reputation: 17 919

1In Windows Vista, Windows 7, 8you can you can use start menu search box like run command. No need to press Win+R. Press Win and type in search box. Try it! – Kamil – 2014-08-26T00:25:16.250

(Not enough rep to answer). If you want to open a file whose extension is associated to NotePad++, just type the full filename: d:\mytext.txt and it will be open in the default app. You cannot pass CL arguments, but quick enough if you just want to open the file – cbuchart – 2018-11-19T11:30:13.750

Answers

68

You could add C:\Program Files (x86)\Notepad++ to your PATH environment variable.

For example, you could run the following on the command prompt:

set PATH=%PATH%;C:\Program Files (x86)\Notepad++

For further options, see What are PATH and other environment variables, and how can I set or use them?

Der Hochstapler

Posted 2013-06-13T21:08:26.037

Reputation: 77 228

Thanks! It works now. Now I can do notepad++ %userprofile%\desktop\testfile.txt which is nice. I used the Environment Variables dialog box for this. What's the syntax for removing an environment variable using the set command? I couldn't find any specific switches or syntax for this. Not on the link you provided and not on the Computer Hope website. – Samir – 2013-06-13T21:24:42.817

1@Sammy: Removing a single directory from the PATH variable is best done through the GUI, I assume. I don't know how to quickly remove it from the command line. If you want to completely remove an environment variable, you can use set something=, but I wouldn't advise you to do that for PATH. – Der Hochstapler – 2013-06-13T21:26:46.663

I found a path command. I understand I'm supposed to use semi colon to delete a path in the PATH variable?... I'm not sure how.

– Samir – 2013-06-13T21:32:07.580

Using path ; clears the search path settings for the current instance of cmd. It doesn't actually remove the search paths from the PATH variable. By opening a new cmd window the search path settings are restored. Oh well, I guess I will use the GUI then. – Samir – 2013-06-13T21:47:42.360

5

This is worth noting: "Changes made with SET will remain only for the duration of the current CMD session." This can be found here. And it says that Set command is used to display, set, or remove CMD environment variables. So Set command can be used to remove the whole variable, in this example the PATH variable. And again, it will not be permanently removed from Windows. It is only valid for the duration of the CMD session. To permanently set an environment variable from CMD, the Setx command should be used instead. Either that or GUI.

– Samir – 2013-06-13T22:09:38.930

Lots of good info here, thanks @Sammy and Oliver Salzburg – David – 2013-06-18T16:15:51.790

@Jikag You're welcome. I'm glad you found it useful. – Samir – 2013-06-18T20:24:53.917

131

Even though the Notepad++ directory is not in your path, you can use the command below to run the program from the command prompt:

start notepad++

To open a file in Notepad++, run:

start notepad++ <filename>

sudha jallu

Posted 2013-06-13T21:08:26.037

Reputation: 1 311

9Not only this answers the original question, this is a very clever workaround that works immediately without having to setup anything. Worked great for me. – Sergio Acosta – 2014-11-27T17:53:06.993

12Love it. Adding everything to the PATH is a horrible solution on windows. What isn't clear is where START searches to find possible commands if it isn't the path. Is it looking through the stuff installed in the start menu? – user10550 – 2014-12-16T14:36:24.937

and it works also if you are in a cygwin shell: cygstart notepad++ – laika – 2016-02-17T17:03:01.267

1Awesome! I use this after search some string with findstr /spim /c:"SomeString" *.*. – Paul Vargas – 2016-03-22T21:02:31.343

@user10550 I'm pretty sure Start references stuff in Libraries C:\Users\username\AppData\Roaming\Microsoft\Windows where as the $PATH variable is much different. You can actually specify what Start -> search references. More Detail

– Kolob Canyon – 2016-09-30T15:06:46.483

this should be the accepted answer, every now and then, why touch the PATH variable – computingfreak – 2016-11-16T05:26:31.730

20

I would not want to clutter my PATH just for using a single tool.

One alternative is to use an alternative text editor as 100% replacement for Notepad as explained here with many details. Another description with a dedicated editor launcher tool can be found here. Another Notepad++ launcher on github.

A less invasive alternative is a cmd file like this:

"C:\Programme\Notepad++\notepad++.exe" %*

This file has to reside somewhere along the existing PATH. I actually put all my tools in one common UTIL directory, which is part of PATH.

Axel Kemper

Posted 2013-06-13T21:08:26.037

Reputation: 2 892

Please note that in PowerShell the syntax for updating the PATH Environment Variable is a little different http://stackoverflow.com/a/1333717/47226

– Aaron Hoffman – 2015-06-28T16:00:11.300

1It looks like your link to the article on how to replace Notepad is broken already. – RobH – 2018-02-02T21:38:23.687

@RobH: Thanks for the hint. Is the fix ok for you? – Axel Kemper – 2018-02-02T21:52:13.000

That one works. (Of course, according to that article, the techniques that it describes don't work for Notepad++ due to how sophisticated it has become.) – RobH – 2018-02-02T22:08:12.223

@RobH: I keep trying to make my readers happy. Do you have links which I should include? – Axel Kemper – 2018-02-02T22:12:39.110

Nope. I was merely pointing out something that I noticed in the article. – RobH – 2018-02-08T19:34:45.407

What do you mean by "cmd file"? And what's with the asterisk and the percent sign? What file has to reside "along" the PATH? (It's not like it's going somewhere.) How do you make use of UTIL? Last time I checked there is no variable called UTIL. Is this something you came up yourself and added manually to the system? Can you explain any of this? And maybe give me some concrete example I can work with and hopefully learn from? Or are you just here to brag about how you know command line? I don't mean to be rude or anything, I'm just saying how it is. We all have different skill levels. – Samir – 2013-06-14T15:33:12.250

2A cmd file could be the text script file npp.cmd which has the command as single text line inside. If you create a directory c:\util and put the script file into it, extend your PATH by c:\util, you from then on can call Notepad++ by typing "npp". %* stands for "all commandline arguments". – Axel Kemper – 2013-06-14T17:41:54.797

1A cmd file is often called a "batch file". In the days of MS-DOS, the extension was always .BAT but these days it is often .cmd. The commands in the file are executed by cmd.exe which is the command-line shell itself. – steveha – 2013-10-23T07:04:57.347

8

This is what I have done, in this way you dont have to type notepad++ Create np.bat file with this set of commands

@echo off
start "" "C:\Program Files (x86)\Notepad++\notepad++.exe" %*

place np.bat file in c:\Windows

open the command prompt and type np or np myfile.txt and enter.

Nayana Adassuriya

Posted 2013-06-13T21:08:26.037

Reputation: 203

Using start "" to prefix the command here prevents locking up the command prompt if a notepad++.exe is not already running. – Jeremy Murray – 2018-11-06T21:26:06.760

i created an 'edit.bat' file with the contents : 'start notepad++ %1' - does just what i need to edit in the context of a cmd session. – theRiley – 2019-04-18T19:59:26.180

7

Combining the answers from Axel Kemper and adding some extra's, here is what I did to make a permanent command that you can give any name you want.

First of all I created an extra folder. In my case: "C:\Users\Hansel\CmdFiles". In this folder I created a new text file throught the right click menu -> new -> text document. Edit the text document using notepad or notepad++ and type the following code in the .txt file:

@echo off
"C:\Software\Notepad++\notepad++.exe" %*

Then you have to rename the file to your personal command, for example "npp.cmd".

On a side note: the @echo off prevents the command from printing to the command prompt;

the link between the quotation marks can refer to any executable;

*%** will make sure that anything you type after the npp command (for example "npp nonsense.txt") will be put after the original command in the quotation marks.

Then you need to edit an "environment variable", in this case the so called PATH (this variable contains the folders where Windows looks for commands and executables). To add the folder to your PATH, push the windows button to enter the start menu and type "edit environment variables for your account". Under "User variables for Hansel", create a new "Path" variable if it does not exist or edit the old "Path" variable if there is one.

If you make a new PATH variable, the variable value should just read: C:\Users\Hans\CmdFiles

If you edit an old PATH variable, the variable value should read: oldstuff;C:\Users\Hans\CmdFiles (mind the semi colon).

Windows now looks for commands in the folder "C:\Users\Hansel\CmdFiles" and you can easily add new commands to this folder!

Hansel

Posted 2013-06-13T21:08:26.037

Reputation: 104

8You don't need @ECHO OFF for a one-line command. The @ suppresses echo for that line alone, so @"C:\Software\Notepad++\notepad++.exe" %* does what you want. – Clement Cherlin – 2015-04-15T17:16:58.683

3

A simple way to run any program installed on Windows from command is:

  1. Find the location of notepad++.exe, create a shortcut under the installation directory.

  2. cut and paste the shortcut to C:/windows/system 32.

  3. Now you can press 'Win + R' and type the name of shortcut. All done.

PS: in my case, I named the shortcut 'notepadpp' (or even 'nppp') so that I don't have to press 'shift + =' twice for '+' symbol

Extremely simple and easy, and it's easy to delete the shortcut. You don't even need to change the path, registry

A kindheart Internet user

Posted 2013-06-13T21:08:26.037

Reputation: 31

2

To run any program from command line with a short name you can create an alias for it by the command doskey:

doskey alias="drive:\path to program\executable" $*

For example, after running command
doskey notepad++="C:\Program Files (x86)\Notepad++\notepad++.exe" $*
you can open the text file with notepad++ by notepad++ textfile. Of course, you can use shorter alias something as npp or n++.

Also you can create alias for some path you often open:

doskey home=cd C:\Users\myprofile

But unfortunately you cannot use this alias in path. If you run doskey home=C:\Users\myprofile and then enter in the command line cd home or start home\myfile you receive error message.

To create your aliases automatically each time when cmd runs you can put its into the batch file like autorun.cmd and set it in the registry entry:

HKCU\Software\Microsoft\Command Processor\AutoRun

or

HKLM\Software\Microsoft\Command Processor\AutoRun

Links to the articles:
Console Aliases
Command Processor\AutoRun

almaceleste

Posted 2013-06-13T21:08:26.037

Reputation: 53

2

One way is to make a change to this registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Notepad++.exe]

You can download a zipped .reg file from Donn Felker that lets you open a file with just an n shortcut.

I edited the .reg before running it and to make sure the path to Notepad++ is correct (e.g. C:\Program Files (x86)) and I also changed the shortcut to n instead of n.

Then double click to add to your registry.

Hugo

Posted 2013-06-13T21:08:26.037

Reputation: 2 640

1

Add the program directory to your PATH.

Oesor

Posted 2013-06-13T21:08:26.037

Reputation: 300

0

In PowerShell:

$ENV:Path="$ENV:Path;C:\Program Files (x86)\Notepad++"

Raúl Salinas-Monteagudo

Posted 2013-06-13T21:08:26.037

Reputation: 1 058