The C++ standard doesn't rule the file extension, so the most of people use .cpp
, but I prefer using .cc
, how to tell Sublime Text save to .cc
when using C++ syntax as default?
The way to change the default file extension shown by the save-as dialog when saving a file set to a specific syntax is to override that syntax's default .sublime-syntax
file. In your case that would be the C++.sublime-syntax
file.
Of course, as MattDMo points out, the easiest thing to do is to manually type the preferred file extension whenever you save a file. But for those that want to make the change, here's how to do it.
Command Palette
and select View Package File
.C++
and then select C++/C++.sublime-syntax
. ST will open the file.file_extensions:
and a list like this:file_extensions:
- cpp
- cc
- cp
- cxx
- c++
...snip...
file_extensions
list as the default file extension for the save-as dialog..cc
the default extension instead of .cpp
, edit the list order so that - cc
is the 1st item and - cpp
is 2nd, i.e. swap the top 2 lines around.Packages
directory with this path: ../Packages/C++/C++.sublime-syntax
. If you like you can create a C++
directory in Packages
and then just use Ctrl+S
to save because the path will have been automatically set by ST but the file won't save unless the ../Packages/C++/
directory already exists./home/user/.config/sublime-text-3/Packages/C++/C++.sublime-syntax
Open Resource
Command Palette command could be used to extract .sublime-syntax
files instead of ST's native View Package File
command. That plugin will automatically create the appropriate Packages
directory when necessary.Your altered Packages/C++/C++.sublime-syntax
file will now override the default version that is shipped with ST. You can reverse this easily simply by deleting the file. It is safe to delete the directory as well if you are not overriding any other files in the same directory.
The only problem with this is when you install a new version of ST. If the newly installed version has an updated C++.sublime-syntax
file, the local one you've created will continue to override the new one. To get around this delete your altered Packages/C++/C++.sublime-syntax
file when you install a new version of ST and repeat the steps above to restore your preferred default file extension once the installation has been done.
Unfortunately there is no way around this, you can not partially override the C++.sublime-syntax
file with just the file_extensions:
section. Of course new versions of ST don't come along very frequently and the C++.sublime-syntax
file gets updated even less often. So this is not a major issue.