17

如果当前文件名以.rb 结尾,我想让notepad++ 运行“ruby {filename_here}”命令,如果它以.pl 结尾,则让“perl {filename_here}”运行。我试过用 NppExec 插件,但它不能做有条件的东西,所以我写了一个 bat

@echo off

if /i %~sx1 == .pl perl "%~f1"
if /i %~sx1 == .rb ruby "%~f1"
if /i %~sx1 == .php php "%~f1"

现在我可以从命令行使用它,例如 C:\Program Files\Notepad++>runscript "D\pl.pl" 并且它工作正常。现在如何将 Notepad++ 中的某个键绑定到“runscript $(FULL_CURRENT_PATH)”?我尝试使用运行->运行菜单 (F5),但它似乎不起作用..

4

5 回答 5

21

您需要将文件名放在命令的末尾。在 Run(F5) 对话框中,试试这个:

runscript $(FULL_CURRENT_PATH)

如果你想测试它,你可以& pause在最后加上a,看看它是否有效。

GOTO您还可以通过使用带有文件扩展名标签的可怕命令稍微调整您的脚本,以便每个文件都不会测试每个扩展名:

@echo off
GOTO %~sx1
:.pl
  perl "%~f1"
  GOTO end
:.rb
  ruby "%~f1"
  GOTO end
:.php
  php "%~f1"
  GOTO end
:end
于 2009-08-03T22:44:58.687 回答
5

我在使它工作时遇到问题,以便在我查看它的作用时保持 shell 窗口打开。将“& pause”放在最后似乎没有帮助,直到我cmd /c在开头添加:

cmd /c c:\php\php.exe -l "$(FULL_CURRENT_PATH)" & pause

为了将命令结果保留在屏幕上,您可以使用 /k 开关,正如 George 所建议的: cmd /k c:\php\php.exe -l "$(FULL_CURRENT_PATH)"

这很好用,我用它在 Notepad++ 中进行快速语法检查。

于 2011-11-04T09:19:40.983 回答
5

In the notepad++ version 6.2, running on Windows, just use "$(FULL_CURRENT_PATH)", with the quotes, so the file will be opened using the default program associated to the file. So, be sure that "edit with notepad++" is NOT the default double click action.

于 2012-11-27T15:15:56.407 回答
1

您可以使用以下脚本尝试 npp_exec :

NPP_SAVE
SET Executer = execute$(EXT_PART)
NPP_EXEC "$(Executer)"

然后使用一个名为 execute.rb 的脚本:

perl $(FULL_CURRENT_PATH) //or something like that

此方法在此处描述

于 2010-11-25T10:40:26.780 回答
1

There is plugin called RunMe that can open current file in default program. It is better solution than "$(FULL_CURRENT_PATH)" command because it change current directory to the file path and that command run the file in N++ path.

于 2013-03-10T20:15:31.140 回答