2

I write a lot of math and physics problems in latex files, which have numbered filenames like albn002.tex.

Often, I need to create a new file based on a file I am already editing. For this, I have to save the file under a new name, in the same directory, with the next number for which there exists no file.

Ideal would be a procedure 'saveToNewNumberedFile' so that I could assign it to something like ',stn'

Can this be programmed directly in vimscript?

2
  • Should all numbers at the end of the name be considered up for changing, or only the last digit? Commented Dec 8, 2012 at 15:34
  • The script should find the next unused file by counting up the 3digit number at the end of the filename (without the extension) Commented Dec 8, 2012 at 17:01

1 Answer 1

3

Have a look at my EditSimilar plugin. Edit: In its latest version 2.30, the :999SavePlus command (with a large count) will search for the last existing file within that offset range, and then save the current file with an offset one larger than that.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for the tip. I had a look at the extension, it's missing the function of finding an unused filename
Yeah, as I've mentioned, automatically finding the unused number and saving wasn't directly possible. Since this is generally useful functionality, I've extended the plugin. Please check out the latest version.
Thanks again, I have installed your new version and it gets the job done! I tried to find the code for SavePlus, and wanted to isolate it because I don't need all the other functionality of your plugin. The code seems quite big for the simple task that I want to perform, so I would like to reduce it for my purposes. Could you please point me to the relevant part of the plugin?
Well, it's not so easy. All those commands are related to each other; that's why they are all part of one plugin. Why don't you just keep them; maybe they turn out helpful some time in the future?! (I use all of them a lot.) Alternatively, you could :delcommand those you don't want.
Too bad, I would have liked to learn from the code. But the new command is really handy to create a new example based on an existing one. Big thanks, cool script!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.