I want to set a shortcut to open my current file using an external program (in my case, Visual Studio).
I thought I could use the $file variable, available in the build system. So it I write:
{ "keys": ["ctrl+o"], "command": "exec", "args": {"shell_cmd": "\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\IDE\\devenv.exe\" $file"} }
I get in the Sublime console prompt:
Running "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" $file
As you can see, the $file variable isn't expanded to the pull path of the open file. Does anyone know what's the problem here?
Working solution for (but for OS X) was to use it like this:
{ "keys": ["super+shift+option+o"], "command": "exec", "args": {"cmd": ["open", "-a", "ForkLift", ""]}}
Related
I have a project with a myproject.sublime-project file. If I open the project by opening this file in the Sublime Text UI, Sublime respects the exclusion rules in the file.
However, if I open the file in Sublime from the command line, it does not:
subl myproject.sublime-project
The excluded files and folders appear in the Sublime Text UI. The same is true if I do subl ..
Is there a way I can open this project from the command line, and have it respect the rules in myproject.sublime-project?
Here are the contents of the file, for reference:
{
"folders":
[
{
"path": ".",
"file_exclude_patterns": [
"server/site/*.js"
],
"folder_exclude_patterns": [
".sass-cache",
"node_modules",
]
}
]
}
I'm trying to bind ":W" editor command to save the file just like ":w". I make a lot of this typos.
The vim plugin is: https://marketplace.visualstudio.com/items?itemName=vscodevim.vim
This settings.json code doesn't work:
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": [":","W"],
"commands": [
"workbench.action.files.save"
]
}
]
Unfortunately this is not possible in vs code vim, but I ended up doing what bsaf suggested here and rebound : to ; so that I wouldn't accidentally be holding shift down while pressing w, which doesn't solve the problem you asked but it does solve the problem you mentioned in your post. You can do this by adding this to your settings.json file:
"vim.normalModeKeyBindings": [
{
"before": [";"],
"after": [":"]
}
]
You can still use : as normal, but now ; will also allow you to run editor commands.
I already tried using the SublimeAStyle Package, but it didn't work. When I pressed the keys, the command would not fire (I checked in the console). Now I am trying to write my own key-shortcut to run the program on my source code. I have this:
{ "keys": ["ctrl+alt+f"], "command": "exec", "args": { "cmd": ["C:\\Program Files\\AStyle\\bin\\astyle.exe", "${file_name}"]} }
but the ${file_name} is not expanding to pass the file name to the command. Is there anything I am doing wrong?
Through steps found:
Is it possible to chain key binding commands in sublime text 2?
Using the following Build System:
{
"cmd": ["g++", "$file", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cxx, source.cpp",
"variants": [{
"name": "Run",
"shell": true,
"cmd": ["gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};echo;read line;exit; exec bash\"'"]
}]
}
I created the following .py extension:
import sublime, sublime_plugin
class BuildAndRun(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("build")
self.window.run_command("build", {"variant": "Run"})
And keybiding:
{ "keys": ["ctrl+b"], "command": "build_and_run"},
The keybiding activates the extension correctly, but then in terminal it returns:
bash: /home/hadrian/Documents/new: Permission denied
'new' is the name of of .cpp file.
The problem is also that, if it only has (in the .py extension) build, it builds, if it only has run, it runs, but if it has both it returns that bash error.
I'm not being able to find out where this 'permission error' is created through the whole process.
I would like to run a external python script (or external command/program) when I press a key on Sublime Text 2.
How can I do this?
Here is a solution:
Preferences->Key Bindings - User and put this in the file (overriding the [,] inside):
[
{ "keys": ["<your shortucut>"], "command": "exec", "args": { "cmd": ["<path to your script>"]} }
]
Where <your shortcut> as the name says is the shortcut (examples: F1, ctrl+shift+F1, etc.) and <path to your command> is the location of your command (examples: echo, /home/user/scripts/my_script.py, ls, etc.)