我认为接受的答案没有达到 OP 想要达到的目标。 OP 想知道如何在终端中执行当前文件。
@Flycode 的设置对我不起作用。我使用的是 CentOS 7 和 Sublime Text 3。由于人们可能使用不同的终端模拟器,所以我列出了不同终端的不同设置。
注意
以下设置在上述环境下测试,效果良好。我不能保证他们会在其他环境中工作。如果它不适合你,请告诉我。
选项 1:GNOME 终端
您可以使用以下设置,
{
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"shell": true,
"working_dir": "${file_path}",
"selector": "source.c++, source.cxx, source.cpp, source.cc",
"variants":
[
{
"name": "Run",
"shell_cmd": "gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};exec bash \"'",
}
]
}
gnome-terminal会自动关闭执行窗口,上面的命令
"shell_cmd": "gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};exec bash \"'"
以这种方式使用以确保我们可以看到执行结果。有关如何防止 gnome-terminal 自动关闭的详细讨论,请参阅 this SO post。
选项 2:XTerm
您可以使用以下设置(为简洁起见,我省略了一些设置)
{ // same stuff as option 1
"variants":
[
{
"name": "Run",
//use this if you want to input other command after programm execution
"shell_cmd": "xterm -e '${file_path}/${file_base_name}; bash'",
//or you can use the below setting if you just want to execute this program
// "shell_cmd": "xterm -hold -e ${file_path}/${file_base_name}",
}
]
}
请参阅this SO post,了解如何防止 xterm 窗口自动关闭。
选项 3:控制台
您可以使用以下设置,
{ // same stuff as option 1
"variants":
[
{
"name": "Run",
"shell_cmd": "konsole --hold -e ${file_path}/./${file_base_name}",
}
]
}
请参阅此处和here 讨论在执行程序后保持 konsole 窗口。