51

I am using msysgit in Windows 7. How do I invoke notepad++ from Git Bash, like we do it with our default notepad?

Like for example

name@usename notepad textfile.txt

Instead I want the file to open with notepad++.

Note : I've added notepad++ to my PATH, but still unable to invoke it from commandline.

Edit

I tried this in .gitconfig -->

[alias] notepad='C:/Program Files/Notepad++/notepad++.exe'

but isn't working.

peterh
  • 11,875
  • 18
  • 85
  • 108
  • It's tough to write an alias because of all the special characters needing escaping - the space in 'program files' the brackets in '(x86)' and the plus symbols in 'notepad++'. – Colonel Panic Mar 08 '13 at 17:04
  • 1
    @ColonelPanic https://stackoverflow.com/questions/892555/how-do-i-specify-c-program-files-without-a-space-in-it-for-programs-that-cant – Leponzo Dec 16 '21 at 17:21

15 Answers15

63

So, by default you won't have a .bashrc file so just navigate your to your home directory by typing:

cd ~

create or edit the .bashrc with vim (or whatever editor you are comfortable with):

vim .bashrc

Here is the line I had to add to mine (I am running a 64 bit OS so if you aren't don't copy this exactly)

alias notepad="/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"

If your copy of windows is 32 bit then it should look like this

alias notepad="/c/Program\ Files/Notepad++/notepad++.exe"

Finally, close and reopen your terminal/bash (or, as noted, run source ~/.bashrc), and voila!

wp78de
  • 18,207
  • 7
  • 43
  • 71
