Here is a way to do this in any type of file. You will need this extension (that I wrote), Find and Transform. Make this keybinding (in your keybindings.json
):
{
"key": "alt+d",
"command": "findInCurrentFile",
"args": {
"replace": [
"$${",
"const date = new Date();",
"const options = { weekday: 'short', month: 'short', year: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric'};",
"let str = `${LINE_COMMENT} ` + new Intl.DateTimeFormat('en-US', options).format(date) + ' ';",
"return str.padEnd(70, '-');", // padEnd with ---, whatever final length you want
"}$$"
],
"restrictFind": "line",
"postCommands": "cancelSelection"
},
// "when": "editorLangId == r"
}
You can use any of the Intl.DateTimeFormat
options.
Note the use of ${LINE_COMMENT}
at the beginning of the string. That will resolve to the comment style of whichever language you are in at the time. The demo is in an r
file.
