例如:
name@usename notepad textfile.txt
相反,我想要用notepad++打开文件。
注意:我已将notepad++添加到我的PATH中,但仍然无法从命令行调用它。
编辑:
我在.gitconfig中尝试了这个——> [alias] notepad='C:/Program Files/Notepad++/notepad++.exe'
但没有起作用。
默认情况下,您不会有一个.bashrc文件,因此只需键入以下内容即可导航到您的主目录:
cd ~
使用vim(或您熟悉的任何编辑器)创建或编辑.bashrc文件:
vim .bashrc
这是我必须添加到我的代码中的一行(我正在运行64位操作系统,所以如果你不是,请不要完全复制)
alias notepad="/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
如果你的 Windows 是 32 位的,则应该看起来像这样
alias notepad="/c/Program\ Files/Notepad++/notepad++.exe"
最后,关闭并重新打开您的终端/ bash(或者,如注释所述,运行 source〜/ .bashrc
),然后就完成了!
alias open="/c/Program\ Files\/Notepad++/notepad++.exe"
- Ryansource
命令。(source ~/.bashrc
) - aderchox这些是实现目标的更快方法
start notepad++
start notepad++ <filename>
alias np='start notepad++'
np <filename>
经过尝试和测试,只需去做!
我为我的64位机器添加了32位Notepad++。
$ cd ~
$ vim .bash_profile
请将以下内容添加到文件中并保存:
64位系统
alias npp="/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
32位系统
alias npp="/c/Program\ Files/Notepad++/notepad++.exe"
$ npp [file_name]
.bashrc
文件中吗? - HattrickNZ我相信git-bash是一个真正的bash shell,所以它启动时会运行某个地方的.bashrc文件(很可能是你的主目录或git-bash开始的目录)。查找该文件,并在找到后在其中添加别名行以便使用notepad++:
alias notepad="/c/Program\ Files/Notepad++/notepad++.exe"
当然,请使用实际的Notepad++路径。
@SageMage的回答非常准确。
提醒一下,如果您在.bashrc中进行更改,则需要关闭并重新打开GitBash才能激活更改。
附注:希望这篇文章对您有所帮助,两年后看到它了!
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
.
Close and re-open Git Bash
npp
in Git Bash, if it opens then you're good to go. If not, try the below points:Test .bashrc by running the command below in Git Bash
source ~/.bashrc
Retry typing npp
to start Notepad++. If Notepad++ doesn't start, check the contents of the file ~/.bashrc created in step 1.
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
Close and re-open Git Bash. Type npp
in Git Bash to check it starts correctly.
在您的.bash配置文件中添加以下内容:
别名 myeditor="'C:\\Program Files (x86)\\Notepad++\\notepad++.exe'"
请使用"\\\\"代替"\\"。
首先,如果您还没有创建任何 .bashrc 或 .bash_profile 文件,请使用 vim 或其他编辑器(如其他人所提到的)创建其中一个。
或者
如果您还没有任何可以与 git bash 一起使用的编辑器,请手动打开记事本或 notepad++ 编辑器,并将文件保存在主目录中。
注意:您可以使用以下方法检查主目录:
cd ~
pwd
我的Notepad++路径是C:\Program Files\Notepad++\notepad++.exe
因此,如果要进入任何目录到Notepad++目录,我必须先进入根目录,然后进入所需的路径。因此,这是我必须添加到我的.bash_profile文件中的行。
alias note="//\/c/Program\ Files/Notepad++/notepad++.exe"
'//'将其带到根目录
'P.S.:
我将Notepad++文件夹添加到了我的路径中,这样我就可以直接输入notepad++
$ which notepad++
/c/Program Files (x86)/Notepad++/notepad++