SageMage
  • 1,096
  • 8
  • 16
  • 2
    Wow, this is a game-changer! So good! I used: `alias open="/c/Program\ Files\/Notepad++/notepad++.exe"` – Ryan Jul 17 '17 at 16:14
  • Are you sure with it? It still says me that command not found. – Bartis Áron Sep 15 '17 at 13:56
  • 2
    If you haven't closed and reopened your bash client, it may not see the new addition. This gave me a headache for a while on some other scripting I was doing to open VS solutions. – Josh Gust Feb 06 '18 at 23:33
  • 2
    @JoshGust or you can `source` it. (`source ~/.bashrc') – aderchox Oct 29 '18 at 18:38
  • Notepad++ is now available for both, 32 bit and 64 bit Windows. So the second snippet will also work in 64 OS. – Wolf Jul 20 '23 at 11:35
46

these are the faster ways to achieve the goal

start notepad++ 
start notepad++ <filename>
alias np='start notepad++'
np <filename>

tried and tested, just do it!

computingfreak
  • 4,939
  • 1
  • 34
  • 51
6

I added this for my 64-bit machine with 32-bit Notepad++.

$ cd ~
$ vim .bash_profile

Add this to the file then save:

64-bit systems

alias npp="/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"

32-bit systems

alias npp="/c/Program\ Files/Notepad++/notepad++.exe"

Now you should be able to open any file with notepad++ by entering

$ npp [file_name]
HyperionX
  • 1,332
  • 2
  • 17
  • 31
5

I believe git-bash is an actual bash shell, so when it starts, it runs a .bashrc file from somewhere (most likely your home directory or the directory git-bash starts in). Look for that file, and when you find is, add an alias line somewhere for notepad++:

alias notepad="/c/Program\ Files/Notepad++/notepad++.exe"

Of course use your actual path to Notepad++ there.

Alex
  • 1,103
  • 1
  • 11
  • 24
  • all of this is correct but chances are he doesn't have a .bashrc file yet because he hasn't ever used it. Read my comment or create a .bashrc file in your users home directory and add the appropriate path to the application – SageMage May 13 '13 at 22:33
  • you can also use single quotes around double quotes so : alias np='"C:\Program Files (x86)\Notepad++\notepad++.exe"' – chrispepper1989 Sep 05 '18 at 10:33
4

@SageMage's answer is right on spot.

Just a reminder. You need to close and reopen GitBash after after you make a change in .bashrc in order for it to be activated.

PS: After two years, I hope this helped!

padawanTony
  • 1,348
  • 2
  • 22
  • 41
3

The below is listed on Udacity's course on Git and GitHub. It worked for me:

  1. Run the following command in Git Bash after checking the location of Notepad++ on your PC.

    echo 'alias npp="C:/Program\ Files\ \(x86\)/Notepad\+\+/notepad\+\+.exe"' >> ~/.bashrc
    

    Notice how I had to escape characters like the space and the brackets. You can escape any character if you're not sure whether it should be escaped or not. Also make sure to use the alias you want; I chose npp.

  2. Close and re-open Git Bash

  3. Type npp in Git Bash, if it opens then you're good to go. If not, try the below points:
  4. Test .bashrc by running the command below in Git Bash

    source ~/.bashrc
    
  5. Retry typing npp to start Notepad++. If Notepad++ doesn't start, check the contents of the file ~/.bashrc created in step 1.

  6. To ensure the .bashrc file contents are loaded each time you open Git Bash, edit ~/.bash_profile and add the following two lines. (Reference)

    if [ -r ~/.profile ]; then . ~/.profile; fi
    
    case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
    
  7. Close and re-open Git Bash. Type npp in Git Bash to check it starts correctly.

Michael
  • 8,362
  • 6
  • 61
  • 88
Amgad
  • 169
  • 2
  • 7
  • I would add to @Amgad's answer that you'll probably have to add escape characters around the parentheses as well! – bjpreisler Apr 11 '17 at 12:21
1

First of all, if you haven't created any .bashrc profile or .bash_profile create either of the one using vim or any other editor as others have mentioned

Or

In case you did not have any such editor which can work with git bash yet make one manually by opening a notepad or notepad++ editor and saving the file at the home directory.

Note: You can check your home directory by using

 cd ~

 pwd

My Notepad++ path is C:\Program Files\Notepad++\notepad++.exe

So for going to any directory to notepad++ directory, I have to go to root directory and then to the required path. So here is the line that I had to add to mine .bash_profile

alias note="//\/c/Program\ Files/Notepad++/notepad++.exe"

'//' takes it to the root directory

P.S.:

  • You may have to change the path depending on your target directory( notepad++ directory)
  • The "Program Files"directory should be written like 'Program\ Files'.
  • If your Notepad++ directory is in Program Files (x86) then use 'Program\ Files\ (x86)'
Shreyansh
  • 458
  • 4
  • 11
1

In your .bash profile add

alias myeditor="'C:\\Program Files (x86)\\Notepad++\\notepad++.exe'"

Give "\\" instead of "\".

Yumlembam Rahul
  • 151
  • 1
  • 8
1
  1. Open Git Bash on your system/project and type the following command in the Git Bash

    git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

  2. Press Enter and if no error occurs, you have successfully set up Notepad++ as your text editor in Git Bash. You can also check it by typing the command

    git config --global core.editor

enter image description here

Jayani Sumudini
  • 1,409
  • 2
  • 22
  • 29
  • You explained how to set up the core.editor (which is unnecessary), not how to open/invoke the app related to the file wanted to be opened from git bash, which is achieved by typing `start filename`, start will open the program associated to the file extension – FiruzzZ Aug 26 '20 at 12:30
0

I added the Notepad++ folder to my path, so I can just type notepad++

$ which notepad++
/c/Program Files (x86)/Notepad++/notepad++
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
0

This config works for me

editor = \"/c/Program Files (x86)/Notepad++/Notepad++.exe\" -multiInst

The multiInst argument is just to make it friendlier for interactive edits where you already have notepad++ open. (If Notepad++ is already open and you run the process again, it adds the file to your existing instance and then exits immediately, which git takes to mean you've finished)

Rob
  • 4,327
  • 6
  • 29
  • 55
0

I met the cannot find the command issue. I figured out that is because I was doing all those vim .bashrc under my working directory. It seems I have to do that under the Git Bash home directory...

cs95
  • 379,657
  • 97
  • 704
  • 746
Lou
  • 1
0

https://docs.github.com/en/get-started/getting-started-with-git/associating-text-editors-with-git

The section under "Using Notepad++ as your editor" provided the answer.

Run the following in Git Bash and you're away.

$ git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

If you want to open up the global git config file after setting up notepad++ use this:

$ git config --global -e
Dee
  • 69
  • 1
  • 10
-1

In your git bash just add:

alias npp='notepad++ -multiInst -nosession'

I hope this works.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Akshay Shenoy
  • 1,194
  • 8
  • 10
-2

An alias is used with the git command, so with the one in your OP, you should be able to run git notepad. I don't think this is quite what you want, though. If you correctly added notepad++ to your PATH variable, then you should be able to just do notepad++. You can check this by running which notepad++. If this doesn't give the full path to notepad++, then the PATH isn't set correctly.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268