Lazy New File README
Lazy new file allows you to quickly create a new file based on the path of the currently open file in your editor.
Create one or multiple files in any project, quickly and easily.
AI Usage
I've used AI recently to help with this project. I was running into some issues with a new feature and didn't have the time to
really dig through why I was seeing the results I was. I've been using things like Claude code at work, and while I'm not an AI Evangelist,
nor would I even consider myself a true fan of AI, it does have it's uses in places like this.
I will always be critical of any external PR with AI.
Contributes
Contributes the following:
lazy-lazy-new-file.lazyNewFile command
- Three configuration options:
lnf.alwaysUseCurrentFile – by default we will always use the
filepath of the currently open file to determine where the new file will be
created, but just in case you use this in a multiple workspace environment,
you a selector will appear to determine which workspace to use.
NOTE: This will ALWAYS default to the root of that workspace.
lnf.openAfterCreate – Open the new file after creating it.
lnf.showExplorerItem – show the "Lazy New File" item in the explorer context.
lnf.aliases – Aliases for the current workspace.
lnf.ladderOpen – When creating multiple files, alternate between opening them on the left and right panes.
- Adds a "Lazy New File" to the context menu on the explorer files. Does not
show up for folders as the behavior is mimicked by VSCode already.
Keybindings
By default there are no added keybindings. I would recommend something
like ctrl+alt+n on Windows
Creating multiple files
Creating multiple files in one prompt requires you to use a comma in the input field. The comma can be top level, or can be nested within a set of curly brackets({}); e.g.
$components/expandable/{expandable.svelte,expandable.stories.svelte}
Will create two files in the folder where $components/ is aliases:
$components/expandable/expandable.svelte
$components/expandable/expandable.stories.svelte
These follow the same rules as the rest of the extension: if it matches an alias, it will be created from the given directory the alias is associated with.
Otherwise it will be based on the current file.
Examples
# Assume we have `src/somefile.html` open
`a.ts,b.ts` -> `src/a.ts` + `src/b.ts`
`$routes/a/{+page.ts,+page.svelte}` -> `src/routes/a/+page.ts` + `src/routes/a/+page.svelte`
`$root/a.ts,b.ts` -> `/a.ts` + `src/b.ts`
`$utils/components/bob.svelte` -> `packages/utils/src/components/bob.svelte`
`lib/{something/index.ts,something-else.ts,something-else-else.ts}` -> `src/lib/something/index.ts` + `src/lib/something-else.ts` + `src/lib/something-else-else.ts`
NOTE: by default the aliases begin with $, this is to mimic bundlers to some degree, but there is no hard rule that your aliases must begin with the the $ symbol.
Aliases
Aliases should be unique among themselves and not nested. Both the shortcut and the expanded value should end with slashes.
Wildcard Matches
Wildcard matches have been implemented recently, extending the syntax and unlocking setups for monorepos or specific nested file structures.
The key for a wildcard match should contain one or more asterisks (*), and the replacement matcher should use the dollar sign, followed by a corresponding match number, e.g.
"@*/*/": "${workspaceRoot}/packages/$1/src/$2/. These matches should still follow other rules for aliases.
✅ Examples of good aliases
"lnf.aliases": {
"$src/*/": "${workspaceRoot}/src/$1/",
"$src/": "${workspaceRoot}/src/",
"$lib/": "${workspaceRoot}/lib/"
}
❌ Examples of bad aliases
"lnf.aliases": {
"$src/": "${workspaceRoot}/src",
// This item will never be matched because the extensions exists on first match
"$src/*/": "${workspaceRoot}/src/$1/",
"$src/lib/": "${workspaceRoot}/src/lib/"
}
Workspaces
If you are working a repository that utilizes workspaces, where there are multiple
packages and apps, it can be useful to have it so that your aliases become aware of that.
"lnf.aliases": {
"$src/*/": "${workspaceRoot}/packages/$1/src/??"
}