jsynowiec / vscode-insertdatestring

An extension for Visual Studio Code that provides a configurable command for inserting the current date and time
MIT License
63 stars 14 forks source link

insert a newline in Insert Date String #27

Open smcnally opened 1 year ago

smcnally commented 1 year ago

In Settings ... Insert Date String: Format This works great:

# YYMMDD - #### H:mmA

Can I insert a newline so a Format value like

# YYMMDD \n #### H:mmA

inserts

# YYMMDD
#### H:mmA

I've tried with and without single- and double quotes around newline and carriage return characters. No luck so far. \n, \r, 0xA and 0xD

Thank you for this extension -- long-time listener; first-time caller

hseliger commented 1 year ago

From what I can see, the function uses Javascript's now.format() method, which only supports literal strings, but afaik unfortunately does not expand special characters. So I guess you're out of luck.

Two possible alternatives: create a macro to first insert the date, then a newline, then the time (you can call the extension's function to insert the time/date stamps).

Alternative 2, better yet more complex: provide a patch for insertdatestring to first call now.format() to format the date string, and then expand the formatting codes (where I don't know a quick solution, but would assume that one of the string formatting methods should do the trick).

smcnally commented 1 year ago

many thanks - will work at these alternatives and follow up here. much obliged