如何在Sublime Text 3中为特定语法设置默认保存扩展名(如C++设为.cc)
How to Set Default Save Extension for Specific Syntax (C++ to .cc) in Sublime Text 3
Let's break this down into two parts: first the general method for setting a default save extension for any syntax in Sublime Text 3, then the specific steps to get C++ files to default to .cc instead of the common .cpp.
General Method for Specific Syntax Default Extensions
If you want to set a default save extension for any programming language or syntax in Sublime Text 3, follow these straightforward steps:
- First, open a file that uses the syntax you want to configure (or switch to it via
View > Syntax > [Your Target Syntax]). - Open the syntax-specific user settings by navigating to
Preferences > Settings - More > Syntax Specific - User. This will open a dedicated settings file for that syntax (it might be empty if you haven't edited it before). - Add the key-value pair
"default_extension": "your-extension"to the JSON object. Note that you don't include the leading dot here—Sublime will handle that automatically when saving.
Specific Steps for C++ to .cc
Since the C++ standard doesn't mandate a file extension (.cpp is just the most widely adopted convention), switching to .cc is totally valid and easy to set up:
- Open a new file or switch an existing one to C++ syntax via
View > Syntax > C++. - Open the C++ syntax-specific user settings: go to
Preferences > Settings - More > Syntax Specific - User. This opensC++.sublime-settingsin your user config folder. - Paste the following JSON into the file (if it's empty, just add this; if there are existing settings, append the line to the existing JSON object):
{ "default_extension": "cc" }
- Save the
C++.sublime-settingsfile. From now on, any new file using C++ syntax will default to saving with the.ccextension. If you switch an existing file's syntax to C++, the save dialog will also use.ccas the default option.
内容的提问来源于stack exchange,提问作者user13739935
相关产品推荐
相关产品推荐

