我已经在环境变量的路径中添加了notepad++.exe。

现在在命令提示符中,notepad++.exe filename.txt打开filename.txt。但我想用np filename。txt来打开文件。

我尝试使用DOSKEY np=notepad++。但它只是把一个已经打开的notepad++放在前面,而不打开文件。我怎样才能让它打开文件呢?

谢谢。


当前回答

实际上,我要给你一个更好的,让你知道一个小技巧,自从我以前在Amiga上编程时,我就用过。在您使用的任何新系统上,无论是个人系统还是专业系统,第一步都是创建两个文件夹:C:\BIN和C:\BATCH。然后修改路径语句,将两者放在开头的顺序C:\BATCH;C:\BIN;[剩余的路径]。

完成这些后,如果你有一些需要访问的实用程序,只需将它们复制到C:\BIN文件夹,它们就在你的路径中。要临时覆盖这些赋值,您可以将一个与可执行文件同名的批处理文件添加到C:\ batch文件夹中,路径将在C:\BIN文件之前找到它。它应该涵盖你可能需要做的任何事情。

Of course, these days the canonical correct way to do this would be to create a symbolic junction to the file, but the same principle applies. There is a little extra added bonus as well. If you want to put something in the system that conflicts with something already in the path, putting it in the C:\BIN or C:\Batch folder will simply pre-empt the original - allowing you to override stuff either temporarily or permanently, or rename things to names you're more comfortable with - without actually altering the original.

其他回答

首先,您可以创建一个名为np的文件。cmd并将其放在PATH搜索列表中的文件夹中。 然后,编辑np。CMD文件如下所示:

@echo off
notepad++.exe

你需要传递参数,试试这个:

doskey np=notepad++.exe $*

编辑(回应Romonov的评论)Q:有什么方法可以让命令提示符记住,这样我就不必每次打开新的命令提示符时都运行这个了?

Doskey是一个由命令处理器(例如cmd.exe)解释的文本命令,它不能知道在其他进程(特别是还没有启动的进程)中修改状态。

使用doskey设置初始命令shell环境的人通常使用/K选项(通常通过快捷方式)来运行一个批处理文件,该文件执行所有常见的设置(如-设置窗口的标题,颜色等)。

cmd.exe /K env.cmd

env.cmd:

title "Foo Bar"
doskey np=notepad++.exe $*
...

实际上,我要给你一个更好的,让你知道一个小技巧,自从我以前在Amiga上编程时,我就用过。在您使用的任何新系统上,无论是个人系统还是专业系统,第一步都是创建两个文件夹:C:\BIN和C:\BATCH。然后修改路径语句,将两者放在开头的顺序C:\BATCH;C:\BIN;[剩余的路径]。

完成这些后,如果你有一些需要访问的实用程序,只需将它们复制到C:\BIN文件夹,它们就在你的路径中。要临时覆盖这些赋值,您可以将一个与可执行文件同名的批处理文件添加到C:\ batch文件夹中,路径将在C:\BIN文件之前找到它。它应该涵盖你可能需要做的任何事情。

Of course, these days the canonical correct way to do this would be to create a symbolic junction to the file, but the same principle applies. There is a little extra added bonus as well. If you want to put something in the system that conflicts with something already in the path, putting it in the C:\BIN or C:\Batch folder will simply pre-empt the original - allowing you to override stuff either temporarily or permanently, or rename things to names you're more comfortable with - without actually altering the original.

Windows 10中的控制台别名

要定义控制台别名,请使用Doskey.exe创建宏,或使用AddConsoleAlias函数。

dos命令

doskey test=cd \a_very_long_path\test

还要在最后传递参数:doskey short=longname $*

添加控制台别名

AddConsoleAlias( TEXT("test"), 
                 TEXT("cd \\<a_very_long_path>\\test"), 
                 TEXT("cmd.exe"));

更多信息在这里控制台别名,Doskey,参数

或者你也可以使用cder,它可以让你像linux一样添加别名:

alias subl="C:\Program Files\Sublime Text 3\subl.exe" $*