aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--book/src/keymap.md15
-rw-r--r--helix-term/src/commands.rs53
-rw-r--r--helix-term/src/keymap.rs5
3 files changed, 52 insertions, 21 deletions
diff --git a/book/src/keymap.md b/book/src/keymap.md
index 003d0845..844938ec 100644
--- a/book/src/keymap.md
+++ b/book/src/keymap.md
@@ -24,13 +24,13 @@
| PageDown | Move page down |
| ctrl-u | Move half page up |
| ctrl-d | Move half page down |
-| Tab | Switch to next view |
| ctrl-i | Jump forward on the jumplist TODO: conflicts tab |
| ctrl-o | Jump backward on the jumplist |
| v | Enter select (extend) mode |
| g | Enter goto mode |
| : | Enter command mode |
| z | Enter view mode |
+| ctrl-w | Enter window mode |
| space | Enter space mode |
| K | Show documentation for the item under the cursor |
@@ -132,6 +132,17 @@ Jumps to various locations.
TODO: Mappings for selecting syntax nodes (a superset of `[`).
+## Window mode
+
+This layer is similar to vim keybindings as kakoune does not support window.
+
+| Key | Description |
+|-----|-------------|
+| w, ctrl-w | Switch to next window |
+| v, ctrl-v | Vertical right split |
+| h, ctrl-h | Horizontal bottom split |
+| q, ctrl-q | Close current window |
+
## Space mode
This layer is a kludge of mappings I had under leader key in neovim.
@@ -140,7 +151,5 @@ This layer is a kludge of mappings I had under leader key in neovim.
|-----|-----------|
| f | Open file picker |
| b | Open buffer picker |
-| v | Open a new vertical split into the current file |
| w | Save changes to file |
-| c | Close the current split |
| space | Keep primary selection TODO: it's here because space mode replaced it |
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index bff102dc..c88a5eee 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2240,11 +2240,6 @@ pub fn hover(cx: &mut Context) {
);
}
-// view movements
-pub fn next_view(cx: &mut Context) {
- cx.editor.focus_next()
-}
-
// comments
pub fn toggle_comments(cx: &mut Context) {
let (view, doc) = cx.current();
@@ -2308,16 +2303,38 @@ pub fn jump_backward(cx: &mut Context) {
};
}
-//
+pub fn window_mode(cx: &mut Context) {
+ cx.on_next_key(move |cx, event| {
+ if let KeyEvent {
+ code: KeyCode::Char(ch),
+ ..
+ } = event
+ {
+ match ch {
+ 'w' => rotate_view(cx),
+ 'h' => hsplit(cx),
+ 'v' => vsplit(cx),
+ 'q' => wclose(cx),
+ _ => {}
+ }
+ }
+ })
+}
-pub fn vsplit(cx: &mut Context) {
+pub fn rotate_view(cx: &mut Context) {
+ cx.editor.focus_next()
+}
+
+// split helper, clear it later
+use helix_view::editor::Action;
+fn split(cx: &mut Context, action: Action) {
use helix_view::editor::Action;
let (view, doc) = cx.current();
let id = doc.id();
let selection = doc.selection(view.id).clone();
let first_line = view.first_line;
- cx.editor.switch(id, Action::VerticalSplit);
+ cx.editor.switch(id, action);
// match the selection in the previous view
let (view, doc) = cx.current();
@@ -2325,6 +2342,20 @@ pub fn vsplit(cx: &mut Context) {
doc.set_selection(view.id, selection);
}
+pub fn hsplit(cx: &mut Context) {
+ split(cx, Action::HorizontalSplit);
+}
+
+pub fn vsplit(cx: &mut Context) {
+ split(cx, Action::VerticalSplit);
+}
+
+pub fn wclose(cx: &mut Context) {
+ let view_id = cx.view().id;
+ // close current split
+ cx.editor.close(view_id, /* close_buffer */ false);
+}
+
pub fn space_mode(cx: &mut Context) {
cx.on_next_key(move |cx, event| {
if let KeyEvent {
@@ -2336,18 +2367,12 @@ pub fn space_mode(cx: &mut Context) {
match ch {
'f' => file_picker(cx),
'b' => buffer_picker(cx),
- 'v' => vsplit(cx),
'w' => {
// save current buffer
let (view, doc) = cx.current();
doc.format(view.id); // TODO: merge into save
tokio::spawn(doc.save());
}
- 'c' => {
- let view_id = cx.view().id;
- // close current split
- cx.editor.close(view_id, /* close_buffer */ false);
- }
// ' ' => toggle_alternate_buffer(cx),
// TODO: temporary since space mode took it's old key
' ' => keep_primary_selection(cx),
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index 7376cd03..e51dfbc5 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -264,10 +264,7 @@ pub fn default() -> Keymaps {
ctrl!('u') => commands::half_page_up,
ctrl!('d') => commands::half_page_down,
- KeyEvent {
- code: KeyCode::Tab,
- modifiers: KeyModifiers::NONE
- } => commands::next_view,
+ ctrl!('w') => commands::window_mode,
// move under <space>c
ctrl!('c') => commands::toggle_comments,