30

How do I write a custom command to open files with Notepad++ text editor in Windows Command prompt.

For eg.

C:\Sites>ntp abc.txt

opens the file abc.txt in Notepad++

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Prakhar
  • 3,486
  • 17
  • 44
  • 61

6 Answers6

38

Create a batch file containing this line

@START c:\Program Files\Notepad++\notepad++.exe "%1"

and put it into some directory that is in your PATH list (or, alternatively, add a directory with a .bat file to PATH).

Kaerber
  • 1,623
  • 16
  • 21
  • This opens the file passed as argument in Notepad and not in Notepad++ – Prakhar Mar 03 '11 at 14:25
  • Is it possible to set this command as the default program for files of the type `.txt`? – Anderson Green Dec 28 '12 at 01:47
  • 1
    I think you can use the Open With dialog, browse to the bat file, select it, and set the checkbox "Always use". – Kaerber Jan 20 '16 at 14:41
  • what if there are two batch file with same name but at different directory and path to both batch file are added to the PATH list – Bibek Ghimire Jul 22 '17 at 07:25
  • 1
    Well, the obvious choice would be to rename one of the files. Or you can create another command, with a different name, leading to one of the files, listing the full path. – Kaerber Jul 25 '17 at 11:32
  • @BibekGhimire In that case I think the first occurrence of the batch path in your PATH will win. – Henrik Oct 18 '20 at 00:29
15

You can use doskey. Try:

doskey ntp=notepadpp.exe

and now you can do simply:

ntp blah.txt

tenfour
  • 36,141
  • 15
  • 83
  • 142
  • 7
    I use this: doskey ntp="C:\Program Files\Notepad++\notepad++.exe" $* – Sam Mackrill Sep 06 '11 at 10:28
  • 11
    Well.. the commands is only stored in memory, so when you close the console you loose your commands. – Automatico Feb 03 '13 at 20:28
  • 1
    I liked this answer but then I read @Cort3z comment and then was disappointed. Is there any way that you can have cmd save that command? – krummens Jun 15 '17 at 16:26
  • i like this answer more than the accepted answer, because it is simpler. I don't want two have to create a file and add it to the %PATH%. – Makan Aug 21 '20 at 17:04
9

Create a .bat file and save it as npt.bat

In that file put the following line of code (or change it to match the path to your notepad++.exe))

@START c:\"Program Files (x86)"\Notepad++\notepad++.exe "%1"

Note that you need quotation marks around any parts of the path with spaces in it.

Now place it in whatever directory you like and add the directory to PATH in your User variables.

Learning2Code
  • 91
  • 1
  • 1
5

You can also create a bat file which does what you wish (mentioned in other answers here), then put it in C:\Windows\System32.

Execute it by writing the name of the file. For example ntp if your file was named ntp.bat

Make sure that you restart the command line before trying your new super cool custom command.

Coco
  • 826
  • 1
  • 12
  • 20
1

In addition to the answer of @Kaerber

This works for me

@START c:\"Program Files"\Notepad++\notepad++.exe "%1"

While this doesn't work (and just opens the explorer)

@START "c:\Program Files\Notepad++\notepad++.exe" "%1"
SoliQuiD
  • 2,093
  • 1
  • 25
  • 29
1

suppose we use 3 different versions of python and want to refer to each as commands like:

python36 -m pip install numpy python38 -m pip list python310 --version

just create a file called "python36.cmd" and write this one line in it

"C:\Program Files\Python36\python.exe" %*

and put it in a directory that is already in the PATH. If you use VSCode then its bin directory will already be in PATH variable. so put the python36.cmd file there.