## 経緯
新しいファイルがどのディレクトリ配下に作成されるかは`Default location for new notes`の設定によって決まる。今の仕様では、都度設定を`Same folder as current file`にするか、現在のディレクトリ名を手動入力しなければならない。補完もできないためミスも多いし面倒..。
## やり方
[[Templater]]を使って以下のtemplateを作る。実行しやすいコマンド名にするといい。私は`Create file in current directory`にした。
```js
<%*
const cur = app.workspace.activeLeaf.view.editor.getCursor()
const title = app.workspace.activeLeaf.view.editor.getClickableTokenAt(cur)?.text ?? "untitled"
const path = `${app.workspace.getActiveFile().parent.path}/${title}.md`
const createdFile = await app.vault.create(path, "")
await app.workspace.openLinkText("", createdFile.path, true, app.workspace.activeLeaf.getViewState())
app.commands.executeCommandById("workspace:edit-file-title")
%>
```
カーソル配下がInternal Linkになっている場合は、ファイル名として採用する。
## 動作イメージ
![[create-file-in-current-directory.mp4]]