diff options
author | devins2518 | 2021-08-24 00:37:44 +0000 |
---|---|---|
committer | GitHub | 2021-08-24 00:37:44 +0000 |
commit | e1c9f132637bcf2406c7c1403ab3d8dfd882369e (patch) | |
tree | c59cebc3e3dca95dc37b8950ddf62b651a23c8d3 /helix-term/src | |
parent | 81984be9f40d796f7d48ff5a949252550f83b3c8 (diff) |
Add :vsplit and :hsplit commands (#639)
* add vsplit and hsplit commands
* handle splits more elegantly
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index a78f137a..56e4f1b6 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -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", @@ -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), } ]; |