10

I have a number of files that I would like colored different ways even though they have the same extension. For example, I have some *.config files that are actually Python files and some that are XML files. When I open them I have to manually change the language to Python or XML.

It would be nice if, for example, Notepad++ would remember that c:\foo\bar\whatevs.config should use the Python styling, but c:\hey\ho\boo.config should use XML styling.

Any way in Notepad++ to say "remember the language that was used the last time the file was opened"? A plugin perhaps?

4
  • Are you running into problems somewhere by using the correct file extensions?
    – iglvzx
    Dec 2, 2011 at 19:07
  • 1
    I have a Python app that uses .config files that are really Python files, and .NET uses .config files that are really XML files. As another example, I have markdown files that use the .txt extension because they sync with an Android app that doesn't understand what .md files are.
    – mhenry1384
    Dec 2, 2011 at 19:12
  • I see. Does it remember the language you set when you close Notepad++ with the file open, and then reopen Notepad++?
    – iglvzx
    Dec 2, 2011 at 19:15
  • 2
    Actually it does, if you have "Remember current session for next launch" checked (which I don't). But it forgets it when you close the file and reopen it.
    – mhenry1384
    Dec 2, 2011 at 19:21

4 Answers 4

12

There is a GUI option to set up a static link between file extension and language (instead of manually editing the %APPDATA% langs.xml file or %PROGRAMFILES% langs.model.xml file as @jakub.g suggested):

If you go to Settings -> Style Configurator -> select the language on the left, then at the bottom of the screen two textboxes appear:

Style Configurator

In this example, I added "config" to the User ext. textbox so any time I open a file with a .config file extension the XML syntax highlighting will be automatically selected under the Language menu.

I know this doesn't solve the problem of remembering which syntax highlighting to apply to a single specific file, but it is an easy way to set up highlighting for all file extensions.

If you want to remember the syntax highlighting selection for an individual file I believe the only option is to select the checkbox: Settings -> Preferences -> MISC -> Remember current session for next launch.

4
  • it doesn't save it though. once you close and reopen notepad++, the changes are gone.
    – r3wt
    Jan 26, 2015 at 18:39
  • @r3wt I believe you need to run as administrator otherwise it won't have permissions to save the preferences to your user profile.
    – wweicker
    Feb 4, 2015 at 18:02
  • This will not work for in-built file extensions. You have to manually remove the extension from the ext part of the language in the langs.xml file. That file can live in %APPDATA%/Notepad++ or the Notepad++ install directory or in your cloud Storage i.e. DropBox, OneDrive or GoogleDrive if you have thhe Settings in the Cloud option enabled. Jun 29, 2015 at 11:06
  • Does this work for custom languages? I can't find mine anywhere in the list. Jul 14, 2017 at 7:36
1

This isn't quite what you're asking for, but applies to your comment regarding .txt files as Markdown files. One possible option is to set Markdown as the language for all .txt files.

This assumes markdown_npp is installed. Edit the following files at your own risk (make backup copies before editing these files):

  • Open langs.xml from %appdata%\Notepad++
    • Remove txt extension from normal language:
      • Before: <Language name="normal" ext="txt" />
      • After: <Language name="normal" ext="" />
  • Open userDefineLang.xml from %appdata%\Notepad++
    • Add txt extension to Markdown language:
      • Before: <UserLang name="Markdown" ext="md">
      • After: <UserLang name="Markdown" ext="md txt">
  • Restart Notepad++
1
  • worked for me, and it was the only way i could get notepad++ to permanently store the relationship. thanks
    – r3wt
    Jan 26, 2015 at 18:47
0

To add fixed connection between extension and language, open NPP folder (e.g. C:\Program hFiles\Notepad++), there are several XML files there. Edit them (I don't remember which exactly, langs.xml or langs.model.xml).

Example: <Language name="cpp" ext="h hpp hxx cpp cxx cc">

Find the language you want and add the extension.

However I don't know how to make the same extension vary per-folder.

0

This works with notepad++ v.8.4.6
which comes with preinstalled two files (markdown._preinstalled.udl.xml and markdown._preinstalled_DM.udl.xml[for darkmode]) in %APPDATA%\Notepad++\userDefineLangs

Do the following.

in `%APPDATA%\Notepad++`  
    amend langs.xml
        **Before**: <Language name="normal" ext="txt"/>
        **After**: <Language name="normal" ext=""/>
    amend userDefineLangs\markdown._preinstalled.udl.xml
        **Before**: <UserLang name="Markdown (preinstalled)" ext="md markdown" udlVersion="2.1">
        **After**: <UserLang name="Markdown (preinstalled)" ext="md markdown txt" udlVersion="2.1">

Associate txt/md with notepad++
    Start notepad++ by `Run as admin`
        Filemenu Settings/Preference/File Association

(Do the same with markdown._preinstalled_DM.udl.xml if you use darkmode.)

Restart notepad++. (Note that, in order for it to take effect, you need to reopen (close and open) txt files if any txt files are already opened before the setup.)

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.