Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/generated/typable-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| `:buffer-close-all!`, `:bca!`, `:bcloseall!` | Force close all buffers ignoring unsaved changes without quitting. |
| `:buffer-next`, `:bn`, `:bnext` | Goto next buffer. |
| `:buffer-previous`, `:bp`, `:bprev` | Goto previous buffer. |
| `:goto-buffer`, `:gb` | Goto buffer by number. |
| `:write`, `:w` | Write changes to disk. Accepts an optional path (:write some/path.txt) |
| `:write!`, `:w!` | Force write changes to disk creating necessary subdirectories. Accepts an optional path (:write! some/path.txt) |
| `:write-buffer-close`, `:wbc` | Write changes to disk and closes the buffer. Accepts an optional path (:write-buffer-close some/path.txt) |
Expand Down
36 changes: 36 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,31 @@ fn buffer_previous(
Ok(())
}

fn goto_buffer_number(
cx: &mut compositor::Context,
args: Args,
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}

let buffer_num = args[0].parse::<usize>()?;

if buffer_num == 0 {
bail!("Buffer numbers start from 1");
}

let docs: Vec<_> = cx.editor.documents.keys().collect();
if buffer_num > docs.len() {
bail!("Buffer {} does not exist", buffer_num);
}

let doc_id = *docs[buffer_num - 1];
cx.editor.switch(doc_id, Action::Replace);
Ok(())
}

fn write_impl(
cx: &mut compositor::Context,
path: Option<&str>,
Expand Down Expand Up @@ -2791,6 +2816,17 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
..Signature::DEFAULT
},
},
TypableCommand {
name: "goto-buffer",
aliases: &["gb"],
doc: "Goto buffer by number.",
fun: goto_buffer_number,
completer: CommandCompleter::none(),
signature: Signature {
positionals: (1, Some(1)),
..Signature::DEFAULT
},
},
TypableCommand {
name: "write",
aliases: &["w"],
Expand Down