I am new to Sublime Text 2 on Mac OS.
I installed the package SublimeREPL.
Is it possible to create a keyboard shortcut to run the file with SublimeREPL?
More precisely, here is a screenshot. I want to avoid going through this menu and run quickly with a keyboard shortcut.
You can set a keyboard shortcut for the command in your screenshot using Sublime key-bindings.
Open Sublime.
Go to Preferences > Key Bindings - User
Add these lines to the opened file between brackets:
{ "keys": ["ctrl+alt+b"], "command": "run_existing_window_command", "args":
{
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}}
Save it.
It's done! You can type any key-combinations instead of "ctrl+alt+b", but make sure it's not reserved by Sublime itself (check in Preferences > Key Bindings - Default)
You can set keyboard shortcuts for any menu item that you can select, in any app.
Go to System Preferences → Keyboard → Shortcuts → App Shortcuts
Click the + to add a new shortcut.
Set the Application to Sublime Text.app, the Menu Title to the exact name of the menu option, and choose a Keyboard Shortcut.
Click Add.
I found that I lost the keybinding to the installed sublimeREPL, so I had to find how to get it back, since it is a time saving indispensable for me. I used it also on a pc that had not sublime Repl and worked for both. This worked for me in 2019, version 3.2
in preferences / keybinding (after you installed package control and sublimeREPL). I made this video too.
[
{"keys": ["ctrl+b"], "command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["C:/Users/giova/AppData/Local/Programs/Python/Python37-32/python.exe", "-u", "-i", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}}
]
p.s.: change the location of the python.exe as it is stored in your pc.
You can also do this:
[
{"keys": ["ctrl+b"], "command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "s",
"args": {
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"cmd": ["py", "-u", "-i", "$file_basename",],
"type": "subprocess",
"encoding": "utf8",
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"view_id": "*REPL* [python]",
}}
]
To use different version of python, you can type py -2.7 for example, if you have them installed.
You can also use 'python' in the cmd list.
To see where the location of python is, you can import sys and look at sys.path from python itself. You can also add "-m", "-pdb" to do the debugging, using another key combination maybe.
This works again in 3.2
[
{ "keys": ["ctrl+b"], "command": "run_existing_window_command", "args":
{
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}}
]
Go to Preferences -> Key Bindings, and write this in the window "Sublime-keymap --User"
[
{
"keys": ["ctrl+alt+b"],
"command": "repl_open",
"args": {
"cmd": ["python", "-u", "-i", "$file_basename"],
"cwd": "$file_path",
"encoding": "utf8",
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"external_id": "python",
"syntax": "Packages/Python/Python.tmLanguage",
"type": "subprocess"
}
}]
i have an addition to Romina's answer,
i used her code, but it opens with Python default version, in my case (Linux Mint) it was Python 2.7,
so if you have that trouble just change her code with this:
[
{
"keys": ["ctrl+alt+b"],
"command": "repl_open",
"args": {
"cmd": ["python3", "-u", "-i", "$file_basename"],
"cwd": "$file_path",
"encoding": "utf8",
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"external_id": "python3",
"syntax": "Packages/Python/Python.tmLanguage",
"type": "subprocess"
}
}]
And it works with Python 3 (if you have it installed of course)
tq, add debug
{ "keys": ["ctrl+b"], "command": "run_existing_window_command", "args":
{
"id": "repl_python_pdb",
"file": "config/Python/Main.sublime-menu"
}
},
Related
How does one add user input when debugging on VScode?
I have tried the following
Edited my launch.json to set externalConsole : true
Tried giving input as a command line argument as mentioned here
Irrespective of following step by step the above methods, something was off.
I kept getting a window where I couldn't do anything. The step up / down / in buttons went inactive.
Here in my launch.json file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++-10 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "C/C++: g++-10 build active file"
}
]
}
and here is my tasks.json file
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++-10 build active file",
"command": "g++",
"args": [
"-g",
"${file}",
"-std=c++17",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
System details
Version: 1.48.1
Commit: 3dd905126b34dcd4de81fa624eb3a8cbe7485f13
Date: 2020-08-19T17:09:41.484Z
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 20.0.0
The resolve is given in a gist here
The issue is when VSCode launches the debug adapter, then the debug adapter launches lldb-mi, then lldb-mi launches Terminal. There is a prompt that should appear, but somehow the DebugAdapter is not forwarding this permissions request.
The work around is to have VS Code launch the terminal once. You can do this by adding and running this tasks in your tasks.json:
{
"label": "Open Terminal",
"type": "shell",
"command": "osascript -e 'tell application \"Terminal\"\ndo script \"echo hello\"\nend tell'",
"problemMatcher": []
}
You can run this specific task using Command + Shift + p. Type Tasks and look for Tasks: Run Tasks then select Open Terminal.
I have written a small blog post about the same, detailing each and every step with images which can be found here.
I've set up a launch.json file such that a C++ program uses an external console (so that it can receive user inputs), but when launching, VSCode simply opens a terminal window without running the program in it. If "externalConsole": true, is set to false, the program runs and can be debugged fine, just can't take inputs.
Note: No task.json file is used, CMake is used to create the executable binary.
Launch file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/bin/program_bin",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/bin",
"environment": [],
"MIMode": "lldb",
"externalConsole": true,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
]
}
]
}
Is it possible that VSCode doesn't have 'permission' to run an external terminal? Using on MacOS.
I have the same issue. This may not be the working answer, but hopefully it will get us farther down the correct path.
I did some digging and found the following:
VS Code Documentation mentioned that it opens an external console via lldb-mi.
A search for lldb-mi led to this post on the Apple Developer forums.
...which leads to an open source Github Repo with a build of lldb-mi
I need to read through the documentation for that build first, and then I'll give it a shot. I'll post results if it solves the issue.
I've tried to use standard (recomended ways of debugging from vscode documentation) and ran into the same issues with external terminal.
I'm also using mac and switching to CodeLLDB plugin to use LLDB for debugging helped
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
just follow documentation: https://github.com/vadimcn/vscode-lldb/blob/v1.8.1/MANUAL.md
But as a hint here is my working setup:
(I couldn't though make it work on windows, but I'm running windows via Parallel II, so maybe natively this plugin will work too)
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/g++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json
{
"configurations": [
{
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
// "stdio": ["input.txt", null, null], // https://github.com/vadimcn/vscode-lldb/blob/v1.8.1/MANUAL.md#stdio-redirection
"cwd": "${fileDirname}",
"preLaunchTask": "C/C++: clang build active file" // this have to be the same as "label" in tasks.json
}
],
"version": "2.0.0"
}
just make sure you have all tools available, check by running in cli:
/usr/bin/clang --version
# and
lldb --version
good luck
I have a C file that I'm trying to debug but fail.
I'm using vscode on windows 10.
The file is quite large so I don't want to copy it here.
This is how my launch.json file looks in the .vscode folder in the folder that I'm working in:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/? linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc.exe build active file"
}
]
}
This is how my tasks.json looks like in the same .vscode folder:
{
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
}
}
],
"version": "2.0.0"
}
when I press the "start debugging" button the screen freezes and the program stalls and then vscode crashes
I managed to find a solution, I deleted the old files, clicked debug, it wanted me to create a new configuration, chose gcc launch and then there was an option 'gcc.exe build and debug active file' , clicked it, and now everything works.
I've updated the content of the files above to how they look right now if anyone has the same issue in the future.
I want to ask how to debug a simple hello world output from a C++ file, on the launch file I have to put the executable but I have only created a C++ file, how to compile it, I have tried everything, please help.
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
// compiles and links with debugger information
"args": ["-g", "-o", "main.exe", "main.cpp"],
// without debugger information
// "args": ["-o", "hello.exe", "hello.cpp"],
"showOutput": "always"
}
Pretty old question but here's a clear explanation for anyone in future.
Issue is that the debugger was looking for a.exe but your build file will probably be named different.
Changing the values of program variable to "${workspaceFolder}\\${fileBasenameNoExtension}.exe" will fix this issue. This should be in the tasks.json and the launch.json.
This env variable takes care that the right name is substituted. Now set a breakpoint and press f5.
Further details here and here.
Here's a full preview of a working launch.json
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\MinGw\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
And a full preview of tasks.json.
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
NOTE: As explained here and here, you might want to set "externalConsole": true if your code needs input from user.
When i choose in REPL, EVAL or TRANSFER i have the following error running a py:
Cannot find REPL for 'python'
I use python 3, and reading other post i make this changes to use in sublime text 3
1.Create a file name: Python3.sublime.build with the following code:
{
"path": "/Library/Frameworks/Python.framework/Versions/3.3/bin/",
"cmd": ["python3.3", "-u", "$file"],
"env":{},
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Then i have the option to build a Python3 System
2.In settings in sublime REPL - Default i put this:
"default_extend_env": {"PATH": "/Library/Frameworks/Python.framework/Versions/3.3/bin/python3:{PATH}"},
and change the file Main.sublime-menu in located in Packages/SublimeREPL/config/Python with this:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{"caption": "Python",
"id": "Python",
"children":[
{"command": "repl_open",
"caption": "Python 3",
"id": "repl_python3",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["/Library/Frameworks/Python.framework/Versions/3.3/bin/python3", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
{"command": "repl_open",
"caption": "Python 3 - IPython",
"id": "repl_python_ipython3",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"autocomplete_server": true,
"cmd": {
"osx": ["/Library/Frameworks/Python.framework/Versions/3.3/bin/python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"linux": ["/Library/Frameworks/Python.framework/Versions/3.3/bin/python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"windows": ["/Library/Frameworks/Python.framework/Versions/3.3/bin/python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
},
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {
"PYTHONIOENCODING": "utf-8",
"SUBLIMEREPL_EDITOR": "$editor"
}
}
}
]}
]
}]
}
]
I think there's must be an easy way to refer python 3 but i don't find it or not find clear, when i choose in Tools, SublimeREPL, Python and Python 3 it open a new tab with python 3
Set Layout to "2 Rows" under View Menu.
Select "SublimeREPL:Python" from the Command Palette under Tools.
~Morgan (very new at this)
"https://superuser.com/questions/755320/sublime-text-cant-find-interpreters-for-sublimerepl"
Was the deal/fix on my side. ** REPL needs to be open first. . . . **
Dunno if its the same for others, but this small detail was the key for me.
lol.
Hope that helps