Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands for buffer navigation #1926

Closed
Darksecond opened this issue Apr 2, 2022 · 2 comments · Fixed by #1940
Closed

Commands for buffer navigation #1926

Darksecond opened this issue Apr 2, 2022 · 2 comments · Fixed by #1940
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors

Comments

@Darksecond
Copy link

I would love to see a set of commands for buffer navigation, like in vim.
Specifically something like buffer_next and buffer_previous which can be aliased to :bn and :bp.
They would allow the user to switch buffers without having to go through the b menu.

@Darksecond Darksecond added the C-enhancement Category: Improvements label Apr 2, 2022
@archseer archseer added E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors labels Apr 2, 2022
@sudormrfbin
Copy link
Member

There's gn and gp for next and previous buffer, so it's just a matter of adding the typable commands (defined in https://github.com/helix-editor/helix/blob/master/helix-term/src/commands/typed.rs) which utilize already existing functions:

fn goto_next_buffer(cx: &mut Context) {
goto_buffer(cx, Direction::Forward);
}
fn goto_previous_buffer(cx: &mut Context) {
goto_buffer(cx, Direction::Backward);
}
fn goto_buffer(cx: &mut Context, direction: Direction) {
let current = view!(cx.editor).doc;
let id = match direction {
Direction::Forward => {
let iter = cx.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())
}
Direction::Backward => {
let iter = cx.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())
}
}
.unwrap();
let id = *id;
cx.editor.switch(id, Action::Replace);
}

@kirawi kirawi added the A-helix-term Area: Helix term improvements label Apr 2, 2022
@David-Kunz
Copy link
Contributor

Hi @Darksecond and @sudormrfbin,

I've just created a PR to add the typed commands buffer-next and buffer-previous.

Best regards,
David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants