Notepad ++:自定义语法突出显示.txt文件

jj.*_*jj. 5 syntax-highlighting notepad++

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

有没有办法让Notepad ++通过阅读文本文件中的特殊代码对文本文件应用适当的语法高亮?

例如,如果我有一些sql,文本文件的第一行可以这样读:

##Language=SQL 

... my sql code properly highlighted as sql ...
Run Code Online (Sandbox Code Playgroud)

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

jj.*_*jj. 3

最后我自己写了:

  1. 你需要Python插件

  2. 将以下代码添加到您的startup.py 文件中

  3. 将 Python 初始化设置从“LAZY”切换为“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])

Run Code Online (Sandbox Code Playgroud)