{"id":19364555,"url":"https://github.com/math2001/kpymap","last_synced_at":"2026-05-16T10:33:33.780Z","repository":{"id":74806323,"uuid":"98624445","full_name":"math2001/kpymap","owner":"math2001","description":"A Sublime Text plugin to generate keymap using Python","archived":false,"fork":false,"pushed_at":"2017-08-04T08:16:22.000Z","size":66,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-18T10:04:04.651Z","etag":null,"topics":["keybindings","python","python3","sublime-text","sublime-text-3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/math2001.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-28T07:55:59.000Z","updated_at":"2017-07-31T11:53:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"0bb936d0-ee27-4136-8b3d-e5d23cb469ce","html_url":"https://github.com/math2001/kpymap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/math2001/kpymap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/math2001%2Fkpymap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/math2001%2Fkpymap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/math2001%2Fkpymap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/math2001%2Fkpymap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/math2001","download_url":"https://codeload.github.com/math2001/kpymap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/math2001%2Fkpymap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33098849,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["keybindings","python","python3","sublime-text","sublime-text-3"],"created_at":"2024-11-10T07:37:41.552Z","updated_at":"2026-05-16T10:33:33.764Z","avatar_url":"https://github.com/math2001.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kpymap\n\n\u003c!-- MarkdownTOC --\u003e\n\n- [API](#api)\n    - [`add(keys, command[, args][, context])`](#addkeys-command-args-context)\n    - [`get_context(key[, operator][, operand][, match_all])`](#get_contextkey-operator-operand-match_all)\n    - [`context(...)`](#context)\n    - [`get_option(option_name)`](#get_optionoption_name)\n    - [`set_option(option_name, option_value)`](#set_optionoption_name-option_value)\n- [Options](#options)\n- [Tip](#tip)\n    - [Encoding](#encoding)\n    - [No updates](#no-updates)\n- [Examples](#examples)\n    - [`with` block](#with-block)\n- [Installation](#installation)\n    - [Using package control](#using-package-control)\n    - [Using the command line](#using-the-command-line)\n\n\u003c!-- /MarkdownTOC --\u003e\n\n\nA simple API that allows you to write your Sublime Text keybindings in python.\n\nAll it does is provide you a tiny API to add keybindings and convert them into JSON (properly formated for sublime keybindings).\n\nAll you have to do is create python script (for example `kpymaper.py`) in your `User` folder, and add this boilerplate (it won't be written in the further examples):\n\n```python\nfrom kpymap import *\nreset()\n\n# code goes here\n\ngenerate()\n```\n\n**Watch out**: If you save this script, it'll overwrite your current keybindings. Make sure you make a copy of **before**.\n\nYou have access to the following functions:\n\n## API\n\n### `add(keys, command[, args][, context])`\n\nAdds a keybinding.\n\n- `keys` must be a list of **strings**\n- `command` must be a string\n- `args` (optional) a dict\n- `context` (optional) a context (you can get one using [`get_context`](#get_context)). It might also be a *list* of context\n\n### `get_context(key[, operator][, operand][, match_all])`\n\nThis allows you to get a context object, so that you can add it to a keybinding.\n\n- `key` must be a **string** or a **context** object (if it is, every other arguments will be ignored and returns the given context).\n- `operator` (optional) must be a **string**. Default: `equal`\n- `operand` (optional) any JSON serializable object. Default: `True`\n- `match_all` (optional) a boolean. Default: `False`\n\nNote: if only specify 2 arguments (such as `get_context('selector', 'source.python')`), the second argument will be understood as the **operand** and the operator will be set to `equal` (its default value)\n\n### `context(...)`\n\nIt takes the exact same arguments as [`get_context`](#get_context), but it implements a specific behaviour using `with` blocks. Every keybinding added (`add`) inside this block will have the the specified context(s). Of course, the others won't.\n\n### `get_option(option_name)`\n\nGets the value of the [option](#options) `option_name`. It has to be a string.\n\n### `set_option(option_name, option_value)`\n\nSet the [option](#options) `option_name` to `option_value`. `option_name` has to be a string.\n\n## Options\n\nHere are the available options:\n\n|        Option Name        | Type | Default |                    Description                     |\n|---------------------------|------|---------|----------------------------------------------------|\n| `match_all_default_value` | bool | `False` | the `match_all` `Context`'s argument default value |\n\n## Tip\n\n### Encoding\n\nIn order to make python work with unicodes and non-ascii characters, you can add this at the top of the `kpymaper.py`:\n\n```python\n# -*- encoding: utf-8 -*-\n```\n\nIt just tell python to use the `utf-8` encoding\n\n### No updates\n\nIf the changes you make don't seem to be applied, you might want to check in the console (`View → Show Console`).\n\nWhen a warning is printed into the console, a message will be printed in the status bar. Since a warning isn't notified in any other way for now, you should often check the status bar after saving your `kpymaper.py`, it might explain to you an unexpected behaviour.\n\nIf you think anything that seems like a bug to you, please [raise an issue](https://github.com/math2001/kpymaper/issues/new).\n\n## Examples\n\n### `with` block\n\n```python\n\n# You can set common contests using `with` block\nwith context('selector', 'source.python', True):\n    add('.', '.', 'insert', {'characters': 'self.'})\n    add('alt+f', 'fold_python_function')\n\n# or not\n\nadd('ctrl+u', 'upper_case')\n\n# You can nest some!\n\nwith context('selector', 'text.markdown.html', True):\n    with context('selection_empty', False):\n        add('`', 'insert_snippet', '`$SELECTION`')\n        add('*', 'insert_snippet', '*$SELECTION*')\n\n    add('*', 'move', {'forward': True, 'by': 'characters'},\n        get_context('regex_contains', '^*', True))\n    add('`', 'move', {'forward': True, 'by': 'characters'},\n        get_context('regex_contains', '^`', True))\n\n# or add more than one context using one `with` statement\n\nwith context('setting.save_on_focus_lost'), \\\n     context('setting.learning_mode'):\n     add('ctrl+s', 'message_dialog',\n         {'message': 'Stop using ctrl+s, Sublime Text saves automatically for you'})\n\n```\n\nGives:\n\n```json\n[\n    {\n        \"keys\": [\".\", \".\"],\n        \"command\": \"insert\",\n        \"args\": {\n            \"characters\": \"self.\"\n        },\n        \"context\": [\n            {\"key\": \"selector\", \"operand\": \"source.python\", \"match_all\": true}\n        ]\n    },\n    {\n        \"keys\": [\"alt+f\"],\n        \"command\": \"fold_python_function\",\n        \"context\": [\n            {\"key\": \"selector\", \"operand\": \"source.python\", \"match_all\": true}\n        ]\n    },\n    {\n        \"keys\": [\"ctrl+u\"],\n        \"command\": \"upper_case\"\n    },\n    {\n        \"keys\": [\"`\"],\n        \"command\": \"insert_snippet\",\n        \"args\": {\n            \"contents\": \"`$SELECTION`\"\n        },\n        \"context\": [\n            {\"key\": \"selector\", \"operand\": \"text.markdown.html\", \"match_all\": true},\n            {\"key\": \"selection_empty\"}\n        ]\n    },\n    {\n        \"keys\": [\"*\"],\n        \"command\": \"insert_snippet\",\n        \"args\": {\n            \"contents\": \"*$SELECTION*\"\n        },\n        \"context\": [\n            {\"key\": \"selector\", \"operand\": \"text.markdown.html\", \"match_all\": true},\n            {\"key\": \"selection_empty\"}\n        ]\n    },\n    {\n        \"keys\": [\"*\"],\n        \"command\": \"move\",\n        \"args\": {\n            \"by\": \"characters\", \n            \"forward\": true\n        },\n        \"context\": [\n            {\"key\": \"selector\", \"operand\": \"text.markdown.html\", \"match_all\": true},\n            {\"key\": \"regex_contains\", \"operand\": \"^*\", \"match_all\": true}\n        ]\n    },\n    {\n        \"keys\": [\"`\"],\n        \"command\": \"move\",\n        \"args\": {\n            \"by\": \"characters\", \n            \"forward\": true\n        },\n        \"context\": [\n            {\"key\": \"selector\", \"operand\": \"text.markdown.html\", \"match_all\": true},\n            {\"key\": \"regex_contains\", \"operand\": \"^`\", \"match_all\": true}\n        ]\n    },\n    {\n        \"keys\": [\"ctrl+s\"],\n        \"command\": \"message_dialog\",\n        \"args\": {\n            \"message\": \"Stop using ctrl+s, Sublime Text saves automatically for you\"\n        },\n        \"context\": [\n            {\"key\": \"setting.save_on_focus_lost\"},\n            {\"key\": \"setting.learning_mode\"}\n        ]\n    }\n]\n```\n\n## Installation\n\nBecause it is not available on package control for now, you have to add this repo \"manually\" to your list.\n\n### Using package control\n\n1. Open up the command palette (\u003ckbd\u003ectrl+shift+p\u003c/kbd\u003e), and find `Package Control: Add Repository`. Then enter the URL of this repo: `https://github.com/math2001/kpymap` in the input field.\n2. Open up the command palette again and find `Package Control: Install Package`, and just search for `kpymap`. (just a normal install)\n\n### Using the command line\n\n```bash\ncd \"%APPDATA%\\Sublime Text 3\\Packages\"             # on window\ncd ~/Library/Application\\ Support/Sublime\\ Text\\ 3 # on mac\ncd ~/.config/sublime-text-3                        # on linux\n\ngit clone \"https://github.com/math2001/kpymap\"\n```\n\n\u003e Which solution do I choose?\n\nIt depends of your needs:\n\n- If you intend to just use kpymap, then pick the first solution (Package Control), **you'll get automatic update**.\n- On the opposite side, if you want to tweak it, use the second solution. Note that, to get updates, you'll have to `git pull`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmath2001%2Fkpymap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmath2001%2Fkpymap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmath2001%2Fkpymap/lists"}