SublimeText: How to find the command for "Next Build Result" to map it to a different key? - sublimetext3

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" }

Related

Sublime Text: Add "Permute Lines -> Shuffle" shortcut key

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).

Make cmd+| map to command in sublime text

In Atom cmd+| maps to toggling the file tree, how can I make sublime text do the same when these keys are pressed
If by toggling the file tree you mean hiding and showing the side bar, what you want to do is remap the key bound to the command that does that by default.
Note: Based on your use of cmd in the question, I'm assuming you're on a Mac so the answer is tailored for that. The operation remains the same but the key name will be different for the other platforms.
If you look at the default key bindings (available from the Preferences menu, which under MacOS is part of the Sublime Text menu entry) you can determine what keys are bound to what by default. In this case the command you want is toggle_side_bar; if you don't know the command you can find it by searching the key map to find the keys that you know you press to do this normally.
With that information, the default key binding for MacOS is:
{ "keys": ["super+k", "super+b"], "command": "toggle_side_bar" },
In your own custom key bindings file (available from the same menu as the defaults) you just need to insert your own key binding. For your case, that would look like this:
{ "keys": ["super+\\"], "command": "toggle_side_bar" },
You might think that the key should be super+| since that is what you want to bind to ultimately; however that will not work because in order to generate that character, you need to be pressing Shift, and thus without shift as a part of the key binding, it won't work.
Instead we use the character that is generated if you press the key without shift, which on my keyboard is \. That is a special character in JSON strings, so it needs to be doubled in order to be correct.
For keyboard layouts different from US QWERTY, you might need to swap that character for something else. You can determine the binding you want by opening the Sublime console with View > Show Console, entering the command sublime.log_input (True) and then pressing the key combination in question; Sublime will tell you what it thinks you pressed.

Stop highlighted text from autofilling sublime's goto anything search

I use goto anything quite a bit, but mainly for searching for files. It goes a little something like this:
cmd p, immediately start typing file name
shit, there's a random string of junk at the beginning of my search
backspace, backspace, backsp....
type file name
receive list of file choices that I wanted to begin with
Is there a setting I can set somewhere to make the behavior a little more sane for my use-case?
Thanks.
I don't believe that's a default behavior. What plugins do you have installed? If you log the commands (sublime.log_commands(True) in the ST console), what do you see? I get command: show_overlay {"overlay": "goto", "show_files": true}. If it's not that, a plugin may be binding to super + p. If that's the case, you may either remove the plugin, or create a user key binding with the proper command/arguments.

Sublime Text 2 vintage key mapping like vim

i am working with Sublime Text2 in vintage mode. I disabled the arrow keys, so i don't use them to move the cursor in insert mode. Now is was wondering, if it is possible, to map the up/down keys, so that they will move a line of code up and down. In vim it is easy possible by just mapping the keys to do a sequence like "dd k P" to delete the line move cursor up and past it above.
The syntax for the key mapping in Sublime still is quite complicated to me as a beginner.
Thanks
Insert the following into your user key bindings.
[
{ "keys": ["up"], "command": "swap_line_up" },
{ "keys": ["down"], "command": "swap_line_down" }
]
The key mapping file is just JSON. There are 4 keys.
keysis a list of key entries. An entry will generally be something like ["<modifier> + <character>"]. You can define multi level keybindings by creating additional entries in the array. An example of this is to show and hide the side bar. The entry for this is ["ctrl+k", "ctrl+b"]. The available keys are described here.
command is a string specifying the command to run. To see what command is running with a particular action, you can enter sublime.log_commands(True) in the ST console.
args are the arguments passed to the command. This is a dictionary object. The keys for this correspond to the parameter name for a given command.
context is a list of dictionary entries to conditionally execute a given command. These can be somewhat complicated. There is a reference for context here.
I think the best way to familiarize yourself with the key bindings is to just try things out. I used the default keys as a reference.
You might want to keep this as a reference.
You can run a series of commands by creating macros. These are just lists of commands and arguments and are further described here.

Bind shortcut to command palette command?

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.

Resources