windows 从 Git Bash 调用记事本++

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15298732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:20:14  来源:igfitidea点击:

Invoking notepad++ from Git Bash

windowscommand-linenotepad++msysgitgit-bash

提问by SageMage

Hi guys i'm using msysgitin Window 7. How do i invoke notepad++ from Git Bash like we do it with our default notepad. Like for example

大家好,我在 Window 7 中使用msysgit。我如何像使用默认记事本那样从 Git Bash 调用 notepad++。例如

name@usename notepad textfile.txt

name@usename 记事本 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.

注意:我已将 notepad++ 添加到我的 PATH,但仍然无法从命令行调用它。

Edit

编辑

I tried this in .gitconfig-->

我在.gitconfig--> 中试过这个

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

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

but isn't working.

但不工作。

回答by SageMage

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

因此,默认情况下您不会有 .bashrc 文件,因此只需键入以下内容导航到您的主目录:

cd ~

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

使用 vim(或任何您喜欢的编辑器)创建或编辑 .bashrc:

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)

这是我必须添加到我的行(我正在运行 64 位操作系统,所以如果你不是,请不要完全复制)

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

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

如果您的 Windows 副本是 32 位,那么它应该如下所示

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

回答by computingfreak

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!

尝试和测试,就去做吧!

回答by HyperionX

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

我为带有 32 位 Notepad++ 的 64 位机器添加了这个。

$ cd ~
$ vim .bash_profile

Add this to the file then save:

将此添加到文件中,然后保存:

64-bit systems

64 位系统

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

32-bit systems

32位系统

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

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

现在您应该可以通过输入来使用记事本++打开任何文件

$ npp [file_name]

回答by padawanTony

@SageMage's answer is right on spot.

@SageMage 的回答是正确的。

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.

只是提醒。在 .bashrc 中进行更改后,您需要关闭并重新打开 GitBash 才能激活它。

PS: After two years, I hope this helped!

PS:两年后,我希望这有帮助!

回答by Alex

I believe git-bash is an actual bash shell, so when it starts, it runs a .bashrcfile 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++:

我相信 git-bash 是一个真正的 bash shell,所以当它启动时,它会.bashrc从某个地方运行一个文件(很可能是你的主目录或 git-bash 开始的目录)。寻找那个文件,当你找到它时,在某处为记事本++添加一个别名行:

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

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

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

当然,在那里使用 Notepad++ 的实际路径。

回答by Jayani Sumudini

  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

  1. 在您的系统/项目上打开 Git Bash 并在 Git Bash 中键入以下命令

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

  2. 按 Enter 键,如果没有出现错误,则您已成功将 Notepad++ 设置为 Git Bash 中的文本编辑器。您也可以通过键入命令来检查它

    git config --global core.editor

enter image description here

在此处输入图片说明

回答by Amgad

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

下面列出了 Udacity在 Git 和 GitHub上的课程。它对我有用:

  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 nppin Git Bash, if it opens then you're good to go.If not, try the below points:
  4. Test .bashrcby running the command below in Git Bash

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

  6. To ensure the .bashrcfile contents are loaded each time you open Git Bash, edit ~/.bash_profileand 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 nppin Git Bash to check it starts correctly.

  1. 检查 PC 上 Notepad++ 的位置后,在 Git Bash 中运行以下命令。

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

    请注意我必须如何转义空格和括号等字符。如果您不确定是否应该转义,您可以转义任何字符。还要确保使用您想要的别名;我选择了npp

  2. 关闭并重新打开 Git Bash

  3. 键入npp在Git中的Bash,如果它打开,然后你就可以走了。如果没有,请尝试以下几点:
  4. 通过在 Git Bash 中运行以下命令来测试.bashrc

    source ~/.bashrc
    
  5. 重试键入npp以启动 Notepad++。如果 Notepad++ 没有启动,请检查在步骤 1 中创建的文件~/.bashrc的内容。

  6. 为确保 . 每次打开 Git Bash 都会加载bashrc文件内容,编辑~/.bash_profile并添加以下两行。(参考)

    if [ -r ~/.profile ]; then . ~/.profile; fi
    
    case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
    
  7. 关闭并重新打开 Git Bash。键入nppGit中的Bash来检查它是否正确启动。

回答by Yumlembam Rahul

In your .bash profile add

在您的 .bash 配置文件中添加

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

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

Give "\\" instead of "\".

给“\\”而不是“\”。

回答by Rob

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)

multiInst 参数只是为了使其对已经打开 notepad++ 的交互式编辑更友好。(如果 Notepad++ 已经打开并且您再次运行该过程,它会将文件添加到您现有的实例中,然后立即退出,这在 git 中意味着您已完成)

回答by Lou

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

我遇到了找不到命令的问题。我发现这是因为我在我的工作目录下执行了所有这些 vim .bashrc。看来我必须在 Git Bash 主目录下执行此操作...