Sublime Forum

DeadKeys in Linux

#1

Hi

I’ve bought Sublime 3 a long time ago, and then I was a Mac User. Sublime worked perfectly well.
Given the last news from Apple, mac books got expensive, and therefore I got back to Linux.

Although I was an emacs user, and I still like to use it, I would like to use Sublime too. Unfortunately, Sublime has issues with deadkeys in Linux. When I try to put an accent above a letter, it just insert the two chars separately.

Is there any easy way to fix this? Is there any release to be soon available fixing this?
I confess it is a little embarrassing that the only editor I bought doesn’t work properly, but emacs, code, atom, etc, all work correctly. But yeah, I want Sublime, please :slightly_smiling:

Thank you

0 Likes

#2

You could create a plugin to change the keys. I made a small plugin, which just adds the accent char to the character. This only works with unicode and inserts 2 chars instead of one, but you can adapt it using a mapping.

Open Tools > Developer > New Plugin… and paste:

import sublime_plugin

accent_map = {
    "\u0300": {
        "a": "à",
        "e": "è",
        # ...
    },
    "\u0301": {
        "a": "á",
        "e": "é",
        # ...
    },
    "\u0302": {
        "a": "â",
        "e": "ê",
        # ...
    },
}


class InsertAccentCommand(sublime_plugin.TextCommand):
    def run(self, edit, accent, character):
        view = self.view
        mapping = accent_map.get(accent, {})
        c = mapping.get(character.lower(), character + accent)
        if character.isupper():
            c = c.upper()
        for sel in view.sel():
            view.insert(edit, sel.b, c)

Add this to your keymap:

    {
        "keys": ["`", "<character>"],
        "command": "insert_accent",
        "args": { "accent": "\u0300" },
    },
    {
        "keys": ["´", "<character>"],
        "command": "insert_accent",
        "args": { "accent": "\u0301" },
    },
    {
        "keys": ["^", "<character>"],
        "command": "insert_accent",
        "args": { "accent": "\u0302" },
    },
1 Like

#3

Thank you, that is a solution, yeah, more like a Hack.
But At least is allows me to use Sublime while it isn’t fixed :slightly_smiling:

0 Likes

#4

I edited the code to make clear how you can use single characters and fall back to the 2 char solution. Just fill the mapping.

1 Like

#5

Btw, is there any sublime API that can help me no to repeat lowercase and uppercase letters in that keymap?

Also, I added a useful line for the accent followed by a space to keep the accent.

0 Likes

#6

Dead keys always worked perfectly for me on Linux, though I hardly ever use them.

Which distro are you using and what keyboad + layout?

0 Likes

#7

Mint 18, Standard PT Keyboard.

0 Likes

#8

I change the code to query lowercase characters and convert them to uppercase if necessary.

1 Like

#9

Very thankful!

0 Likes

#10

Just adding a note that r-stein code is great, but does not solve the problem. As a programmer, I usually change my keyboard to US when writing code, and when I do, I would expect the accents not to behave as dead-keys. So, I think this issue should be addressed in an update.

Thank you!

0 Likes

#11

You can also disable the keybindings for source code by adding a context:

    {
        "keys": ["`", "<character>"],
        "command": "insert_accent",
        "args": { "accent": "\u0300" },
        "context":
        [
            { "key": "selector", "operator": "not_equal", "operand": "source" },
        ],
    },

I also think, that it should be fixed, but that is not always such easy.

1 Like