7

我将我认为有用的代码示例作为文本文件保存在我的计算机上。我将它们存储为 txt 文件而不是编写它们的语言,以便它们将在 Notepad++ 而不是编辑器中打开(即我不希望我的 c++ 示例在 IDE 中打开,只是在记事本中打开)。

有没有办法让 Notepad++ 通过读取文本文件本身中的特殊代码来对文本文件应用适当的语法突出显示?

例如,如果我有一些 sql,则文本文件的第一行可能是这样的:

##Language=SQL 

... my sql code properly highlighted as sql ...

提前致谢。我意识到我可以在打开文件后选择语言(即语言> SQL),但如果它可以自动完成会更方便。

4

5 回答 5

4

不,它不能。您可以手动选择它或使用特殊的文件类型扩展名,然后将其与 Notepad++ 关联并告诉它将文件突出显示为适当的语言。

例如,对 SQL 使用 .txtsql 文件,对 C++ 使用 .txtcpp 文件等。

于 2009-12-09T23:24:47.057 回答
2

我建议给他们适当的文件扩展名,然后将这样的内容导入您的注册表:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\NotepadPlusPlus]

[HKEY_CLASSES_ROOT\*\shell\NotepadPlusPlus\command]
@="C:\\path\\to\\notepad++.exe \"%1\""

然后,您可以通过快速右键单击在 NP++ 中打开文件,NP++ 将能够根据文件扩展名自动检测正确的语言。

于 2009-12-09T23:23:50.647 回答
2

手动选择是一种更简单的方法。以 .txt 格式存储所有文件(不考虑 java 或 C 或 C++)。在 Notepad++ 中打开文件并在菜单中选择相应的语言。例如语言 --> Java。

于 2009-12-31T11:31:09.447 回答
2

I ended up writing it myself:

  1. You need the Python plugin

  2. Add the code below to your startup.py file

  3. Switch your Python Initialization setting from "LAZY" to "ATSTARTUP"


#if found determine the menu command and switch language in NPP
def switch_language_view(args):
    notepad.activateBufferID(args["bufferID"])
    lineone = editor.getLine(0)
    if '##' in lineone:
        lineone = lineone[lineone.rfind('##'):].replace('##', '')
        lineone = "MENUCOMMAND." + lineone.upper()
        try:
            notepad.menuCommand( eval(lineone) )
        except:
            pass

#command to link notification
notepad.callback(switch_language_view, [NOTIFICATION.FILEOPENED])

于 2014-12-04T23:32:21.917 回答
1

你可以尝试一些 npp 脚本,

Python

lua

and/or hacking macros. you could make the script start conditionally, check your special string and select the language for you.

于 2012-03-08T16:09:10.537 回答