Invoking notepad++ from Git Bash

后端 未结 14 2258
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 16:01

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.t

相关标签:
14条回答
  • 2021-01-31 16:22

    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.

    0 讨论(0)
  • 2021-01-31 16:22

    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.

    0 讨论(0)
  • 2021-01-31 16:22

    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)

    0 讨论(0)
  • 2021-01-31 16:24

    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)'
    0 讨论(0)
  • 2021-01-31 16:27

    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...

    0 讨论(0)
  • 2021-01-31 16:28

    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]
    
    0 讨论(0)
提交回复
热议问题