Skip to content

Commit

Permalink
Add :vsplit and :hsplit commands (#639)
Browse files Browse the repository at this point in the history
* add vsplit and hsplit commands

* handle splits more elegantly
  • Loading branch information
devins2518 authored Aug 24, 2021
1 parent 81984be commit e1c9f13
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,40 @@ mod cmd {
Ok(())
}

fn vsplit(
cx: &mut compositor::Context,
args: &[&str],
_event: PromptEvent,
) -> anyhow::Result<()> {
let (_, doc) = current!(cx.editor);
let id = doc.id();

if let Some(path) = args.get(0) {
cx.editor.open(path.into(), Action::VerticalSplit)?;
} else {
cx.editor.switch(id, Action::VerticalSplit);
}

Ok(())
}

fn hsplit(
cx: &mut compositor::Context,
args: &[&str],
_event: PromptEvent,
) -> anyhow::Result<()> {
let (_, doc) = current!(cx.editor);
let id = doc.id();

if let Some(path) = args.get(0) {
cx.editor.open(path.into(), Action::HorizontalSplit)?;
} else {
cx.editor.switch(id, Action::HorizontalSplit);
}

Ok(())
}

pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "quit",
Expand Down Expand Up @@ -2138,6 +2172,20 @@ mod cmd {
doc: "Display tree sitter scopes, primarily for theming and development.",
fun: tree_sitter_scopes,
completer: None,
},
TypableCommand {
name: "vsplit",
alias: Some("vsp"),
doc: "Open the file in a vertical split.",
fun: vsplit,
completer: Some(completers::filename),
},
TypableCommand {
name: "hsplit",
alias: Some("sp"),
doc: "Open the file in a horizontal split.",
fun: hsplit,
completer: Some(completers::filename),
}
];

Expand Down

0 comments on commit e1c9f13

Please sign in to comment.