Improve Next.js filenames readability in VSCode with custom tab labels

When working with multiple files of the same name open in Next.js, distinguishing the different tabs can be hard.

Natt Nguyen·April 13, 2024 (8 months ago)·2 min read

#nextjs
#vscode
Improve Next.js filenames readability in VSCode with custom tab labels

I like names that are descriptive, that do not hide your code's true intent but illuminate it. — Linus Torvalds

Working with Next.js, it can be hard to identify which page.tsx belongs to which directory. Luckily VSCode has a way to have a custom display label to the tabs.

In VSCode, use the shortcut to open UI settings:

  1. command ⌘ + shift + p
  2. Type and go in "Preferences: Open Settings (UI)"
  3. Type in search: "Custom Labels"
  4. Add item
  5. Type in:
    • Item: **/**.tsx | Value: ${dirname}/${filename} => route.ts
    • Item: **/**.ts | Value: ${dirname}/${filename} => layout.tsx, page.tsx, template.tsx

In VSCode, use the shortcut to open JSON settings:

  1. command ⌘ + shift + p
  2. Type and go in "Preferences: Open User Setting (JSON)"
  3. Copy this config to your setting
"workbench.editor.customLabels.patterns": {
"**/**.ts": "${dirname}/${filename}", // route.ts
"**/**.tsx": "${dirname}/${filename}" // layout.tsx, page.tsx, template.tsx
}
"workbench.editor.customLabels.patterns": {
"**/**.ts": "${dirname}/${filename}", // route.ts
"**/**.tsx": "${dirname}/${filename}" // layout.tsx, page.tsx, template.tsx
}
"workbench.editor.customLabels.patterns": {
"**/**.ts": "${dirname}/${filename}", // route.ts
"**/**.tsx": "${dirname}/${filename}" // layout.tsx, page.tsx, template.tsx
}
"workbench.editor.customLabels.patterns": {
"**/**.ts": "${dirname}/${filename}", // route.ts
"**/**.tsx": "${dirname}/${filename}" // layout.tsx, page.tsx, template.tsx
}

Before:

iTerm2 setting theme

After:

iTerm2 setting theme

It is way easier to distinguish which file belongs to which directory.

Subscribe to my blog

I'd love to share my love for design, engineering, and thinking with you when my new articles are published.

You can unsubscribe at any time, no hard feelings.