Adding File Types
-
How can I add additional recognized file types to Notepad++? For example, I create a lot of files with filetype .dat, and I would like to not have to manipulate the “Save as type” menu to “All types” every time I create one or Save As. I tried Settings, Preferences, File Association to no effect. Thank you.
-
This post is deleted! -
@Fred ,
If you are using a built-in type for your extension, then you can add your extension to the User ext. list on Settings > Style Configurator > Language:
XXXXX
. Then, if you set Language >X
>XXXXX
before doing Save As, it will show up in the list of extensions desired. For example, for Perl, I addedt tkpl wperl
as three extra extensions for Perl files; so if I do Language > P > Perl on a new file, then Save As, it shows the extra extensions in the Save as type field in the dialog.
However, your custom extension won’t be the first in the list, so it won’t be the extension that gets auto-added if you have that dialog’s ☑ Append Extension checkbox on, so you will still need to type the extension.
If you want it to be first in the list (and thus the default extension for that file type), instead of using the GUI to put your extension in User ext. field, you can instead edit
%AppData%\Notepad++\lang.xml
, and edit theext="..."
field for the built-in language so that your extension is first (then save and exit/reload Notepad++). At that point, it will be the first extension in the Save As for that filetype, and can be auto-added. (For example, I could change<Language name="perl" ext="pl pm plx" commentLine="#">
to<Language name="perl" ext="t pl pm plx" commentLine="#">
if I wanted.t
to be the default Perl extension [I don’t, because Perl test-suite files are not the normal Perl extension that I use, but I could].)If you have a User Defined Language (UDL) instead of a built-in language, and have your
dat
extension defined as an extension for your UDL, then doing Language > UDLName before Save As will at least automatically default to “All Types” for the Save as type field.If you don’t like having to do the manual Language >
X
>XXXXX
, and want a keyboard shortcut, then the good news is that Macros can play back language-setting commands; the bad news is, Macros cannot record language-setting commands, so you have to manually craft a Macro by editing%AppData%\Notepad++\shortcuts.xml
instead of simply recording it. For example,<Macro name="NewPerlAndSaveAs" Ctrl="yes" Alt="yes" Shift="yes" Key="78"> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41001 = File|New" /> <Action type="2" message="0" wParam="41001" lParam="0" sParam="" /> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 46013 = Language|Perl" /> <Action type="2" message="0" wParam="46013" lParam="0" sParam="" /> <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41008 = Save|As" /> <Action type="2" message="0" wParam="41008" lParam="0" sParam="" /> </Macro>
This macro, which I can run with
Ctrl+Alt+Shift+N
, will do File > New then change the language to Perl, then Save As. To look up thewParam
needed for your language, look at menuCmdId.h . For example, in that list, you can see that IDM_LANG_PERL is (IDM_LANG + 13); IDM_LANG is 46000, so to change to Perl, I usewParam="46013"
in one of those lines. So you could have a keyboard shortcut that creates a new file in whatever type.dat
is supposed to be, and automatically starts the Save As process even before you’ve typed one character, to help you remember to save as soon as possible.If you have a UDL, it won’t have a menuCmdID in the source code; instead, you can use the NppUISpy plugin to look up the currently-assigned command-ID for
wParam
usage. For example, if I wanted to set to the Markdown UDL that is preinstalled in Notepad++, I would use UI Spy to look that up:
and then I would setwParam="46181"
. But for UDL, you have to be more careful, because if you later add another UDL that changes the sequence of UDLs in that menu, the CommandID may change. (But as long as you don’t do new UDLs, it stays consistent, in my experience.) -
@PeterJones
My head is spinning after reading your exceptionally detailed much appreciated post; but it reminded me that I had added one different UDL a while back, and I forgot that you have to do a Language command first to activate it. Adding .dat, then selecting a Language, did indeed set the default Save as to ., which is very helpful. It’s too bad the N++ developers don’t pick up the existing extension and apply either . or your selected extension automatically, because that’s the situation I originally ran into - saving an existing file via Save As or Save a Copy As. I’ll skip the macro for now, but I greatly appreciate your attention to detail! -
@PeterJones ,
Thanks, @PeterJones , I didn’t know that either. Although it never really bothered me much doing the Save As and putting the extension on, I usually create my files in the dBASE IDE to create the forms and method stubs, and then edit the methods with Notepad++ when I’m working on making a program work in the IDE at the same time, because I don’t have to close NPP like I do the IDE editor to run the program. It makes compile,run,edit much quicker to work on the code of the program, that way. I just tried the language switch, and it did start using my UDL without even having to name the file first, so…kudos for the tip. :-)I started to answer @Fred, but realized the File Associations might not have been what he was looking for, so I deleted it.