From be758be087a20193d926abccb5c1dacffe20e87e Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 23 Sep 2025 15:51:27 +0200 Subject: [PATCH 1/2] feat: make delete_buffer command with no argument delete the current buffer --- src/tui/mainview.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 1243632..b8fc38b 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -617,8 +617,10 @@ const cmds = struct { pub fn delete_buffer(self: *Self, ctx: Ctx) Result { var file_path: []const u8 = undefined; - if (!(ctx.args.match(.{tp.extract(&file_path)}) catch false)) - return error.InvalidDeleteBufferArgument; + if (!(ctx.args.match(.{tp.extract(&file_path)}) catch false)) { + const editor = self.get_active_editor() orelse return error.InvalidDeleteBufferArgument; + file_path = editor.file_path orelse return error.InvalidDeleteBufferArgument; + } const buffer = self.buffer_manager.get_buffer_for_file(file_path) orelse return; if (buffer.is_dirty()) return tp.exit("unsaved changes"); From f7496654ae3982fb39e766d87eec90d03a99525a Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 23 Sep 2025 15:52:18 +0200 Subject: [PATCH 2/2] feat: add vim mode aliases for buffer commands This adds these vim mode specific commands: :bd (Close file) :bw (Delete buffer) :bnext (Next buffer/tab) :bprevious (Previous buffer/tab) :ls (List/switch buffers) closes #296 --- src/tui/mode/vim.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/tui/mode/vim.zig b/src/tui/mode/vim.zig index e88cd7d..81839b9 100644 --- a/src/tui/mode/vim.zig +++ b/src/tui/mode/vim.zig @@ -51,6 +51,31 @@ const cmds_ = struct { } pub const @"e!_meta": Meta = .{ .description = "e! (force reload current file)" }; + pub fn bd(_: *void, _: Ctx) Result { + try cmd("close_file", .{}); + } + pub const bd_meta: Meta = .{ .description = "bd (Close file)" }; + + pub fn bw(_: *void, _: Ctx) Result { + try cmd("delete_buffer", .{}); + } + pub const bw_meta: Meta = .{ .description = "bw (Delete buffer)" }; + + pub fn bnext(_: *void, _: Ctx) Result { + try cmd("next_tab", .{}); + } + pub const bnext_meta: Meta = .{ .description = "bnext (Next buffer/tab)" }; + + pub fn bprevious(_: *void, _: Ctx) Result { + try cmd("next_tab", .{}); + } + pub const bprevious_meta: Meta = .{ .description = "bprevious (Previous buffer/tab)" }; + + pub fn ls(_: *void, _: Ctx) Result { + try cmd("switch_buffers", .{}); + } + pub const ls_meta: Meta = .{ .description = "ls (List/switch buffers)" }; + pub fn move_begin_or_add_integer_argument_zero(_: *void, _: Ctx) Result { return if (@import("keybind").current_integer_argument()) |_| command.executeName("add_integer_argument_digit", command.fmt(.{0}))