Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
590 views
in Technique[技术] by (71.8m points)

sublimetext3 - How to edit Sublime Text build settings?

I want to enable -std=gnu++11 in Sublime Text 3's C++ Single File build on Ubuntu 12.04.

I have already upgraded the tool chain to the latest g++ and do not want to see the following error on every build:

error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

I browsed to /home/myuname/.config/sublime-text-3 but cannot find any file to edit.

How can I edit the build settings?

question from:https://stackoverflow.com/questions/23789410/how-to-edit-sublime-text-build-settings

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

edited

My original answer works, but there's a much better way of doing this, by creating your own build system. This use case is exactly why the feature is there.

Go to ToolsBuild SystemNew Build System… (all the way at the bottom) and enter the contents below. Save as C++ 11 Single File.sublime-build, and it will now be accessible in the build system menu. Select it, hit CtrlB to build, and then hit CtrlShiftB to run the resulting program. Or you can use a Build and Run option and call it by hitting CtrlB, then selecting that option.

{
    "cmd": ["g++", "-std=gnu++11", "${file}", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",

    "variants":
    [
        {
            "name": "Run",
            "cmd": ["${file_path}/${file_base_name}"]
        },
        {
            "name": "Build and Run",
            "cmd": ["g++ -std=gnu++11 ${file} -o ${file_path}/${file_base_name} && ${file_path}/${file_base_name}"],
            "shell": true
        }
    ]
}

If you need to edit it in the future, the file is in the User folder of Packages. The Packages directory is the one opened when selecting Preferences → Browse Packages…:

  • Linux: ~/.config/sublime-text-3/Packages or ~/.config/sublime-text/Packages
  • OS X: ~/Library/Application Support/Sublime Text 3/Packages or ~/Library/Application Support/Sublime Text/Packages
  • Windows Regular Install: C:Users(YourUserName)AppDataRoamingSublime Text 3Packages or C:Users(YourUserName)AppDataRoamingSublime TextPackages
  • Windows Portable Install: (InstallationFolder)Sublime Text 3DataPackages (InstallationFolder)Sublime TextDataPackages

The exact path depends on version and whether or not you upgraded from Sublime Text 3.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...