Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/roobert/bufferline-cycle-windowless.nvim

:window: A Neovim/Bufferline extension to cycle through windowless buffers to give a more traditional tab based experience
https://github.com/roobert/bufferline-cycle-windowless.nvim

Last synced: 14 days ago
JSON representation

:window: A Neovim/Bufferline extension to cycle through windowless buffers to give a more traditional tab based experience

Awesome Lists containing this project

README

        

# :window: Bufferline Cycle Windowless

![Screenshot](https://user-images.githubusercontent.com/226654/208528189-10984843-96cc-4e86-bcfe-efa5b4b13707.gif)

A [bufferline](https://github.com/akinsho/bufferline.nvim) extension to cycle through windowless buffers.

## :zap: Motivation

Neovims default tab-window-buffer model allows viewing open buffers in multiple windows.

This plugin helps give a more traditional behaviour for tabs by configuring the ability to skip past
buffers that are already open in an existing window. The behaviour is toggleable and
configurable to be on or off by default.

## :rocket: Installation

### Lazy

```lua
{
"roobert/bufferline-cycle-windowless.nvim",
dependencies = {
{ "akinsho/bufferline.nvim" },
},
config = function()
require("bufferline-cycle-windowless").setup({
-- whether to start in enabled or disabled mode
default_enabled = true,
})
end,
},
```

### Packer

```lua
use {
"roobert/bufferline-cycle-windowless.nvim",
requires = {
{ "akinsho/bufferline.nvim" },
},
setup = function()
require("bufferline-cycle-windowless").setup({
-- whether to start in enabled or disabled mode
default_enabled = true,
})
end,
}
```

## :hammer_and_wrench: Usage

### Simple Example

#### Standard Neovim

``` lua
vim.api.nvim_set_keymap("n", "", "BufferLineCycleWindowlessNext",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "", "BufferLineCycleWindowlessPrev",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "", "BufferLineCycleWindowlessToggle",
{ noremap = true, silent = true })
```

#### Lunarvim

``` lua
lvim.keys.normal_mode[""] = "BufferLineCycleWindowlessNext"
lvim.keys.normal_mode[""] = "BufferLineCycleWindowlessPrev"
lvim.keys.normal_mode[""] = "BufferLineCycleWindowlessToggle"
```

### Advanced Example

This example firstly creates empty splits rather than splits with a view of the current file, and secondly, when cycling through buffers occurs it will delete the `[no file]` buffers, removing them from the buffer list / bufferline.

#### Standard Neovim

``` lua
-- open empty splits
vim.api.nvim_set_keymap("n", "|", "vsplit +enew", {})
vim.api.nvim_set_keymap("n", "_", "split +enew", {})

-- since we open empty splits - clean them up as we cycle through open buffers
function ChangeTab(motion)
local last_buffer_id = vim.fn.bufnr()
local last_buffer_name = vim.fn.expand("%")

if motion == "next" then
vim.cmd([[BufferLineCycleWindowlessNext]])
elseif motion == "prev" then
vim.cmd([[BufferLineCycleWindowlessPrev]])
else
error("Invalid motion: " .. motion)
return
end

if last_buffer_name == "" then
vim.cmd("bd " .. last_buffer_id)
end
end

-- switch through visible buffers with shift-l/h
vim.api.nvim_set_keymap("n", "", "lua ChangeTab('next')", {})
vim.api.nvim_set_keymap("n", "", "lua ChangeTab('prev')", {})
vim.api.nvim_set_keymap("n", "", "BufferLineCycleWindowlessToggle", {})

-- lighten up bufferline background
lvim.builtin.bufferline = {
active = true,
options = {
separator_style = "slant",
},
highlights = {
fill = {
bg = "#252d52",
},

separator_selected = {
fg = "#252d52",
},

separator_visible = {
fg = "#252d52",
},

separator = {
fg = "#252d52",
},

buffer_visible = {
fg = "#9696ca",
bold = false,
},

buffer_selected = {
fg = "#eeeeee",
bold = false,
},

tab_selected = {
bold = false,
},
},
}

```

#### Lunarvim

``` lua
-- open empty splits
lvim.builtin.which_key.mappings["|"] = { "vsplit +enew", "Vertical split" }
lvim.builtin.which_key.mappings["_"] = { "split +enew", "Horizontal split" }

-- since we open empty splits - clean them up as we cycle through open buffers
function ChangeTab(motion)
local last_buffer_id = vim.fn.bufnr()
local last_buffer_name = vim.fn.expand("%")

if motion == "next" then
vim.cmd([[BufferLineCycleWindowlessNext]])
elseif motion == "prev" then
vim.cmd([[BufferLineCycleWindowlessPrev]])
else
error("Invalid motion: " .. motion)
return
end

if last_buffer_name == "" then
vim.cmd("bd " .. last_buffer_id)
end
end

-- switch through visible buffers with shift-l/h
lvim.keys.normal_mode[""] = "lua ChangeTab('next')"
lvim.keys.normal_mode[""] = "lua ChangeTab('prev')"
lvim.keys.normal_mode[""] = "BufferLineCycleWindowlessToggle"

-- lighten up bufferline background
lvim.builtin.bufferline = {
active = true,
options = {
separator_style = "slant",
},
highlights = {
fill = {
bg = "#252d52",
},

separator_selected = {
fg = "#252d52",
},

separator_visible = {
fg = "#252d52",
},

separator = {
fg = "#252d52",
},

buffer_visible = {
fg = "#9696ca",
bold = false,
},

buffer_selected = {
fg = "#eeeeee",
bold = false,
},

tab_selected = {
bold = false,
},
},
}

```