diff --git a/README.md b/README.md index 4c8e5b8..b2561e3 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,8 @@ Bufferlist comes with the following defaults: line = "▎", modified = "󰝥", }, + win_opts = {}, -- set local vim opts of BufferList window + start_cursor_on_buf_line = true, -- set this to true if you want the cursor to start on the line of the currently opened buffer top_prompt = true, -- set this to false if you want the prompt to be at the bottom of the window instead of on top of it. show_path = false, -- show the relative paths the first time BufferList window is opened } @@ -178,6 +180,17 @@ press `keymap.toggle_path` to toggle the relative path to each buffer from the n #### Show relative path set `show_path` to `true` to show the relative path the first time you open the BufferList window after it has been loaded. +### Adding custom window opts +You can add custom local opts for BufferList window via `win_opts` option. `win_opts` takes a table of `key = value` items. You can see a list of available options by running `:help option-summary`, any option marked as local can be set. + +This example shows how to set window opts to highlight the cursor line of BufferList window: +```lua +win_opts = { + cursorline = true, + cursorlineopts = "line", +}, +``` + ### Adding custom keymaps You can add custom keymaps for BufferList window via `win_keymaps` option, and keymaps for buffers via `bufs_keymaps` option #### For BufferList window diff --git a/lua/bufferlist.lua b/lua/bufferlist.lua index 52d16ed..9caae50 100644 --- a/lua/bufferlist.lua +++ b/lua/bufferlist.lua @@ -35,6 +35,8 @@ local default_opts = { prompt = "", save_prompt = "󰆓 ", }, + win_opts = {}, + start_cursor_on_buf_line = true, top_prompt = true, show_path = false, } @@ -258,8 +260,10 @@ local function list_buffers() local modified_byteidx = fn.byteidx(default_opts.icons.modified, 1) local function refresh() + local store_cursor_line = unpack(api.nvim_win_get_cursor(0)) cmd("bwipeout") list_buffers() + fn.setcursorcharpos(store_cursor_line, 6) end for i = 1, #b do @@ -420,7 +424,15 @@ local function list_buffers() vim.wo[win].number = true bo[scratch_buf].modifiable = false - fn.setcursorcharpos(1, 6) + if default_opts.start_cursor_on_buf_line then + fn.setcursorcharpos(tostring(current_buf_line or 1), 6) + else + fn.setcursorcharpos(1, 6) + end + + for key, value in pairs(default_opts.win_opts) do + vim.wo[win][key] = value + end km.set("n", default_opts.keymap.close_bufferlist, function() cmd("bwipeout")