Request: default filename is first line of file
-
With Word (et al) the first time you hit save it will enter the first line of the file as the default filename. For example, if my file is:
Do List for 21-11-26
task 1
task 2the first time I hit Ctrl+S it will use “Do List for 21-11-26.txt” as the default filename. I wish Np++ would do this. Right now I have to copy the first line, hit Ctrl+S, then paste the first line in the save box.
-
It makes zero sense for programmers, and Notepad++ is first and foremost a programmer’s text editor, so I don’t see something like this happening natively.
However, something like this could be easily scripted with a PythonScript. A really barebones version (just as a demo) of
SaveUsingFirstLineAsFilename.pymight be:# -*- coding: utf-8 -*- from Npp import * class SUFLAF(object): def __init__(self): f = notepad.getCurrentFilename() if f.startswith('new '): l = editor.getLine(0) notepad.saveAs(l + '.txt') if __name__ == '__main__': SUFLAF()You’d run this script when you want to save such a file, rather than pressing Ctrl+s.
-
Using first line as default filename would be nice for text files though.
-
@stephane352 said in Request: default filename is first line of file:
Using first line as default filename would be nice for text files though.
Even that feels yucky to me and not something the Notepad++ developers would be likely to implement.
If you must have it, go with the script approach. To work effectively, though, the script needs to be “rounded out” a bit more. I wasn’t inclined to do that, because I’d only do that kind of thing if it was some capability I had a lot of interest in. Because I don’t…someone else would have to do it.
-
Thank you Alan K for that script. I used to use NPP for all my programming but now I use VSCode; but I still use NPP for all other text files (do lists, notes, etc) and for those this is a very useful feature.
I didn’t know how to use it, so for others in the same predicament I had to:
- Go to Plugins menu | Plugins Admin; install PythonScript
- Plugins | PythonScript | New Script
- Paste the script, save it as FirstLineAsFileName
to run it I have to do:
Alt (to show menu) | Plugins | PythonScript | Scripts | FirstLineAsFileNameI’m trying to figure out how to create a shortcut to run this script because it takes a lot of mousing to get to it
-
@doug-rogers said in Request: default filename is first line of file:
I’m trying to figure out how to create a shortcut to run this script because it takes a lot of mousing to get to it
First, you have to tell PythonScript to add it to the menu: Plugins > PythonScript > Configuration…, then select the script and click the left Add button. Then restart Notepad++, and you will see that your chosen script is now at the Plugins > PythonScript >
scriptnamelevel instead of buried deeper. Once that’s true, then Notepad++'s Preferences > Shortcut Mapper > Plugin Commands will list your script (you can filter byPythonScriptto find it faster), and you can assign a shortcut that way.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login