on master help sign in
Add horizontal and vertical split scratch buffers (#1763)
c0dbd6dJoe
book/src/generated/typable-cmd.md+2
@@ -46,7 +46,9 @@
46| `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. |
46| `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. |
47| `:debug-eval` | Evaluate expression in current debug context. |
47| `:debug-eval` | Evaluate expression in current debug context. |
48| `:vsplit`, `:vs` | Open the file in a vertical split. |
48| `:vsplit`, `:vs` | Open the file in a vertical split. |
49+| `:vsplit-new`, `:vnew` | Open a scratch buffer in a vertical split. |
49| `:hsplit`, `:hs`, `:sp` | Open the file in a horizontal split. |
50| `:hsplit`, `:hs`, `:sp` | Open the file in a horizontal split. |
51+| `:hsplit-new`, `:hnew` | Open a scratch buffer in a horizontal split. |
50| `:tutor` | Open the tutorial. |
52| `:tutor` | Open the tutorial. |
51| `:goto`, `:g` | Go to line number. |
53| `:goto`, `:g` | Go to line number. |
52| `:set-option`, `:set` | Set a config option at runtime |
54| `:set-option`, `:set` | Set a config option at runtime |
helix-term/src/commands.rs+10
@@ -380,7 +380,9 @@ impl MappableCommand {
380 jump_view_down, "Jump to the split below",
380 jump_view_down, "Jump to the split below",
381 rotate_view, "Goto next window",
381 rotate_view, "Goto next window",
382 hsplit, "Horizontal bottom split",
382 hsplit, "Horizontal bottom split",
383+ hsplit_new, "Horizontal bottom split scratch buffer",
383 vsplit, "Vertical right split",
384 vsplit, "Vertical right split",
385+ vsplit_new, "Vertical right split scratch buffer",
384 wclose, "Close window",
386 wclose, "Close window",
385 wonly, "Current window only",
387 wonly, "Current window only",
386 select_register, "Select register",
388 select_register, "Select register",
@@ -3794,10 +3796,18 @@ fn hsplit(cx: &mut Context) {
3794 split(cx, Action::HorizontalSplit);
3796 split(cx, Action::HorizontalSplit);
3795}
3797}
3796
3798
3799+fn hsplit_new(cx: &mut Context) {
3800+ cx.editor.new_file(Action::HorizontalSplit);
3801+}
3802+
3797fn vsplit(cx: &mut Context) {
3803fn vsplit(cx: &mut Context) {
3798 split(cx, Action::VerticalSplit);
3804 split(cx, Action::VerticalSplit);
3799}
3805}
3800
3806
3807+fn vsplit_new(cx: &mut Context) {
3808+ cx.editor.new_file(Action::VerticalSplit);
3809+}
3810+
3801fn wclose(cx: &mut Context) {
3811fn wclose(cx: &mut Context) {
3802 if cx.editor.tree.views().count() == 1 {
3812 if cx.editor.tree.views().count() == 1 {
3803 if let Err(err) = typed::buffers_remaining_impl(cx.editor) {
3813 if let Err(err) = typed::buffers_remaining_impl(cx.editor) {
helix-term/src/commands/typed.rs+34
@@ -771,6 +771,26 @@ fn hsplit(
771 Ok(())
771 Ok(())
772}
772}
773
773
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+
774fn debug_eval(
794fn debug_eval(
775 cx: &mut compositor::Context,
795 cx: &mut compositor::Context,
776 args: &[Cow<str>],
796 args: &[Cow<str>],
@@ -1293,6 +1313,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1293 fun: vsplit,
1313 fun: vsplit,
1294 completer: Some(completers::filename),
1314 completer: Some(completers::filename),
1295 },
1315 },
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+ },
1296 TypableCommand {
1323 TypableCommand {
1297 name: "hsplit",
1324 name: "hsplit",
1298 aliases: &["hs", "sp"],
1325 aliases: &["hs", "sp"],
@@ -1300,6 +1327,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1300 fun: hsplit,
1327 fun: hsplit,
1301 completer: Some(completers::filename),
1328 completer: Some(completers::filename),
1302 },
1329 },
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+ },
1303 TypableCommand {
1337 TypableCommand {
1304 name: "tutor",
1338 name: "tutor",
1305 aliases: &[],
1339 aliases: &[],
helix-term/src/keymap.rs+8
@@ -682,6 +682,10 @@ impl Default for Keymaps {
682 "C-j" | "j" | "down" => jump_view_down,
682 "C-j" | "j" | "down" => jump_view_down,
683 "C-k" | "k" | "up" => jump_view_up,
683 "C-k" | "k" | "up" => jump_view_up,
684 "C-l" | "l" | "right" => jump_view_right,
684 "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+ },
685 },
689 },
686
690
687 // move under <space>c
691 // move under <space>c
@@ -732,6 +736,10 @@ impl Default for Keymaps {
732 "C-j" | "j" | "down" => jump_view_down,
736 "C-j" | "j" | "down" => jump_view_down,
733 "C-k" | "k" | "up" => jump_view_up,
737 "C-k" | "k" | "up" => jump_view_up,
734 "C-l" | "l" | "right" => jump_view_right,
738 "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+ },
735 },
743 },
736 "y" => yank_joined_to_clipboard,
744 "y" => yank_joined_to_clipboard,
737 "Y" => yank_main_selection_to_clipboard,
745 "Y" => yank_main_selection_to_clipboard,