Is there a way in Notepad++ to adjust the syntax highlighting for specific keywords? What I want is to be able to change the color of the import keyword in Python. I know you can create a user defined language but I don't want to go through all of that work, I just want to change the color of individual keywords.

Is this possible in Notepad++?


After thinking about this problem a bit more I realized that what I really want is to be able to add extra menus to the style configurator so I can create multiple groups of keywords. That way I can have default keywords colored blue, another group of keywords colored red, and another group of keywords colored green, etc.

Thanks in advance for any input!

  • The Python language is supported and includes "import". More keywords can be added via Settings -> Style Configurator -> Python -> KEYWORDS -> User defined keywords.
    – harrymc
    Mar 8 '16 at 8:19
  • 1
    That is not what I am asking. What I am asking is how to create multiple sets of keywords so you can color each set differently. I realize that import is in the keywords but I would like to change the color of that statement without changing the color of the other keywords Mar 8 '16 at 13:07
  • Then you are not going to escape from defining a new language, but you can start with the existing Python and modify it. Luckily, lots of documentation about it does exist.
    – harrymc
    Mar 8 '16 at 20:32
  • 1
    How would create a new language from an existing one? I haven't found any information about it. Mar 8 '16 at 20:36

You will need to defining a new language, but the existing definitions for Python can help.

I have never defined a Notepad++ language, but here is what I know :

Unfortunately, built-in and user-defined languages are defined in two separate locations and by two different mechanisms.

In both cases, they are defined inside XML files. You will need to understand XML a little if you wish to appropriate parts from the existing definition for python, but you will build your language by using the menu command Language -> Define your language.

Built-in definitions are found in the file C:\Program Files (x86)\Notepad++\langs.model.xml. You can search this file for python and find this very simple-minded definition :

<Language name="python" ext="py pyw" commentLine="#">
   <Keywords name="instre1">and as assert break class continue def del elif else except exec False finally for from global if import in is lambda None not or pass print raise return triple True try while with yield</Keywords>

The above definition is only good for extracting from it the list of all the python keywords, which you can then break into groups. More python definitions are to be found in more files, but they are not worth the effort of appropriating them.

Now go into the Define your language menu. This dialog allows you to entirely define the python language. Your first step should be the button "Create new...", enter a name such as "Python mine", and continue from there.

You will also need to go into the menu of Settings -> Style Configurator, click on "Python" and delete its file extensions in the "Default ext.:" box, so as to revoke these extensions from the built-in python language. Add these file-extensions to your new language definition.

For better understanding the Define your language dialog, here are some references :

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.