Sublime Forum

Remapping character keys possible?

#1

Is it possible in Sublime to remap characters? When I google I only find answers about mapping commands to shortcuts, that’s not what I mean. In vim I have for instance:

:inoremap ¡ {

i.e. when i type ¡ (Spanish symbol?) I get a curly brace instead. So, is it possible to do such remappings in Sublime (3)? Thank you.

0 Likes

#2

It is indeed possible to just simply map a character onto another character. However you may wish to limit this to particular scopes so that you don’t block yourself out of using that character in other documents.

For example (not saying this is a good idea, just an example)

{
		"keys": ["a"],
		"command": "insert",
		"args": {"characters": "b"},
		"context": [{"key": "selector", "operand": "source.the_no_a_lang"}]
}
1 Like

#3

Yeah I only want to limit this to characters for which I have absolutely no use, such as ¡, £, ¤, so I’m worried about unforeseen consequences of such a change.

I tried adapting your example but can’t get it to work. What I did:

Preferences -> Key Bindings
{ "keys": ["¡"], "command": "insert", "args": {"characters": "{"}, "context": [{"key": "selector", "operand": "source.the_no_¡_lang"}] }

I’m guessing the problem is with the very last part, but I don’t know how that’s “supposed” to look :stuck_out_tongue:

0 Likes

#4

You can just drop the context part if you want to enable it everywhere. Otherwise you can get the context selector of the current syntax by pressing ctrl+alt+shift+p

1 Like

#5

Alright. So I went ahead and tried the example a to b mapping, but still nothing.

EDIT: I.e. I tried:
{ "keys": ["a"], "command": "insert", "args": {"characters": "b"} }
but it doesn’t work.

0 Likes

#6

Do you have an error output in the ST console ctrl+`? If no write

sublime.log_input(True)

and maybe

sublime.log_commands(True)

Then try it again and look at the output

0 Likes

#7

Hm I’m not sure what you mean? I opened the console (that shortcut doesn’t work, btw) and wrote the two commands. When I type ¡ I get:

chr evt: ¡ (0xa1)

Or did you mean something else? I appreciate the help so far!

0 Likes

#8

What happens when you hit the A on your keyboard? The console should print this:

chr evt: a (0x61)
command: insert {"characters": "b"}

Don’t forget to type sublime.log_commands(True) and sublime.log_input(True) in the console first.

By the way, when you map a to b you can comment out the keybinding first if you want to restore this crazy setting :wink:

1 Like

#9

Er, yes. I guess I didn’t mean for my example to be taken literally (especially the scope.the_no_a_lang part) Please inject the character you wish to remap and the character you wish to remap it to in the obvious spots, and remove the context check if you truly want it in all documents.

Obligatory:

MRS. GREGORY: Ahh, what’s so special about the cheesemakers?
GREGORY: Well, obviously, this is not meant to be taken literally. It refers to any manufacturers of dairy products.

1 Like