I did see:
Sublime text: how to add a key binding to hex_viewer package command
Sublime Text set key binding for Tools > Babel > Babel Transform
I have installed JSON Reindent in my Sublime (3.2.2 Build 3211). To reindent a JSON I press Ctrl+Shift+P type in JSON Reindent in command pallet and press enter.
I would like to bind a key combo say Ctrl+Shift+J to JSON Reindent command. I already have my own Default (Linux).sublime-keymap in the right place with a lot of overrides. But I'm unable to find command name.
This functionality is brought in by a plugin so command won't be available here. I tried to:
bind indent and reindent, no luck
bind json_reindent, JSON_Reindent and JSON Reindent, no luck
enable command logging via sublime.log_commands(True) in cosole, then did
Ctrl+A (select all)
Ctrl+Shift+P
type in JSON Reindent in command pallet
press Enter
It printed following in console (nothing for JSON reindent).
>>> sublime.log_commands(True)
command: move_to {"extend": true, "to": "eol"}
command: select_all
command: show_overlay {"overlay": "command_palette"}
What do I put for command to bind a plugin's command in my Default (Linux).sublime-keymap?
{ "keys": ["ctrl+shift+j"], "command": "?????" },
The command you're looking for is found in the plugin's sublime_json_reindent.py file and is, in fact, called as sublime_json_reindent. It can also be found in the Default.sublime-commands file.
Related
New Windows Terminal (Windows Terminal (Preview) Version: 0.2.1831.0) have settings in JSON file. How can I setup powershell running with Anaconda?
Anaconda running in powershell with:
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\Users\akali\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\Users\akali\Anaconda3' "
Windows Terminal use profiles in JSON like this:
"profiles": [{
"colorScheme": "Solarized Light",
"commandline": "powershell.exe"
}]
How can I use running with Args with double quote in JSON that allow me run something like -Command "& 'C:\'"?
I realize I'm late of some years but I had a similar problem and stranded up here looking for an answer. So, I'm hoping that this is useful for people like me in the future.
After some time tinkering I generated an Anaconda profile:
copy paste an existing profile
generate guid here
open C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)
right click on Anaconda Powershell Prompt (Miniconda3) and go to Properties
copy the entire content of the target field and paste it on the field commandline (make sure the field is commandline and not source)
escape all the \ characters (\ --> \\)
Change the name field
You should have something like this
{
"guid": "{generated guid}",
"hidden": false,
"name": "Anaconda",
"commandline": "powershell.exe -ExecutionPolicy ByPass -NoExit -Command & 'C:\\ProgramData\\Miniconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\ProgramData\\Miniconda3'"
},
As a nice sidenote, you can also create a profile to directly launch an Ipython session or a jupyter notebook.
As you may have noticed, lo launch anaconda in the commandline field we are just launching powershell.exe, and then telling the powershell instance to execute a -Command, which is the subsequent string.
Were you to add a ; ipython to the command, you would launch an ipython session.
Copy-paste the settings for cmd from above.
Go to "C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\Anaconda3 (64-bit)"
Right-click on "Anaconda Prompt (Anaconda3)"
Copy the content from the target field and paste it on the field commandline
Mine is %windir%\System32\cmd.exe "/K" C:\bin\Anaconda3\Scripts\activate.bat C:\bin\Anaconda3
Replace \ with \
Thanks to the above answer by Marco Necci, this is a more clear version with cmd and anaconda
"commandline" : "%windir%\\System32\\cmd.exe /K C:\\bin\\Anaconda3\\Scripts\\activate.bat C:\\bin\\Anaconda3"
Building upon Navaneeth M et al, I contribute a command line which includes the default Anaconda location using USERPROFILE environment variable, specifying non-default Anaconda env (fastai), starting directory and color scheme.
"commandline": "%windir%\\System32\\cmd.exe /K %USERPROFILE%\\Anaconda3\\Scripts\\activate.bat fastai",
"colorscheme": "Solarized Light",
"startingDirectory": "c:\\sw",
Pro Tip: Use keybindings to add a hotkey which opens a new tab in the specified project directory. For example, use ctrl-b to open a new Anaconda tab in just the right place.
"keybindings": [
{
"keys": [ "ctrl+b" ],
"command": {
"action": "newTab",
"profile": "Anaconda",
"startingDirectory": "c:\\sw\\myproject\\myprojectdirectory"
}
}
]
Right click properties of conda powershell shortcut (in desktop or start menu). There you get the path to the command that effectively starts conda using powershell.
Now, just follow the recipe of Marco Necci outlined above, just caring to put double backslashes instead of single ones.
Searching further modifications, in this site i've found that i could generate the new needed guid with powershell itself: [guid]::NewGuid().
And in the repo of new terminal, i've discovered it's possible to customize the icon too. My icon was in a different path, that i came across looking in anaconda shortcut in windows menu (i used anaconda navigator's icon - right click it > more > open; somewhere ending with 'Start Menu\Programs\Anaconda3 (64-bit)': right click once more in the shortcut > properties; change icon - there is the path to the icon).
Again, be wary to use double backslashes instead of single ones.
Sound as lazy as it is I was wondering if it's possible to open a file with sublime using (command line) and in the same command define the expected syntax.
Lets say on a mac we have the subl command installed, so running $ subl .bash_something will open the .bash_something then we have to chose the "shel script(bash)" syntax from the list. what would be really nice (for laze me) is to include the syntax to the command as an argument. i.e.
$ subl -x bash .bash_something
or something like that. this obviously doesn't work but I was wondering if there is similar solution or if its possible to include one
Unfortunately, there is no way that I can find to dynamically set the syntax from the command line. subl has the --command option, which allows you to run a Sublime command while loading the file, directory, or project indicated. However, the command to change the syntax of a view - set_file_type - takes an argument of the form ("syntax": "Packages/PackageName/SyntaxName.sublime-syntax") (or SyntaxName.tmLanguage). As far as I've been able to tell, you simply can't pass arguments to commands run via the command line. I've opened an issue to request an enhancement.
Now, this doesn't mean that all is lost. If you have just a few filetypes that are unknown to Sublime, open them, then select View -> Syntax -> Open all with current extension as... and select the syntax you want. If for some reason this isn't sufficient, or would like finer-grained control over exactly which filenames (not just which extensions) get opened as what, check out the ApplySyntax plugin. It allows you to use regexes to open exactly which file patterns you define as what syntax.
Commands can take arguments in Sublime 3 now. I was able to achieve this functionality with a bash function.
You can pass arguments to the --command option with inline JSON and escaped quotes. This command will change the syntax to Bash for the current active file in Sublime:
subl --command "set_setting {\"setting\": \"syntax\", \"value\": \"Packages/ShellScript/Shell-Unix-Generic.sublime-syntax\"}"
I created a simple bash function and sourced it in my .bash_profile to wrap these two commands together to activate/open a file then change the synax:
function subl_bash() {
subl "$1" && subl --command "set_setting {\"setting\": \"syntax\", \"value\": \"Packages/ShellScript/Shell-Unix-Generic.sublime-syntax\"}"
}
I used that command but forgot how to turn it on:
In sublime console, which is invoked by ctrl+` I typed something like ...
turn_on_debug_mode
... and sublime console started to log every command I run. For example, if I press right mouse button on the view and click Copy file path then in the sublime console I found logging of this action with the name of invoked command like copy_file_path.
So that was an easy way to grab names of commands that I could use in self-written sublime plugins.
The problem is that I do not remember how to turn that debug mode on.
In the console input:
sublime.log_commands(True)
To view keystrokes:
sublime.log_input(True)
I am using Octave for some Machine Learning work and I have noticed in my package library in Sublime that there is SublimeREPL: Octave as an option.
However when I select it, I get the following error message:
FileNotFoundError(2, "No such file or directory: octave")
Is there a way to use sublime to code with Octave?
Many thanks
First, you need to find out where your octave executable lives, and note the full path to it. On Linux or OS X, open your favorite terminal emulator and type which octave, and if it's in your $PATH variable it will print the full path to it (for example, /opt/local/bin/octave or something like that). If it's not in your path, or if you're on Windows, you'll have to search around a bit until you find octave or octave.exe, if you're on Windows.
Once you have the path, open Sublime and select Preferences -> Browse Packages..., which will open your Packages folder (surprisingly). Navigate to Packages/SublimeREPL/config/Octave and open the Main.sublime-menu file in Sublime - don't worry, it's just plain JSON. Go down to line 18 (or thereabouts) - it should say "cmd": ["octave", "-i"],. Change "octave" to "/full/path/to/octave", obviously replacing /full/path/to/ with the actual full path you noted earlier.
Save the file, and you should be all set. Tools -> SublimeREPL -> Octave should now open up an interactive session, just like running octave -i on the command line would do. You can use all of the usual SublimeREPL shortcuts to send code to the running REPL, or just use if for testing functions, code snippets, etc.
Have fun!
I am using Sublime Text 3 on OS X
Octave programs are running perfectly. So you can try the below mentioned steps
Open Sublime
Goto Tools --> Build System --> New Build System...
Paste this code
{
"cmd": ["/usr/local/octave/3.8.0/bin/octave-3.8.0", "$file"],
"selector": "source.m"
}
Save it as Octave.sublime-build
Now use Octave as your build system
Use ⌘ + B to run your code.
Enjoy!
Is there a way to create a build command in Sublime Text that opens a new external window (terminal/cmd.exe)? Everything I try gets captured to the built-in output window.
I tried:
{
"cmd": ["ruby", "$file"],
"target": "cmd.exe",
"file_regex": "rb$",
"selector": "source.rb"
}
But nothing happened
The following works for Windows (I've tested it on XP and 7):
{
"cmd": ["start", "cmd", "/k", "c:/ruby193/ruby.exe", "$file"],
"selector": "source.ruby",
"shell": true,
"working_dir": "$file_dir"
}
Save it as Packages/User/Ruby_cmd.sublime-build (you may need to alter the path to the Ruby executable depending on your system), select Tools -> Build System -> Ruby_cmd, and build with CtrlB.
start does what it says it does, start a new process independent of Sublime Text. cmd is cmd.exe, the Windows command-line interpreter. The /k flag keeps the window open (at a new command prompt) after your program has run, allowing you to examine its output, look at tracebacks, run additional commands, etc.
May be you will find this solution helpful:
https://github.com/rctay/sublime-text-2-buildview
(transfers build output in the separate sublime tab, you can then do with it whatever you want)