Skip to content
Open
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion lua/bufferlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ local default_opts = {
prompt = "",
save_prompt = "󰆓 ",
},
win_opts = {},
start_cursor_on_buf_line = true,
top_prompt = true,
show_path = false,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down