127

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?

3
  • 1
    In 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
    Aug 26, 2014 at 0:25
  • 1
    (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
    Nov 19, 2018 at 11:30
  • You should check the answer from sudha jallu below, that one should be accepted as the answer for your question.
    – Long
    Jan 14, 2021 at 4:53

11 Answers 11

84

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?

7
  • 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
    Jun 13, 2013 at 21:24
  • 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. Jun 13, 2013 at 21:26
  • 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
    Jun 13, 2013 at 21:32
  • 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
    Jun 13, 2013 at 21:47
  • 7
    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
    Jun 13, 2013 at 22:09
185

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>
8
  • 16
    Not only this answers the original question, this is a very clever workaround that works immediately without having to setup anything. Worked great for me. Nov 27, 2014 at 17:53
  • 18
    Love 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
    Dec 16, 2014 at 14:36
  • 1
    Awesome! I use this after search some string with findstr /spim /c:"SomeString" *.*. Mar 22, 2016 at 21:02
  • 4
    this should be the accepted answer, every now and then, why touch the PATH variable Nov 16, 2016 at 5:26
  • 3
    This should be the accepted answer. I hope the OP read this.
    – Long
    Jan 14, 2021 at 4:51
21

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.

9
  • 1
    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
    Jun 14, 2013 at 15:33
  • 3
    A 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". Jun 14, 2013 at 17:41
  • 2
    A 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
    Oct 23, 2013 at 7:04
  • Please note that in PowerShell the syntax for updating the PATH Environment Variable is a little different stackoverflow.com/a/1333717/47226 Jun 28, 2015 at 16:00
  • 1
    It looks like your link to the article on how to replace Notepad is broken already.
    – RobH
    Feb 2, 2018 at 21:38
13

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.

2
  • 2
    Using start "" to prefix the command here prevents locking up the command prompt if a notepad++.exe is not already running. Nov 6, 2018 at 21:26
  • 1
    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
    Apr 18, 2019 at 19:59
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!

1
  • 9
    You 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. Apr 15, 2015 at 17:16
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

1
  • why nppp and not npp? you could type a p less every time Nov 30, 2022 at 9:56
2

Add the program directory to your PATH.

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.

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

2
  • doskey alias is not remembered after the current command prompt session is closed. Can you confirm? Mar 24, 2021 at 19:04
  • @NotepadPlusPlusPRO, as long as I remember - yes, doskey alias is not remembered. but you can add it to the autorun.cmd file, and it'll be created every time you run terminal. this is how it worked when I wrote this post. but now I have been using Linux for a long time and don't know if this behavior persists on Windows. Mar 24, 2021 at 23:09
0

In PowerShell:

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

Notepad++ has quite a cult following. And those people who like what Notepad++ can do will likely be frequent users of this program. So it only makes sense for these people to want easy access to Notepad++ ... and put Notepad++ on the system Path.

And these are likely the same people who would want a script to start notepad++ with a keyboard shortcut:

^q::run "Notepad++.exe"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .