on master help sign in
Add horizontal and vertical split scratch buffers (#1763)

Make subcommand name more descriptive Fix vsplit completer Run cargo xtask docgen

commitc0dbd6dc3f147b46d4352ac78903a7a70741cfd9 authorJoe <Josephharrisonlim@gmail.com> dateSun 13 Mar 2022, 22:47 (5 years ago) parent85492e5
4 files changed+54
book/src/generated/typable-cmd.md+2 helix-term/src/commands.rs+10 helix-term/src/commands/typed.rs+34 helix-term/src/keymap.rs+8
book/src/generated/typable-cmd.md+2
@@ -46,7 +46,9 @@
4646| `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. |
4747| `:debug-eval` | Evaluate expression in current debug context. |
4848| `:vsplit`, `:vs` | Open the file in a vertical split. |
49+| `:vsplit-new`, `:vnew` | Open a scratch buffer in a vertical split. |
4950| `:hsplit`, `:hs`, `:sp` | Open the file in a horizontal split. |
51+| `:hsplit-new`, `:hnew` | Open a scratch buffer in a horizontal split. |
5052| `:tutor` | Open the tutorial. |
5153| `:goto`, `:g` | Go to line number. |
5254| `:set-option`, `:set` | Set a config option at runtime |
helix-term/src/commands.rs+10
@@ -380,7 +380,9 @@ impl MappableCommand {
380380 jump_view_down, "Jump to the split below",
381381 rotate_view, "Goto next window",
382382 hsplit, "Horizontal bottom split",
383+ hsplit_new, "Horizontal bottom split scratch buffer",
383384 vsplit, "Vertical right split",
385+ vsplit_new, "Vertical right split scratch buffer",
384386 wclose, "Close window",
385387 wonly, "Current window only",
386388 select_register, "Select register",
@@ -3794,10 +3796,18 @@ fn hsplit(cx: &mut Context) {
37943796 split(cx, Action::HorizontalSplit);
37953797}
37963798
3799+fn hsplit_new(cx: &mut Context) {
3800+ cx.editor.new_file(Action::HorizontalSplit);
3801+}
3802+
37973803fn vsplit(cx: &mut Context) {
37983804 split(cx, Action::VerticalSplit);
37993805}
38003806
3807+fn vsplit_new(cx: &mut Context) {
3808+ cx.editor.new_file(Action::VerticalSplit);
3809+}
3810+
38013811fn wclose(cx: &mut Context) {
38023812 if cx.editor.tree.views().count() == 1 {
38033813 if let Err(err) = typed::buffers_remaining_impl(cx.editor) {
helix-term/src/commands/typed.rs+34
@@ -771,6 +771,26 @@ fn hsplit(
771771 Ok(())
772772}
773773
774+fn vsplit_new(
775+ cx: &mut compositor::Context,
776+ _args: &[Cow<str>],
777+ _event: PromptEvent,
778+) -> anyhow::Result<()> {
779+ cx.editor.new_file(Action::VerticalSplit);
780+
781+ Ok(())
782+}
783+
784+fn hsplit_new(
785+ cx: &mut compositor::Context,
786+ _args: &[Cow<str>],
787+ _event: PromptEvent,
788+) -> anyhow::Result<()> {
789+ cx.editor.new_file(Action::HorizontalSplit);
790+
791+ Ok(())
792+}
793+
774794fn debug_eval(
775795 cx: &mut compositor::Context,
776796 args: &[Cow<str>],
@@ -1293,6 +1313,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
12931313 fun: vsplit,
12941314 completer: Some(completers::filename),
12951315 },
1316+ TypableCommand {
1317+ name: "vsplit-new",
1318+ aliases: &["vnew"],
1319+ doc: "Open a scratch buffer in a vertical split.",
1320+ fun: vsplit_new,
1321+ completer: None,
1322+ },
12961323 TypableCommand {
12971324 name: "hsplit",
12981325 aliases: &["hs", "sp"],
@@ -1300,6 +1327,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
13001327 fun: hsplit,
13011328 completer: Some(completers::filename),
13021329 },
1330+ TypableCommand {
1331+ name: "hsplit-new",
1332+ aliases: &["hnew"],
1333+ doc: "Open a scratch buffer in a horizontal split.",
1334+ fun: hsplit_new,
1335+ completer: None,
1336+ },
13031337 TypableCommand {
13041338 name: "tutor",
13051339 aliases: &[],
helix-term/src/keymap.rs+8
@@ -682,6 +682,10 @@ impl Default for Keymaps {
682682 "C-j" | "j" | "down" => jump_view_down,
683683 "C-k" | "k" | "up" => jump_view_up,
684684 "C-l" | "l" | "right" => jump_view_right,
685+ "n" => { "New split scratch buffer"
686+ "C-s" | "s" => hsplit_new,
687+ "C-v" | "v" => vsplit_new,
688+ },
685689 },
686690
687691 // move under <space>c
@@ -732,6 +736,10 @@ impl Default for Keymaps {
732736 "C-j" | "j" | "down" => jump_view_down,
733737 "C-k" | "k" | "up" => jump_view_up,
734738 "C-l" | "l" | "right" => jump_view_right,
739+ "n" => { "New split scratch buffer"
740+ "C-s" | "s" => hsplit_new,
741+ "C-v" | "v" => vsplit_new,
742+ },
735743 },
736744 "y" => yank_joined_to_clipboard,
737745 "Y" => yank_main_selection_to_clipboard,