Table of contents
1. Basic configuration
After installing Sublime Text 4, the first step is of course to install it first Package Control
. It is similar to a package manager, with which you can easily install/uninstall/list other plug-ins.
The installation method is: press and hold Cmd + Shift + P
to open the command panel, enter Install Package Control
, and find the corresponding option to install. After the installation is complete, restart Sublime Text, open the command panel, enter Package Control: Install Package
and press Enter to install other plug-ins.
Some useful plugins:
ChineseLocalizations
: Simplified Chinese Chinese. GenerallyConvertToUTF8
, this plug-in is used to solve the problem of garbled Chinese characters in Sublime Text;SideBarEnhancements
: Sidebar enhancement. This plug-in is usuallySyncedSideBarBg
used to solve the problem of inconsistent sidebar color and Sublime Text background color;BracketHighlighter
: Bracket highlighting.
Next is the user configuration. Press Cmd + ,
to open the user configuration and edit it in the box on the right. Here is the blogger's own configuration:
{
/* 字体与主题设置 */
"font_size": 15,
"font_options": ["no_italic", "no_bold"], // 无斜体,无加粗
"color_scheme": "Monokai.sublime-color-scheme", // Monokai主题
"theme": "Default Dark.sublime-theme",
/* 行间距 */
"line_padding_bottom": 1,
"line_padding_top": 1,
/* 光标样式 */
"caret_extra_top": 1,
"caret_extra_bottom": 1,
"caret_extra_width": 1,
/* 其他设置 */
"highlight_line": true, // 高亮当前行
"show_encoding": true, // 右下角显示编码
"trim_trailing_white_space_on_save": true, // 保存时自动在文件末尾增加换行
"show_full_path": true, // 上方显示文件完整路径
"bold_folder_labels": true,
"word_wrap": true, // 是否自动换行
"rulers": [80],
"translate_tabs_to_spaces": true, // 将tab转化为空格
"save_on_focus_lost": true, // 失焦后立即保存
"ignored_packages": ["Vintage"], // 忽略插件
}
User configuration is stored in ~/Library/Application Support/Sublime Text/Packages/User/Preferences.sublime-settings
.
2. Configure the development environment
Over time, the configuration methods given in this article may become invalid, so here is some relevant information:
- System: Ventura 13.1
- Sublime Text version: 4143
- Terminal: iTerm2 3.4.19
2.1 Configuring C++
This section assumes you have iTerm2 installed.
Click in the menu bar above 工具 -> 编译系统 -> 新建编译系统
, clear the content, and then copy the following content into it
{
"cmd": ["bash", "-c", "g++ '${file}' -std=c++11 -stdlib=libc++ -o '${file_path}/${file_base_name}' && open -a iTerm.app '${file_path}/${file_base_name}'"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
}
⚠️ Considering that most users who use Sublime Text to write C++ will choose to run it immediately after compilation, so the configuration given here is also a compile + run configuration. If you only need to compile, you can refer to other bloggers' articles.
After saving, please do not change the default save path, just change the file name to C++11
(of course it can be customized). The storage path of this configuration file is: ~/Library/Application Support/Sublime Text/Packages/User/C++11.sublime-build
.
Click again in the menu bar above 工具 -> 编译系统
and select C++11
. After writing the code and saving it, press Cmd + B
to compile and run.
In order to prevent iTerm from automatically crashing after running, some changes need to be made here. Open iTerm, press Cmd + ,
Open Preferences
, click in turn Profiles -> Session
, and After a session ends
change the following to No Action
.
2.2 Configuring Python
Likewise 工具 -> 编译系统 -> 新建编译系统
, copy the following content into it, and of course don’t forget to replace it . You can view it 你的python解释器路径
by typing in the terminal .which python
{
"cmd":["你的python解释器路径", "-u", "${file}"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"env": {
"PYTHONIOENCODING": "utf8"},
"selector": "source.python",
}
After saving, the file name can be set to Python3
, then click in the menu bar above 工具 -> 编译系统
and select Python3
.
However, Python configured in this way cannot realize interactive input, so you need to install SublimeREPL
a plug-in. After installation, open it ~/Library/Application Support/Sublime Text/Packages/SublimeREPL/config/Python/Main.sublime-menu
, "id": "repl_python_run"
locate according to , replace the in with the interpreter path, as shown in the figure below ( note that it must be , if it is, an error may becmd
reported )python
python3
python3
python
Then configure the shortcut keys. Click in the menu bar above Sublime Text -> Settings -> 快捷键设置
and add the following content:
[
{
"keys": ["alt+shift+n"], // 不喜欢这个键位可自行更改
"caption": "SublimeREPL: Python - RUN current file",
"command": "run_existing_window_command",
"args": {
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"}
},
]
After saving, we can use shortcut keys Alt + Shift + n
for interactive input. Of course, non-interactive input can also use this shortcut key.
3. Summary of some bugs
Will continue to update based on feedback in the comment area...
solved:
- For Macs equipped with M1 chips,
SublimeAStyleFormatter
it may not work. At this time, open Finder, enter the application, right-clickSublime Text.app
, click显示简介
, and check使用 Rosetta 打开
.
Not yet resolved:
- If the blogger's Mac does not install
SublimeAStyleFormatter
orCodeFormatter
this plug-in will result in the inability to open the menu bar aboveSublime Text -> Settings
. But if you create a new user and use it as a new user, you won’t have this problem; iTerm.app
The reason why iTerm is used as the terminal is because if you use the terminal that comes with mac (that is, replace the with in the compilation commandTerminal.app
), it will result in:"xxx"无法打开,因为不允许“(null)”在“终端”中打开文稿
.