Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable keys 2 (Mapping keys to commands) #268

Merged
merged 24 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0ac3ad7
Add convenience/clarity wrapper for Range initialization
PabloMansanet Jun 7, 2021
d1cbc82
Merge branch 'master' of https://github.com/helix-editor/helix
PabloMansanet Jun 11, 2021
c01981c
Add keycode parse and display methods
PabloMansanet Jun 12, 2021
104b422
Add remapping functions and tests
PabloMansanet Jun 12, 2021
815cfd6
Implement key remapping
PabloMansanet Jun 12, 2021
d99b606
Add remapping book entry
PabloMansanet Jun 12, 2021
d7e0f66
Use raw string literal for toml
PabloMansanet Jun 12, 2021
cbb3b0f
Merge remote-tracking branch 'upstream/master' into ConfigurableKeymap
PabloMansanet Jun 14, 2021
8460780
Add command constants
PabloMansanet Jun 14, 2021
da47069
Make command functions private
PabloMansanet Jun 14, 2021
f336d09
Map directly to commands
PabloMansanet Jun 14, 2021
2cd3a7c
Match key parsing/displaying to Kakoune
PabloMansanet Jun 14, 2021
0fdbd11
Formatting pass
PabloMansanet Jun 14, 2021
feda589
Merge remote-tracking branch 'upstream/master' into ConfigurableKeymap
PabloMansanet Jun 14, 2021
818978b
Update documentation
PabloMansanet Jun 14, 2021
26211d0
Formatting
PabloMansanet Jun 14, 2021
e86cc8f
Merge remote-tracking branch 'upstream/master' into ConfigurableKeymap
PabloMansanet Jun 15, 2021
d47c7ba
Fix example in the book
PabloMansanet Jun 15, 2021
9e57822
Refactor into single config file
PabloMansanet Jun 15, 2021
4c6fa7c
Formatting
PabloMansanet Jun 15, 2021
5a096e4
Refactor configuration and add keymap newtype wrappers
PabloMansanet Jun 15, 2021
41792a2
Address first batch of PR comments
PabloMansanet Jun 17, 2021
3211056
Replace FromStr with custom deserialize
PabloMansanet Jun 17, 2021
dd1daed
Merge remote-tracking branch 'upstream/master' into ConfigurableKeymap
PabloMansanet Jun 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back tab?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are valid key codes, originating back to early IBM computers ¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about focus in and focus out available in kakoune?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... I didn't even know focus in/out was information you could get inside a terminal. Relevant link:
https://unix.stackexchange.com/a/480138

That would be pretty cool to be able to bind to commands. Then you could auto-save all files on focus-out, for example.

(Although, long-term a proper auto-save feature will be better for that, of course.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem like Crossterm offers primitives for that, but it does sound interesting! Probably outside of the scope of this PR though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't think it's widely supported or anything, just interesting trivia about old features :)

* Delete => "del"
* Insert => "ins"
* Null => "null"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure what this is, I'm just transcribing the underlying Crossterm KeyEvent API as well as I can. I think this is a way of expressing "no key".

* 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