I just installed a plugin called CodeSniffer (http://soulbroken.co.uk/code/sublimephpcs), and I want to link one of it's commands from the command palette to a keyboard shortcut because I use it so often.
Is there any easy way to do this? Or will I just need to ask the developer what the name of the command is (in the command palette it is 'PHP CodeSniffer: Clear sniffer marks')?
Thanks
It's actually very easy to find the name of a command but it requires a few steps.
Open Sublime Text's built-in console (control+`)
Type in sublime.log_commands(True)
Trigger the command from the command palette
The name of the command will be logged to the console. Then open your user keybindings and create a new keybinding like this:
{ "keys": ["YOUR_SEQUENCE"], "command": "YOUR_COMMAND" }
I provided a similar answer here: Keymap Sublime Text 2 File Type?
Another way is to crack open the .sublime-commands files.
Let's say you've installed Sublime Package Control (which you really want to do!) and then open it up in the command palette (⌘⇧p on os x) and install the Search Stack Overflow package. You'll now have two new commands in the command palette, the "Stackoverflow: Search Selection" and "Stackoverflow: Search from Input" commands.
OK, open the .sublime-commands file for the package. You need to find it first. If you're hardcore you do View > Show Console, and enter print(sublime.packages_path())
Otherwise it should be here
Windows: %APPDATA%\Sublime Text 2\Packages
OS X: ~/Library/Application Support/Sublime Text 2/Packages
Linux: ~/.Sublime Text 2/Packages
Portable Installation: Sublime Text 2/Data/Packages
and then "Search Stack Overflow/Default.sublime-commands"
This is the file that make the commands show up in the command palette in the first place.
It's another JSON file with entries like these
{
"caption": "Stackoverflow: Search from Input",
"command": "stackoverflow_search_from_input"
}
see, that's the command name right there: stackoverflow_search_from_input
Now just open the user key bindings JSON file and add the key binding like #BoundinCode said.
Related
I wondered if anyone could help me out.
In sublime text, when I want to shuffle some lines (for example if I had a list of colour names and wanted them in random order). I've been using Ctrl+Shift+P, and then writing shuffle to get the "Permute lines: Shuffle" command. This is fairly quick but I'd love to have a shortcut for it as I use it very often. I know there's a file I can change but I don't know how to write the command.
Many thanks in advance!
Items that appear in the command palette are stored in sublime-commands files. If you use the View Package File command from the command palette and enter sublime-commands as the filter text, the list of all files in all packages that add commands to the command palette will be displayed.
The first part of the filename shows you what package is contributing the command, and commands that are part of core Sublime are in the Default/ package, so choosing the file Default/Default.sublime-commands will show you the commands Sublime ships with (note that some packages include a file named Default.sublime-commands, so make sure you're picking the Default/ version).
If you look in that file and search for the command that you see in the command palette, you'll find this (reformatted here to not be all one line):
{
"caption": "Permute Lines: Shuffle",
"command": "permute_lines",
"args": {"operation": "shuffle"}
},
This shows you the command and args you need to apply in a key binding.
For commands that also appear in the menu (or are bound to other keys and you want to remap them) you can also open the Sublime console with View > Show Console in the menu and enter sublime.log_commands(True). Now when you choose a menu item or press a key, the command that is being executed will be logged for you. The logging remains in effect until you enter sublime.log_commands(False) in the console or restart Sublime.
In this case doing that and then choosing Edit > Permute Lines > Shuffle will log this in the console:
command: permute_lines {"operation": "shuffle"}
This shows the same command and arguments that are required (if any).
TextMate's Esc auto-complete is great, but it's limited by default to words only in the current document when using the Plain Text grammar. Is it possible to add standard dictionary words to this? E.g., auto-complete to "dictionary" when I press Esc after "dict"?
The old manual references completions as "an array of additional candidates when cycling through completion candidates from the current document." But I don't see how to set this up in the Plain Text bundle settings, and no references to this online. Using 2.0-beta.8.5.
You could use the Avian Missing TextMate2 Bundle to gain access to the "Auto-complete Across Current Tabs" command.
You could then make and keep your_dictionary.txt open in a tab, and just add the words you wish TextMate had to that file.
Although I haven't tested this, it stands to reason that if you opened "Auto-complete Across Current Tabs" in the bundle editor, made a copy, and change line 11:
open_files = `lsof +D "#{project_dir}" -a -c TextMate -Fn`.split("\n").map do |line|
to
open_files = `cat ~/your_dictonary.txt" -a -c TextMate -Fn`.split("\n").map do |line|
Then the script search that file even when it wasn't opened in a tab.
IMHO: I don't think expanding this list to include every word is going to be a good idea. That's basically spell check's job.
I have build_config (and other *_config files), GdbRun and build.txt files which are basically bash shell scripts.
How could I associate these files with shell syntax ? To place a pattern like
'if filename is *_config or GdbRun or build.txt' somewhere.
BufferScroll plugin can remember most of view settings for a particular file including syntax.
Just install BufferScroll and change the syntax manually using the status bar or the command palette and it'll remember it next time you open that file.
Background: I am working on an SML file on SublimeText3 with build system setup.
After a build, i can successfully jump to the first error using the F4 key. I want to add another key mapping for the same "Next Result" command eg:Cmd+N in Vintage mode.
What should i add as in my keybindings file to achieve this?
What documentation,file did you refer/look around to find the proper answer for question 1? What was your thought process in brief to figure it out ?
edit: changed the required keybinding from <leader>cn to Cmd+N to make things easier
For future reference, you can type sublime.log_commands(True) into the Sublime console and then the command name of every action you do will get printed to the console. Once you get the command name you need, you can stop the command printing with sublime.log_commands(False)
You can find the command being called on a default key-binding in the default key bingings file. This file is opened using the menu:
Preferences > Key Bindings - Default
Inside this file you must find the entry corresponding to the keys you are looking for, in this case f4 key is mapped to next_result command as you can see in the key binding:
{ "keys": ["f4"], "command": "next_result" }
I was writing a shell script and ran into a problem: Is there a way to open a file using the user's specified text editor?
The user's chosen editor should be in $EDITOR, but you must still choose a sane default.
"${EDITOR:-vi}" file.txt
Ignacio's right (though arguably, the fallback should be ed, which POSIX requires to be present, although it's essentially only useful to old-timers).
If you're thinking about graphical editors, xdg-open file.txt is what you're after.
note: xdg-open file.xml will open in a Web-Browser, most likely.
So, try;
# select your default sensible-editor from all installed editors, or not.
select-editor
# Open Default Text Editor
sensible-editor file.xml