on master help sign in
Add window mode
8c2fa12Ivan Tham
book/src/keymap.md+12−3
@@ -24,13 +24,13 @@
24| PageDown | Move page down |
24| PageDown | Move page down |
25| ctrl-u | Move half page up |
25| ctrl-u | Move half page up |
26| ctrl-d | Move half page down |
26| ctrl-d | Move half page down |
27−| Tab | Switch to next view |
28| ctrl-i | Jump forward on the jumplist TODO: conflicts tab |
27| ctrl-i | Jump forward on the jumplist TODO: conflicts tab |
29| ctrl-o | Jump backward on the jumplist |
28| ctrl-o | Jump backward on the jumplist |
30| v | Enter select (extend) mode |
29| v | Enter select (extend) mode |
31| g | Enter goto mode |
30| g | Enter goto mode |
32| : | Enter command mode |
31| : | Enter command mode |
33| z | Enter view mode |
32| z | Enter view mode |
33+| ctrl-w | Enter window mode |
34| space | Enter space mode |
34| space | Enter space mode |
35| K | Show documentation for the item under the cursor |
35| K | Show documentation for the item under the cursor |
36
36
@@ -132,6 +132,17 @@ Jumps to various locations.
132
132
133TODO: Mappings for selecting syntax nodes (a superset of `[`).
133TODO: Mappings for selecting syntax nodes (a superset of `[`).
134
134
135+## Window mode
136+
137+This layer is similar to vim keybindings as kakoune does not support window.
138+
139+| Key | Description |
140+|-----|-------------|
141+| w, ctrl-w | Switch to next window |
142+| v, ctrl-v | Vertical right split |
143+| h, ctrl-h | Horizontal bottom split |
144+| q, ctrl-q | Close current window |
145+
135## Space mode
146## Space mode
136
147
137This layer is a kludge of mappings I had under leader key in neovim.
148This 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.
140|-----|-----------|
151|-----|-----------|
141| f | Open file picker |
152| f | Open file picker |
142| b | Open buffer picker |
153| b | Open buffer picker |
143−| v | Open a new vertical split into the current file |
144| w | Save changes to file |
154| w | Save changes to file |
145−| c | Close the current split |
146| space | Keep primary selection TODO: it's here because space mode replaced it |
155| space | Keep primary selection TODO: it's here because space mode replaced it |
helix-term/src/commands.rs+39−14
@@ -2240,11 +2240,6 @@ pub fn hover(cx: &mut Context) {
2240 );
2240 );
2241}
2241}
2242
2242
2243−// view movements
2244−pub fn next_view(cx: &mut Context) {
2245− cx.editor.focus_next()
2246−}
2247−
2248// comments
2243// comments
2249pub fn toggle_comments(cx: &mut Context) {
2244pub fn toggle_comments(cx: &mut Context) {
2250 let (view, doc) = cx.current();
2245 let (view, doc) = cx.current();
@@ -2308,16 +2303,38 @@ pub fn jump_backward(cx: &mut Context) {
2308 };
2303 };
2309}
2304}
2310
2305
2311−//
2306+pub fn window_mode(cx: &mut Context) {
2307+ cx.on_next_key(move |cx, event| {
2308+ if let KeyEvent {
2309+ code: KeyCode::Char(ch),
2310+ ..
2311+ } = event
2312+ {
2313+ match ch {
2314+ 'w' => rotate_view(cx),
2315+ 'h' => hsplit(cx),
2316+ 'v' => vsplit(cx),
2317+ 'q' => wclose(cx),
2318+ _ => {}
2319+ }
2320+ }
2321+ })
2322+}
2312
2323
2313−pub fn vsplit(cx: &mut Context) {
2324+pub fn rotate_view(cx: &mut Context) {
2325+ cx.editor.focus_next()
2326+}
2327+
2328+// split helper, clear it later
2329+use helix_view::editor::Action;
2330+fn split(cx: &mut Context, action: Action) {
2314 use helix_view::editor::Action;
2331 use helix_view::editor::Action;
2315 let (view, doc) = cx.current();
2332 let (view, doc) = cx.current();
2316 let id = doc.id();
2333 let id = doc.id();
2317 let selection = doc.selection(view.id).clone();
2334 let selection = doc.selection(view.id).clone();
2318 let first_line = view.first_line;
2335 let first_line = view.first_line;
2319
2336
2320− cx.editor.switch(id, Action::VerticalSplit);
2337+ cx.editor.switch(id, action);
2321
2338
2322 // match the selection in the previous view
2339 // match the selection in the previous view
2323 let (view, doc) = cx.current();
2340 let (view, doc) = cx.current();
@@ -2325,6 +2342,20 @@ pub fn vsplit(cx: &mut Context) {
2325 doc.set_selection(view.id, selection);
2342 doc.set_selection(view.id, selection);
2326}
2343}
2327
2344
2345+pub fn hsplit(cx: &mut Context) {
2346+ split(cx, Action::HorizontalSplit);
2347+}
2348+
2349+pub fn vsplit(cx: &mut Context) {
2350+ split(cx, Action::VerticalSplit);
2351+}
2352+
2353+pub fn wclose(cx: &mut Context) {
2354+ let view_id = cx.view().id;
2355+ // close current split
2356+ cx.editor.close(view_id, /* close_buffer */ false);
2357+}
2358+
2328pub fn space_mode(cx: &mut Context) {
2359pub fn space_mode(cx: &mut Context) {
2329 cx.on_next_key(move |cx, event| {
2360 cx.on_next_key(move |cx, event| {
2330 if let KeyEvent {
2361 if let KeyEvent {
@@ -2336,18 +2367,12 @@ pub fn space_mode(cx: &mut Context) {
2336 match ch {
2367 match ch {
2337 'f' => file_picker(cx),
2368 'f' => file_picker(cx),
2338 'b' => buffer_picker(cx),
2369 'b' => buffer_picker(cx),
2339− 'v' => vsplit(cx),
2340 'w' => {
2370 'w' => {
2341 // save current buffer
2371 // save current buffer
2342 let (view, doc) = cx.current();
2372 let (view, doc) = cx.current();
2343 doc.format(view.id); // TODO: merge into save
2373 doc.format(view.id); // TODO: merge into save
2344 tokio::spawn(doc.save());
2374 tokio::spawn(doc.save());
2345 }
2375 }
2346− 'c' => {
2347− let view_id = cx.view().id;
2348− // close current split
2349− cx.editor.close(view_id, /* close_buffer */ false);
2350− }
2351 // ' ' => toggle_alternate_buffer(cx),
2376 // ' ' => toggle_alternate_buffer(cx),
2352 // TODO: temporary since space mode took it's old key
2377 // TODO: temporary since space mode took it's old key
2353 ' ' => keep_primary_selection(cx),
2378 ' ' => keep_primary_selection(cx),
helix-term/src/keymap.rs+1−4
@@ -264,10 +264,7 @@ pub fn default() -> Keymaps {
264 ctrl!('u') => commands::half_page_up,
264 ctrl!('u') => commands::half_page_up,
265 ctrl!('d') => commands::half_page_down,
265 ctrl!('d') => commands::half_page_down,
266
266
267− KeyEvent {
267+ ctrl!('w') => commands::window_mode,
268− code: KeyCode::Tab,
269− modifiers: KeyModifiers::NONE
270− } => commands::next_view,
271
268
272 // move under <space>c
269 // move under <space>c
273 ctrl!('c') => commands::toggle_comments,
270 ctrl!('c') => commands::toggle_comments,