Invoking notepad++ from Git Bash
Asked Answered
B

15

52

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.

Blocked answered 8/3, 2013 at 16:29 Comment(2)
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++'.Parapodium
@ColonelPanic #893055Seductive
B
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!

Borsch answered 13/5, 2013 at 22:32 Comment(5)
Wow, this is a game-changer! So good! I used: alias open="/c/Program\ Files\/Notepad++/notepad++.exe"Tersanctus
Are you sure with it? It still says me that command not found.Chesney
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.Manoff
@JoshGust or you can source it. (`source ~/.bashrc')Disrespectful
Notepad++ is now available for both, 32 bit and 64 bit Windows. So the second snippet will also work in 64 OS.Implausible
R
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!

Rainmaker answered 16/11, 2016 at 5:40 Comment(0)
I
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]
Injun answered 11/1, 2016 at 3:50 Comment(2)
think it ahs to be added to this file .bashrc?Rollet
Newer versions of Notepadd++ are natively build for 64-bit systems, so by default it installs to "/c/Program\ Files/Notepad++/notepad++.exe"Babi
H
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.

Hexarchy answered 8/3, 2013 at 16:41 Comment(2)
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 applicationBorsch
you can also use single quotes around double quotes so : alias np='"C:\Program Files (x86)\Notepad++\notepad++.exe"'Delitescence
I
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!

Informal answered 14/4, 2015 at 19:28 Comment(0)
P
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.

Placido answered 28/2, 2017 at 15:39 Comment(1)
I would add to @Amgad's answer that you'll probably have to add escape characters around the parentheses as well!Euroclydon
A
2
  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

Astto answered 3/4, 2020 at 10:46 Comment(2)
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 extensionPriebe
Thanks. I needed to add --replace-all in point 1, which solved my issue.Cultch
H
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)'
Hilly answered 30/10, 2016 at 20:33 Comment(0)
K
1

In your .bash profile add

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

Give "\\" instead of "\".

Kilo answered 29/1, 2017 at 14:8 Comment(0)
P
0

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

$ which notepad++
/c/Program Files (x86)/Notepad++/notepad++
Parapodium answered 8/3, 2013 at 17:3 Comment(1)
@Andi Then notepad++ isn't in the PATH used by the git shell. How did you add it to your path?Dapsang
E
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)

Elwira answered 13/4, 2017 at 11:21 Comment(0)
N
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...

Nestor answered 8/7, 2019 at 2:1 Comment(0)
C
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
Cloven answered 20/8, 2022 at 14:52 Comment(0)
E
-1

In your git bash just add:

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

I hope this works.

Eclogite answered 6/8, 2019 at 5:55 Comment(0)
D
-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.

Dapsang answered 11/3, 2013 at 3:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.