Make cmd+| map to command in sublime text - sublimetext3

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.

Related

Sublime 3.2.2 shortcut for skipping the next selection quick add isn't working (macOS)

Yesterday I could use ⌘ + k to skip the next quick add selection. Today it's stopped working. I think the relevant line in the key bindings file is this:
165 { "keys": ["super+k", "super+d"], "command": "find_under_expand_skip" },
How can I get this important shortcut working again? There's no menu command instantiation of this function, so I can't use Apple's System Prefs for shortcut key assignment (and not sure Sublime Text would honour, some apps are flaky on that). It's for skipping the next instance of your search token when selecting duplicates of the whatever was selected when the first Quick Add was added to the selection.

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

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

Can I emulate arrow key in sublimetext3?

In short:
I want to type [left arrow], [right arrow], [command-v] sequence whenever I press [command-v] in sublime text 3.
In length: I have a problem with IME and pasting in sublime text (OSX). If you don't use asian language you might not understand what I'm saying but let me try.
I'm korean. My language has letters like '각' and '가'. Do you notice the difference? The prior letter have additional 'ㄱ' at its bottom.
To type in those letters, you press 'ㄱ' -> 'ㅏ' -> 'ㄱ' for prior, and 'ㄱ' -> 'ㅏ' for latter. Again, do you notice the difference?
To complete the letter '각', you should make the letter '가' first, and type in additional 'ㄱ'. However, you want '가' this time, so typed 'ㄱ' -> 'ㅏ' and completed the letter '가', but sublime (or OSX IME) doesn't know whether you completed, or should wait for the additional ㄱ to complete the letter '각'. So it awaits next type to decide to start new letter, or to complete something like '각'. My problem begins here.
You completed the letter and want to paste something, so press [command-v], but sublime was waiting for additional component and did not finish the letter. It just deletes the letter '가'. To work around this problem, I type in something like [space] or [arrow key] to make sure sublime completes the letter. This is fairly annoying.
So, I want to automate the annoying potion. Can I type [left arrow], [right arrow], [command-v] sequence whenever I press [command-v] in sublime text 3? [space], [backspace], [command-v] or any combination will work, I think.
Any help will be highly appreiciated
I think a solution to your dilemma could be to create a macro. To do this, look in Tools -> Record Macro, which you'll also notice is triggered by Ctrl + Q. Once you activate that, perform the key combination you wish to invoke. In this case, the sequence:
Left Arrow
Right Arrow
Ctrl + V
Now go back into Tools -> Stop Recording Macro. Now, it won't be explicitly saved yet - your macro is now placed on the buffer, and you can play it back with Tools -> Playback Macro. To save it for continued use, use Tools -> Save Macro... and save it somewhere (most commonly in .../Packages/User, although by no means do you need to save it here).
For reference sake, your macro should look exactly like this:
[
{
"args":
{
"by": "characters",
"forward": false
},
"command": "move"
},
{
"args":
{
"by": "characters",
"forward": true
},
"command": "move"
},
{
"args": null,
"command": "paste"
}
]
That text was generated by following my steps exactly and recording the macro appropriate to your situation.
And to use this macro, we'll need to do a little more tinkering.
Look in Preferences -> Key Bindings - User. This will open a rather derelict text file (assuming you haven't touched it yet) where you can specify your own keyboard mappings. These will override the default settings (located in Preferences -> Key Bindings - Default, if you wish to check those out).
So in this "User" key bindings file, we need to specify that the normal Ctrl + V will be overridden by our custom macro. An empty "User" key bindings file will look like this:
[
]
Not much to extrapolate from. The syntax required here is fairly legible, but pretty difficult to guess at without prior knowledge. Add this entry between those brackets, like so:
[
{
"keys": ["ctrl+v"], "command": "run_macro_file", "args": {"file": "path/to/your/<macro_name>.sublime-macro"}
}
]
Save that file, and you should be good to go. You may need to restart Sublime for this to take effect.

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.

Mapping numeric keypad keys in vim

I'm unable to get this mapping to work in vim inside an xterm terminal.
:map <k0> :echo 'Hello'<CR>
I can get the same mapping to work fine in gvim. If I issue the above command in vim on a terminal, it accepts it, and it shows up correctly when I type :map. But in normal mode, if I press the 0 keypad key, a "0" shows up on the status line, and then disappears with the next keypress.
I'm using the vim that came with Fedora 14 if that matters, and a plain xterm. The keypad keys work fine in insert mode, both with numlock on and off.
What am I missing?
Try to add this line to your ~/.Xdefaults:
xterm*appkeypadDefault: false
and relaunch xterm.
The "Application Keypad Mode" is likely the reason of your troubles.
But I don't think you should do what you are doing. In --NORMAL-- mode, numeric input is used to indicate "count" like in 4dd. Mapping numbers to other commands is going to get you into troubles fast.
You should add a xterm tag to your question.
There's some ambiguity in the question, which may indicate the actual problem. vim accepts that binding for k0 supposing that it is a function key.
Most keyboards that you'll see number function-keys starting at 1, and a few terminal descriptions equate function-key 1 to k0, a few equate it k0 to function-key 10. It's also possible that someone assumes that is part of the numeric keypad, but unlikely (since the keypad uses different character sequences than the function keys).
That's assuming you used a terminal description that knows about the function keys. The vt100 terminal description doesn't do that, since vt100's had no function keys (other than PF1 through PF4 which are or aren't depending who you talk to). But if you had TERM=vt100, then some of the numeric keypad could be recognized on the basis of the terminal description (see for instance the lengthy comment above the vt100+fnkeys description).
It's not in TERM=xterm, however.
What you're overlooking is that vim (helpfully perhaps) amends the terminal description using its built-in termcaps. It recognizes PF1, etc. using table entries like this:
{K_XF1, IF_EB("\033O*P", ESC_STR "O*P")},
{K_XF2, IF_EB("\033O*Q", ESC_STR "O*Q")},
{K_XF3, IF_EB("\033O*R", ESC_STR "O*R")},
{K_XF4, IF_EB("\033O*S", ESC_STR "O*S")},
But there are no entries for the numbered keys; there's no "\033O*p" for the 0 key.
If vim has (in the terminal description) the k0, and you haven't mapped it to anything, vim will treat it as a literal 0. The same happens with k1, etc., in effect treating the function-keys and numeric keypad as the same thing.
For what it's worth, GNU screen does the same thing, but also for the numbered keys. If I run vim inside screen, vim will see only the 0's. A literal 0 in vim doesn't do much in command-mode.

Resources