Skip to content

Commit

Permalink
Configurable keys 2 (Mapping keys to commands) (#268)
Browse files Browse the repository at this point in the history
* Add convenience/clarity wrapper for Range initialization

* Add keycode parse and display methods

* Add remapping functions and tests

* Implement key remapping

* Add remapping book entry

* Use raw string literal for toml

* Add command constants

* Make command functions private

* Map directly to commands

* Match key parsing/displaying to Kakoune

* Formatting pass

* Update documentation

* Formatting

* Fix example in the book

* Refactor into single config file

* Formatting

* Refactor configuration and add keymap newtype wrappers

* Address first batch of PR comments

* Replace FromStr with custom deserialize
  • Loading branch information
PabloMansanet committed Jun 17, 2021
1 parent 47d2e3a commit f7e00cf
Show file tree
Hide file tree
Showing 10 changed files with 928 additions and 340 deletions.
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- [Usage](./usage.md)
- [Configuration](./configuration.md)
- [Keymap](./keymap.md)
- [Key Remapping](./remapping.md)
- [Hooks](./hooks.md)
48 changes: 48 additions & 0 deletions book/src/remapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Key Remapping

One-way key remapping is temporarily supported via a simple TOML configuration
file. (More powerful solutions such as rebinding via commands will be
available in the feature).

To remap keys, write a `config.toml` file in your `helix` configuration
directory (default `~/.config/helix` in Linux systems) with a structure like
this:

```toml
# At most one section each of 'keys.normal', 'keys.insert' and 'keys.select'
[keys.normal]
a = "move_char_left" # Maps the 'a' key to the move_char_left command
w = "move_line_up" # Maps the 'w' key move_line_up
C-S-esc = "select_line" # Maps Control-Shift-Escape to select_line

[keys.insert]
A-x = "normal_mode" # Maps Alt-X to enter normal mode
```

Control, Shift and Alt modifiers are encoded respectively with the prefixes
`C-`, `S-` and `A-`. Special keys are encoded as follows:

* Backspace => "backspace"
* Space => "space"
* Return/Enter => "ret"
* < => "lt"
* > => "gt"
* + => "plus"
* - => "minus"
* ; => "semicolon"
* % => "percent"
* Left => "left"
* Right => "right"
* Up => "up"
* Home => "home"
* End => "end"
* Page Up => "pageup"
* Page Down => "pagedown"
* Tab => "tab"
* Back Tab => "backtab"
* Delete => "del"
* Insert => "ins"
* Null => "null"
* Escape => "esc"

Commands can be found in the source code at `../../helix-term/src/commands.rs`
7 changes: 4 additions & 3 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use helix_lsp::lsp;
use helix_view::{document::Mode, Document, Editor, Theme, View};

use crate::{args::Args, compositor::Compositor, ui};
use crate::{args::Args, compositor::Compositor, config::Config, keymap::Keymaps, ui};

use log::{error, info};

Expand Down Expand Up @@ -40,13 +40,14 @@ pub struct Application {
}

impl Application {
pub fn new(mut args: Args) -> Result<Self, Error> {
pub fn new(mut args: Args, config: Config) -> Result<Self, Error> {
use helix_view::editor::Action;
let mut compositor = Compositor::new()?;
let size = compositor.size();
let mut editor = Editor::new(size);

compositor.push(Box::new(ui::EditorView::new()));
let mut editor_view = Box::new(ui::EditorView::new(config.keymaps));
compositor.push(editor_view);

if !args.files.is_empty() {
let first = &args.files[0]; // we know it's not empty
Expand Down
Loading

0 comments on commit f7e00cf

Please sign in to comment.