Organizing VSCode Settings with a Custom Extension
Learn how to create a custom VSCode extension to organize and categorize your settings.json file, making your development environment cleaner and more
Search for a command to run...
Learn how to create a custom VSCode extension to organize and categorize your settings.json file, making your development environment cleaner and more
No comments yet. Be the first to comment.
Improve your experience of tmux with tmux configuration and a simple bash function
Learn effective Python exception handling with practical examples, including custom error classes and try-except blocks for robust error management.
A python tool to generate cheatsheet of command line tools as a PDF
Use rehype-external-links to open links in new tab
Hey there, fellow developers! If you're like me, you probably spend a lot of time in Visual Studio Code (VSCode), and over time, your settings.json file might have become a bit of a mess. With so many extensions and configurations, it can be tough to keep things neat and tidy. So, I decided to tackle this problem head-on by creating a custom VSCode extension to organize my settings.
Extension: Settings Organizer
GitHub: HYP3R00T/settings-organizer
The idea behind this project is pretty simple: create an extension that categorizes and sorts your settings.json file. I wanted to make sure that settings related to different parts of the editor, like the window, workbench, explorer, editor, terminal, git, extensions, and anything else, are grouped together. This way, everything is easy to find, and the file looks much cleaner.
I found myself wasting too much time scrolling through a chaotic list of settings. Organizing these settings not only makes them more manageable but also helps in quickly locating specific configurations when needed. Plus, this was a great way to dive into VSCode extension development!
The core of this extension is a function that reads your settings.json, categorizes the settings, and then writes them back in an organized manner. Here’s a sneak peek into how it works:
Read thesettings.json file.
Categorize settings based on predefined categories (like window, workbench, etc.).
Sort and write them back to settings.json.
Here’s a snippet of the actual code that handles the categorization and sorting:
function categorizeSettings(settings: any) {
const sortedSettings: { [key: string]: any } = {};
const categoriesOrder = [
"window",
"workbench",
"security",
"explorer",
"terminal",
"editor",
"git",
"extensions",
"remote",
];
// Sort settings based on categories
categoriesOrder.forEach(category => {
for (const key in settings) {
if (key.startsWith(category)) {
sortedSettings[key] = settings[key];
}
}
});
// Add language-specific settings
const languageSettings: { [key: string]: any } = {};
for (const key in settings) {
if (key.startsWith("[") && key.endsWith("]")) {
languageSettings[key] = settings[key];
}
}
// Sort language-specific settings alphabetically
const sortedLanguageSettingsKeys = Object.keys(languageSettings).sort();
sortedLanguageSettingsKeys.forEach(key => {
sortedSettings[key] = languageSettings[key];
});
// Add any miscellaneous settings that don't fit into categories
for (const key in settings) {
if (
!categoriesOrder.some(category => key.startsWith(category)) &&
!(key.startsWith("[") && key.endsWith("]"))
) {
sortedSettings[key] = settings[key];
}
}
return sortedSettings;
}
Once you’ve got everything set up, you can run your extension in VSCode to see the magic happen. It’ll tidy up your settings file, making it much easier to navigate.
Building this extension was not only about cleaning up my own workspace but also about learning and contributing to the developer community. It’s a small tool, but it makes a big difference in maintaining a clean and efficient development environment.
I’m thinking of adding more features like a GUI for configuration options, supporting more categories, and maybe even automatic updates. If you have any ideas or feedback, feel free to share!
Happy coding, and may your settings.json always be neat and tidy!
Original post: Organizing VSCode Settings with a Custom Extension on hyperoot.dev.
Connect with me on social media:
Got feedback or questions? Feel free to leave a comment below or reach out to me on my personal site. Your thoughts are valuable!