aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--book/src/generated/typable-cmd.md2
-rw-r--r--helix-term/src/commands.rs19
-rw-r--r--helix-term/src/commands/typed.rs32
3 files changed, 43 insertions, 10 deletions
diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md
index 1ee2fac4..85507b19 100644
--- a/book/src/generated/typable-cmd.md
+++ b/book/src/generated/typable-cmd.md
@@ -9,6 +9,8 @@
| `:buffer-close-others!`, `:bco!`, `:bcloseother!` | Close all buffers but the currently focused one. |
| `:buffer-close-all`, `:bca`, `:bcloseall` | Close all buffers, without quiting. |
| `:buffer-close-all!`, `:bca!`, `:bcloseall!` | Close all buffers forcefully (ignoring unsaved changes), without quiting. |
+| `:buffer-next`, `:bn`, `:bnext` | Go to next buffer. |
+| `:buffer-previous`, `:bp`, `:bprev` | Go to previous buffer. |
| `:write`, `:w` | Write changes to disk. Accepts an optional path (:write some/path.txt) |
| `:new`, `:n` | Create a new scratch buffer. |
| `:format`, `:fmt` | Format the file using the LSP formatter. |
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index f0fb469b..b93cfc41 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -637,36 +637,35 @@ fn goto_line_start(cx: &mut Context) {
}
fn goto_next_buffer(cx: &mut Context) {
- goto_buffer(cx, Direction::Forward);
+ goto_buffer(cx.editor, Direction::Forward);
}
fn goto_previous_buffer(cx: &mut Context) {
- goto_buffer(cx, Direction::Backward);
+ goto_buffer(cx.editor, Direction::Backward);
}
-fn goto_buffer(cx: &mut Context, direction: Direction) {
- let current = view!(cx.editor).doc;
+fn goto_buffer(editor: &mut Editor, direction: Direction) {
+ let current = view!(editor).doc;
let id = match direction {
Direction::Forward => {
- let iter = cx.editor.documents.keys();
+ let iter = editor.documents.keys();
let mut iter = iter.skip_while(|id| *id != &current);
iter.next(); // skip current item
- iter.next().or_else(|| cx.editor.documents.keys().next())
+ iter.next().or_else(|| editor.documents.keys().next())
}
Direction::Backward => {
- let iter = cx.editor.documents.keys();
+ let iter = editor.documents.keys();
let mut iter = iter.rev().skip_while(|id| *id != &current);
iter.next(); // skip current item
- iter.next()
- .or_else(|| cx.editor.documents.keys().rev().next())
+ iter.next().or_else(|| editor.documents.keys().rev().next())
}
}
.unwrap();
let id = *id;
- cx.editor.switch(id, Action::Replace);
+ editor.switch(id, Action::Replace);
}
fn extend_to_line_start(cx: &mut Context) {
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index c921f85b..4c044793 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -172,6 +172,24 @@ fn force_buffer_close_all(
buffer_close_by_ids_impl(cx.editor, &document_ids, true)
}
+fn buffer_next(
+ cx: &mut compositor::Context,
+ _args: &[Cow<str>],
+ _event: PromptEvent,
+) -> anyhow::Result<()> {
+ goto_buffer(cx.editor, Direction::Forward);
+ Ok(())
+}
+
+fn buffer_previous(
+ cx: &mut compositor::Context,
+ _args: &[Cow<str>],
+ _event: PromptEvent,
+) -> anyhow::Result<()> {
+ goto_buffer(cx.editor, Direction::Backward);
+ Ok(())
+}
+
fn write_impl(cx: &mut compositor::Context, path: Option<&Cow<str>>) -> anyhow::Result<()> {
let jobs = &mut cx.jobs;
let doc = doc_mut!(cx.editor);
@@ -1083,6 +1101,20 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
completer: None,
},
TypableCommand {
+ name: "buffer-next",
+ aliases: &["bn", "bnext"],
+ doc: "Go to next buffer.",
+ fun: buffer_next,
+ completer: None,
+ },
+ TypableCommand {
+ name: "buffer-previous",
+ aliases: &["bp", "bprev"],
+ doc: "Go to previous buffer.",
+ fun: buffer_previous,
+ completer: None,
+ },
+ TypableCommand {
name: "write",
aliases: &["w"],
doc: "Write changes to disk. Accepts an optional path (:write some/path.txt)",