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

Add keybinds for toggling common settings #3309

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 28 additions & 24 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,30 +251,34 @@ This layer is similar to vim keybindings as kakoune does not support window.

#### Space mode

This layer is a kludge of mappings, mostly pickers.


| Key | Description | Command |
| ----- | ----------- | ------- |
| `f` | Open file picker | `file_picker` |
| `b` | Open buffer picker | `buffer_picker` |
| `j` | Open jumplist picker | `jumplist_picker` |
| `k` | Show documentation for item under cursor in a [popup](#popup) (**LSP**) | `hover` |
| `s` | Open document symbol picker (**LSP**) | `symbol_picker` |
| `S` | Open workspace symbol picker (**LSP**) | `workspace_symbol_picker` |
| `g` | Open document diagnostics picker (**LSP**) | `diagnostics_picker` |
| `G` | Open workspace diagnostics picker (**LSP**) | `workspace_diagnostics_picker`
| `r` | Rename symbol (**LSP**) | `rename_symbol` |
| `a` | Apply code action (**LSP**) | `code_action` |
| `'` | Open last fuzzy picker | `last_picker` |
| `w` | Enter [window mode](#window-mode) | N/A |
| `p` | Paste system clipboard after selections | `paste_clipboard_after` |
| `P` | Paste system clipboard before selections | `paste_clipboard_before` |
| `y` | Join and yank selections to clipboard | `yank_joined_to_clipboard` |
| `Y` | Yank main selection to clipboard | `yank_main_selection_to_clipboard` |
| `R` | Replace selections by clipboard contents | `replace_selections_with_clipboard` |
| `/` | Global search in workspace folder | `global_search` |
| `?` | Open command palette | `command_palette` |
This layer contains high-level commands like pickers, some LSP/DAP operations,
clipboard interaction, window management and other miscellaneous commands.

| Key | Description | Command |
| ----- | ----------- | ------- |
| `f` | Open file picker | `file_picker` |
| `F` | Open file picker at current working directory | `file_picker_in_current_directory` |
| `b` | Open buffer picker | `buffer_picker` |
| `j` | Open jumplist picker | `jumplist_picker` |
| `s` | Open document symbol picker (**LSP**) | `symbol_picker` |
| `S` | Open workspace symbol picker (**LSP**) | `workspace_symbol_picker` |
| `g` | Open document diagnostics picker (**LSP**) | `diagnostics_picker` |
| `G` | Open workspace diagnostics picker (**LSP**) | `workspace_diagnostics_picker` |
| `a` | Apply code action (**LSP**) | `code_action` |
| `'` | Open last fuzzy picker | `last_picker` |
| `d` | Debug (experimental) | N/A |
| `w` | Enter [window mode](#window-mode) | N/A |
| `y` | Join and yank selections to clipboard | `yank_joined_to_clipboard` |
| `Y` | Yank main selection to clipboard | `yank_main_selection_to_clipboard` |
| `p` | Paste system clipboard after selections | `paste_clipboard_after` |
| `P` | Paste system clipboard before selections | `paste_clipboard_before` |
| `R` | Replace selections by clipboard contents | `replace_selections_with_clipboard` |
| `t` | Toggle setting | `toggle_setting` |
| `/` | Global search in workspace folder | `global_search` |
| `k` | Show documentation for item under cursor in a [popup](#popup) (**LSP**) | `hover` |
| `r` | Rename symbol (**LSP**) | `rename_symbol` |
| `h` | Select symbol references (**LSP**) | `select_references_to_symbol_under_cursor` |
| `?` | Open command palette | `command_palette` |

> TIP: Global search displays results in a fuzzy picker, use `space + '` to bring it back up after opening a file.

Expand Down
83 changes: 83 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ impl MappableCommand {
record_macro, "Record macro",
replay_macro, "Replay macro",
command_palette, "Open command palette",
toggle_setting, "Toggle setting",
);
}

Expand Down Expand Up @@ -4845,3 +4846,85 @@ fn replay_macro(cx: &mut Context) {
cx.editor.macro_replaying.pop();
}));
}

fn toggle_setting(cx: &mut Context) {
cx.on_next_key(move |cx, event| {
use helix_view::editor::ConfigEvent;

cx.editor.autoinfo = None;
cx.editor.pseudo_pending = None;

if let Some(ch) = event.char() {
let mut config = cx.editor.config().clone();

match ch {
'w' => {
use helix_view::editor::{
WhitespaceRender::Basic, WhitespaceRenderValue::All,
WhitespaceRenderValue::None,
};

config.whitespace.render = match config.whitespace.render {
Basic(None) => Basic(All),
_ => Basic(None),
};
}
'i' => config.indent_guides.render = !config.indent_guides.render,
'c' => config.cursorline = !config.cursorline,
'r' => {
config.rulers = if config.rulers.is_empty() {
vec![80]
} else {
vec![]
};
}
'p' => {
use helix_core::syntax::AutoPairConfig::Enable;

config.auto_pairs = match config.auto_pairs {
Enable(false) => Enable(true),
_ => Enable(false),
}
}
'l' => {
use helix_view::editor::LineNumber::{Absolute, Relative};

config.line_number = match config.line_number {
Absolute => Relative,
Relative => Absolute,
};
}
_ => cx.editor.set_error(format!("Unknown setting '{}'", ch)),
}

if cx
.editor
.config_events
.0
.send(ConfigEvent::Update(Box::new(config)))
.is_err()
{
cx.editor
.set_error(format!("Failed to update setting '{}'", ch));
}
}
});

let help_text = [
("w", "Whitespace (visible, invisible)"),
("i", "Indent guides (on, off)"),
("c", "Cursorline (on, off)"),
("r", "Ruler (80 columns, none)"),
("p", "Auto-pairs (on, off)"),
("l", "Line-number (absolute, relative)"),
];

cx.editor.autoinfo = Some(Info::new(
"Toggle setting",
help_text
.into_iter()
.map(|(col1, col2)| (col1.to_string(), col2.to_string()))
.collect(),
));
cx.editor.pseudo_pending = Some("<space>t".to_string());
}
1 change: 1 addition & 0 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"p" => paste_clipboard_after,
"P" => paste_clipboard_before,
"R" => replace_selections_with_clipboard,
"t" => toggle_setting,
"/" => global_search,
"k" => hover,
"r" => rename_symbol,
Expand Down