NVIM LUAU

Awesome plugins for Neovim

GitHubAdd Plugin

    Tabline

  • akinsho/bufferline.nvim
    944

    A snazzy bufferline for Neovim

  • crispgm/nvim-tabline
    19

    nvim port of tabline.vim with Lua

  • koenverburg/minimal-tabline.nvim
    2

    A minimal tabline, that's it

  • nanozuki/tabby.nvim
    381

    A declarative, highly configurable, and neovim style tabline plugin. Use your nvim tabs as a workspace multiplexer!

  • noib3/nvim-cokeline
    169

    :nose: A Neovim bufferline for people with addictive personalities

  • romgrk/barbar.nvim
    899

    The neovim tabline plugin.

  • Status Line

  • alvarosevilla95/luatab.nvim
    109

    Tabline lua plugin for neovim

  • b0o/incline.nvim
    105

    🎈 Floating statuslines for Neovim

  • datwaft/bubbly.nvim
    167

    Bubbly statusline for neovim

  • feline-nvim/feline.nvim
    564

    A minimal, stylish and customizable statusline for Neovim written in Lua

  • konapun/vacuumline.nvim
    17

    A prebuilt configuration for galaxyline inspired by airline

  • NTBBloodbath/galaxyline.nvim
    118

    neovim statusline plugin written in lua

  • nvim-lualine/lualine.nvim
    1434

    A blazing fast and easy to configure neovim statusline plugin written in pure lua.

  • rebelot/heirline.nvim
    208

    Heirline.nvim is a no-nonsense Neovim Statusline plugin designed around recursive inheritance to be exceptionally fast and versatile.

  • tamton-aquib/staline.nvim
    138

    A modern lightweight statusline and bufferline for neovim in lua. Mainly uses unicode symbols for showing info.

  • windwp/windline.nvim
    280

    Animation statusline, floating window statusline. Use lua + luv make some wind

  • Keybinding

  • b0o/mapx.nvim
    141

    πŸ—Ί A better way to create key mappings in Neovim.

  • folke/which-key.nvim
    1189

    πŸ’₯ Create key bindings that stick. WhichKey is a lua plugin for Neovim 0.5 that displays a popup with possible keybindings of the command you started typing.

  • mrjones2014/legendary.nvim
    210

    πŸ—ΊοΈ A legend for your keymaps, commands, and autocmds, with which-key.nvim integration (requires Neovim nightly)

  • simrat39/rust-tools.nvim
    684

    Tools for better development in rust using neovim's builtin lsp

  • LSP

  • b0o/SchemaStore.nvim
    159

    πŸ› JSON schemas for Neovim

  • folke/trouble.nvim
    1388

    🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.

  • jose-elias-alvarez/nvim-lsp-ts-utils
    373

    Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.

  • neovim/nvim-lspconfig
    3936

    Quickstart configurations for the Nvim LSP client

  • nvim-lua/lsp_extensions.nvim
    193

    Repo to hold a bunch of info & extension callbacks for built-in LSP. Use at your own risk :wink:

  • nvim-lua/lsp-status.nvim
    426

    Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline

  • ray-x/navigator.lua
    572

    Navigate codes like a breeze🎐. Exploring LSP and 🌲Treesitter symbols a piece of 🍰. Take control like a boss 🦍.

  • williamboman/nvim-lsp-installer
    1157

    Neovim plugin that allows you to seamlessly manage LSP servers with :LspInstall. With full Windows support!

  • Guides

  • bennypowers/nvim-regexplainer
    183

    Describe the regexp under the cursor

  • nvim-lua/kickstart.nvim
    2356

    A launch point for your personal nvim configuration

  • Colorschemes

  • catppuccin/nvim
    546

    🍨 Soothing pastel theme for NeoVim

  • dharmx/nvim-colo
    26

    Theming utlilities for neovim. This is very experimental at the moment.

  • ful1e5/onedark.nvim
    174

    Atom's iconic One Dark theme for Neovim, written in Lua

  • HUAHUAI23/nvim-quietlight
    0

    A theme for Neovim with support for LSP, Treesitter, and more.

  • kvrohit/substrata.nvim
    56

    A cold, dark color scheme for Neovim

  • lalitmee/cobalt2.nvim
    7

    cobalt2 theme for neovim in Lua using colorbuddy

  • luisiacc/gruvbox-baby
    42

    Gruvbox theme for neovim with full πŸŽ„TreeSitter support.

  • mhartington/oceanic-next
    986

    Oceanic Next theme for neovim

  • Mofiqul/adwaita.nvim
    38

    Neovim colorscheme using Gnome Adwaita syntax

  • Mofiqul/dracula.nvim
    123

    Dracula colorscheme for neovim written in Lua

  • mrjones2014/lighthaus.nvim
    40

    A Lua implementation of lighthaus-theme/vim-lighthaus

  • navarasu/onedark.nvim
    270

    One dark and light colorscheme for neovim >= 0.5.0 written in lua based on Atom's One Dark and Light theme. Additionally, it comes with 5 color variant styles

  • NTBBloodbath/doom-one.nvim
    74

    doom-emacs' doom-one Lua port for Neovim

  • rebelot/kanagawa.nvim
    738

    NeoVim dark colorscheme inspired by the colors of the famous painting by Katsushika Hokusai.

  • rose-pine/neovim
    310

    Soho vibes for Neovim

  • RRethy/nvim-base16
    301

    Neovim plugin for building a sync base16 colorscheme. Includes support for Treesitter and LSP highlight groups.

  • sunjon/Shade.nvim
    374

    An Nvim lua plugin that dims your inactive windows

  • themercorp/themer.lua
    130

    A simple, minimal highlighter plugin for neovim

  • zanglg/nova.nvim
    82

    Another color scheme for neovim written in lua, WIP

  • Comment

  • danymat/neogen
    373

    A better annotation generator. Supports multiple languages and annotation conventions.

  • Utility

  • echasnovski/mini.nvim
    405

    Neovim plugin with collection of minimal, independent, and fast Lua modules dedicated to improve Neovim (version 0.5 and higher) experience

  • hood/popui.nvim
    42

    NeoVim UI sweetness powered by popfix.

  • meznaric/conmenu
    21

  • mrjones2014/dash.nvim
    132

    πŸƒπŸ’¨ Search Dash.app from your Neovim fuzzy finder. Built with Rust πŸ¦€ and Lua

  • Cursor Line

  • edluffy/specs.nvim
    233

    πŸ‘“ A fast and lightweight Neovim lua plugin to keep an eye on where your cursor has jumped.

  • mg979/vim-visual-multi
    2046

    Multiple cursors plugin for vim/neovim

  • Code Runner

  • FeiyouG/command_center.nvim
    57

    Create and manage keybindings and commands in a more organized manner, and search them quickly through Telescope

  • Extras

  • folke/zen-mode.nvim
    377

    🧘 Distraction-free coding for Neovim

  • goolord/alpha-nvim
    322

    a lua powered greeter like vim-startify / dashboard-nvim

  • Start Up

  • henriquehbr/nvim-startup.lua
    45

    Displays neovim startup time

  • lewis6991/impatient.nvim
    563

    Improve startup time for Neovim

  • Session

  • HUAHUAI23/telescope-session.nvim
    12

    manage your vim session with telescope πŸ”­

  • Fuzzy Finder

  • ibhagwan/fzf-lua
    418

    Improved fzf.vim written in lua

  • nvim-telescope/telescope.nvim
    5023

    Find, Filter, Preview, Pick. All lua, all the time.

  • vijaymarupudi/nvim-fzf
    223

    A Lua API for using fzf in neovim.

  • Misc

  • iggredible/Learn-Vim
    9061

    Learning Vim and Vimscript doesn't have to be hard. This is the guide that you're looking for πŸ“–

  • m-demare/attempt.nvim
    53

    Manage temporary buffers

  • SmiteshP/nvim-gps
    348

    Simple statusline component that shows what scope you are working inside

  • windwp/nvim-autopairs
    1479

    autopairs for neovim written by lua

  • zegervdv/nrpattern.nvim
    43

    Neovim plugin to expand incrementing/decrementing to more formats.

  • Note Taking

  • jakewvincent/mkdnflow.nvim
    97

    Tools for markdown notebook navigation and management

  • nvim-neorg/neorg
    2078

    Modernity meets insane extensibility. The future of organizing your life in Neovim.

  • Motion

  • jinh0/eyeliner.nvim
    170

    πŸ‘€ Move faster with unique f/F indicators.

  • Terminal Integration

  • jlesquembre/nterm.nvim
    35

    neovim plugin to interact with the terminal

  • Scrolling

  • karb94/neoscroll.nvim
    765

    Smooth scrolling neovim plugin written in lua

  • Git

  • kdheepak/lazygit.nvim
    313

    Plugin for calling lazygit from within neovim.

  • zegervdv/settle.nvim
    0

    Settle your merge conflicts from Neovim

  • File Explorer

  • kevinhwang91/rnvimr
    451

    Make Ranger running in a floating window to communicate with Neovim via RPC

  • kyazdani42/nvim-tree.lua
    2040

    A file explorer tree for neovim written in lua

  • Snippets

  • L3MON4D3/LuaSnip
    692

    Snippet Engine for Neovim written in Lua.

  • Browser Integration

  • lalitmee/browse.nvim
    0

    browse for anything using your choice of method

  • Indent

  • lukas-reineke/indent-blankline.nvim
    1272

    Indent guides for Neovim

  • Formatting

  • lukas-reineke/lsp-format.nvim
    248

    A wrapper around Neovims native LSP formatting.

  • Syntax

  • m-demare/hlargs.nvim/
    30

    Highlight arguments' definitions and usages, using Treesitter

  • Splits and Window

  • mrjones2014/smart-splits.nvim
    83

    🧠 Smart, directional Neovim split resizing and navigation. Think about resizing splits in terms of "move the divider to the left/right/up/down".

  • Completion

  • noib3/nvim-compleet
    413

    :zap: An async autocompletion framework for Neovim

  • zbirenbaum/copilot-cmp
    69

    Lua plugin to turn github copilot into a cmp source

  • zbirenbaum/copilot.lua
    100

    Lua plugin for starting and interacting with github copilot

  • Package Managers

  • NTBBloodbath/cheovim
    145

    Neovim configuration switcher written in Lua. Inspired by chemacs.

  • savq/paq-nvim
    408

    🌚 Neovim package manager

  • wbthomason/packer.nvim
    2321

    A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config

  • Game

  • ThePrimeagen/vim-be-good
    619

    vim-be-good is a nvim plugin designed to make you better at Vim Movements.

https://github.com/noib3/nvim-cokeline

The goal of this plugin is not to be an opinionated bufferline with (more or less) limited customization options. Rather, it tries to provide a general framework allowing you to build your ideal bufferline, whatever that might look like.

preview

:book: Table of Contents

  • Features
  • Plans
  • Requirements
  • Installation
  • Configuration
  • Mappings
  • Example configs

:sparkles: Features

Endlessly customizable

nvim-cokeline aims to be the most customizable bufferline plugin around. If you have an idea in mind of what your bufferline should look like, you should be able to make it look that way. If you can't, open an issue and we'll try to make it happen!

Here's a (very limited) showcase of what it can be configured to look like (check out Example configs for more examples):

local get_hex = require('cokeline/utils').get_hex

require('cokeline').setup({
  default_hl = {
    fg = function(buffer)
      return
        buffer.is_focused
        and get_hex('ColorColumn', 'bg')
         or get_hex('Normal', 'fg')
    end,
    bg = function(buffer)
      return
        buffer.is_focused
        and get_hex('Normal', 'fg')
         or get_hex('ColorColumn', 'bg')
    end,
  },

  components = {
    {
      text = function(buffer) return ' ' .. buffer.devicon.icon end,
      fg = function(buffer) return buffer.devicon.color end,
    },
    {
      text = function(buffer) return buffer.unique_prefix end,
      fg = get_hex('Comment', 'fg'),
      style = 'italic',
    },
    {
      text = function(buffer) return buffer.filename .. ' ' end,
      style = function(buffer)
        if buffer.is_hovered and not buffer.is_focused then
          return 'underline'
	end
      end
    },
    {
      text = 'ο™•',
      on_click = function(_, _, _, _, buffer)
	buffer:delete()
      end
    },
    {
      text = ' ',
    }
  },
})

cokeline-default

local get_hex = require('cokeline/utils').get_hex

local green = vim.g.terminal_color_2
local yellow = vim.g.terminal_color_3

require('cokeline').setup({
  default_hl = {
    fg = function(buffer)
      return
        buffer.is_focused
        and get_hex('Normal', 'fg')
         or get_hex('Comment', 'fg')
    end,
    bg = get_hex('ColorColumn', 'bg'),
  },

  components = {
    {
      text = '|',
      fg = function(buffer)
        return
          buffer.is_modified and yellow or green
      end
    },
    {
      text = function(buffer) return buffer.devicon.icon .. ' ' end,
      fg = function(buffer) return buffer.devicon.color end,
    },
    {
      text = function(buffer) return buffer.index .. ': ' end,
    },
    {
      text = function(buffer) return buffer.unique_prefix end,
      fg = get_hex('Comment', 'fg'),
      style = 'italic',
    },
    {
      text = function(buffer) return buffer.filename .. ' ' end,
      style = function(buffer) return buffer.is_focused and 'bold' or nil end,
    },
    {
      text = ' ',
    },
  },
})

cokeline-noib3

local get_hex = require('cokeline/utils').get_hex

require('cokeline').setup({
  default_hl = {
    fg = function(buffer)
      return
        buffer.is_focused
        and get_hex('Normal', 'fg')
         or get_hex('Comment', 'fg')
    end,
    bg = 'NONE',
  },

  components = {
    {
      text = function(buffer) return (buffer.index ~= 1) and '▏' or '' end,
      fg = get_hex('Normal', 'fg')
    },
    {
      text = function(buffer) return '    ' .. buffer.devicon.icon end,
      fg = function(buffer) return buffer.devicon.color end,
    },
    {
      text = function(buffer) return buffer.filename .. '    ' end,
      style = function(buffer) return buffer.is_focused and 'bold' or nil end,
    },
    {
      text = 'ο™•',
      on_click = function(buffer)
        buffer:delete()
      end
    },
    {
      text = '  ',
    },
  },
})

cokeline-bufferline-lua

Dynamic rendering

Even when you have a lot of buffers open, nvim-cokeline is rendered to always keep the focused buffer visible and in the middle of the bufferline. Also, if a buffer doesn't fit entirely we still try to include as much of it as possible before cutting off the rest.

rendering

LSP support

If a buffer has an LSP client attached to it, you can configure the style of a component to change based on how many errors, warnings, infos and hints are reported by the LSP.

lsp-styling

Buffer pick

You can focus and close any buffer by typing its pick_letter. Letters are assigned by filename by default (e.g. foo.txt gets the letter f), and by keyboard reachability if the letter is already assigned to another buffer.

local is_picking_focus = require('cokeline/mappings').is_picking_focus
local is_picking_close = require('cokeline/mappings').is_picking_close
local get_hex = require('cokeline/utils').get_hex

local red = vim.g.terminal_color_1
local yellow = vim.g.terminal_color_3

require('cokeline').setup({
  default_hl = {
    focused = function(buffer)
      return
        buffer.is_focused
        and get_hex('Normal', 'fg')
         or get_hex('Comment', 'fg')
    end,
    bg = get_hex('ColorColumn', 'bg'),
  },

  components = {
    {
      text = function(buffer) return (buffer.index ~= 1) and '▏' or '' end,
    },
    {
      text = '  ',
    },
    {
      text = function(buffer)
        return
          (is_picking_focus() or is_picking_close())
          and buffer.pick_letter .. ' '
           or buffer.devicon.icon
      end,
      fg = function(buffer)
        return
          (is_picking_focus() and yellow)
          or (is_picking_close() and red)
          or buffer.devicon.color
      end,
      style = function(_)
        return
          (is_picking_focus() or is_picking_close())
          and 'italic,bold'
           or nil
      end,
    },
    {
      text = ' ',
    },
    {
      text = function(buffer) return buffer.filename .. '  ' end,
      style = function(buffer) return buffer.is_focused and 'bold' or nil end,
    },
    {
      text = 'ο™•',
      on_click = function(buffer)
        buffer:delete()
      end,
    },
    {
      text = '  ',
    },
  },
})

buffer-pick

Sidebars

You can add a left sidebar to integrate nicely with file explorer plugins like nvim-tree.lua, CHADTree or NERDTree.

local get_hex = require('cokeline/utils').get_hex

local yellow = vim.g.terminal_color_3

require('cokeline').setup({
  default_hl = {
    focused = function(buffer)
      return
        buffer.is_focused
        and get_hex('Normal', 'fg')
         or get_hex('Comment', 'fg')
    end,
    bg = get_hex('ColorColumn', 'bg'),
  },

  sidebar = {
    filetype = 'NvimTree',
    components = {
      {
        text = '  NvimTree',
        fg = yellow,
        bg = get_hex('NvimTreeNormal', 'bg'),
        style = 'bold',
      },
    }
  },

  components = {
    {
      text = function(buffer) return (buffer.index ~= 1) and '▏' or '' end,
    },
    {
      text = '  ',
    },
    {
      text = function(buffer)
        return buffer.devicon.icon
      end,
      fg = function(buffer)
        return buffer.devicon.color
      end,
    },
    {
      text = ' ',
    },
    {
      text = function(buffer) return buffer.filename .. '  ' end,
      style = function(buffer)
        return buffer.is_focused and 'bold' or nil
      end,
    },
    {
      text = 'ο™•',
      on_click = function(buffer)
        buffer:delete()
      end,
    },
    {
      text = '  ',
    },
  },
})

sidebars

Unique buffer names

When files with the same filename belonging to different directories are opened simultaneously, you can include a unique filetree prefix to distinguish between them:

unique-prefix

Clickable buffers

Left click on a buffer to focus it, and right click to delete it. Alternatively, define custom click handlers for each component that override the default behavior.

clickable-buffers

Hover events

Each component has access to an is_hovered property, and can be given custom on_mouse_enter and on_mouse_leave handlers, allowing for implementations of close buttons, diagnostic previews, and more complex funcionality.

hover-events

hover-events-2

Buffer re-ordering (including mouse-drag reordering)

reordering

Close icons

close-icons

Buffer history tracking

require("cokeline.history"):last():focus()

:mountain: Plans and Ideas

  • Statusline

If you have an idea or feature request, don't hesitate to open an issue!

:electric_plug: Requirements

The two main requirements are Neovim 0.5+ and the termguicolors option to be set. If you want to display devicons in your bufferline you'll also need the kyazdani42/nvim-web-devicons plugin and a patched font (see Nerd Fonts).

As of v0.4.0, nvim-lua/plenary.nvim is required as well.

:package: Installation

Lua

With lazy.nvim
{
  "willothy/nvim-cokeline",
  dependencies = {
    "nvim-lua/plenary.nvim",        -- Required for v0.4.0+
    "kyazdani42/nvim-web-devicons", -- If you want devicons
  },
  config = true
}
With packer.nvim
vim.opt.termguicolors = true

require('packer').startup(function()
  -- ...
  use({
    'willothy/nvim-cokeline',
    requires = {
      "nvim-lua/plenary.nvim",        -- Required for v0.4.0+
      "kyazdani42/nvim-web-devicons", -- If you want devicons
    },
    config = function()
      require("cokeline").setup()
    end
  })
  -- ...
end)

Vimscript

If your config is still written in Vimscript and you use vim-plug:

call plug#begin('~/.config/nvim/plugged')
  " ...
  Plug 'nvim-lua/plenary.nvim'        " Required for v0.4.0+
  Plug 'kyazdani42/nvim-web-devicons' " If you want devicons
  Plug 'willothy/nvim-cokeline'
  " ...
call plug#end()

set termguicolors
lua << EOF
  require('cokeline').setup()
EOF

:wrench: Configuration

note Check out the wiki for more details and API documentation.

All the configuration is done by changing the contents of the Lua table passed to the setup function.

The valid keys are:

require('cokeline').setup({
  -- Only show the bufferline when there are at least this many visible buffers.
  -- default: `1`.
  show_if_buffers_are_at_least = int,

  buffers = {
    -- A function to filter out unwanted buffers. Takes a buffer table as a
    -- parameter (see the following section for more infos) and has to return
    -- either `true` or `false`.
    -- default: `false`.
    filter_valid = function(buffer) -> true | false,

    -- A looser version of `filter_valid`, use this function if you still
    -- want the `cokeline-{switch,focus}-{prev,next}` mappings to work for
    -- these buffers without displaying them in your bufferline.
    -- default: `false`.
    filter_visible = function(buffer) -> true | false,

    -- Which buffer to focus when a buffer is deleted, `prev` focuses the
    -- buffer to the left of the deleted one while `next` focuses the one the
    -- right.
    -- default: 'next'.
    focus_on_delete = 'prev' | 'next',

    -- If set to `last` new buffers are added to the end of the bufferline,
    -- if `next` they are added next to the current buffer.
    -- if set to `directory` buffers are sorted by their full path.
    -- if set to `number` buffers are sorted by bufnr, as in default Neovim
    -- default: 'last'.
    new_buffers_position = 'last' | 'next' | 'directory' | 'number' | function(buffer_a, buffer_b) -> true | false,

    -- If true, right clicking a buffer will close it
    -- The close button will still work normally
    -- Default: true
    delete_on_right_click = true | false,
  },

  mappings = {
    -- Controls what happens when the first (last) buffer is focused and you
    -- try to focus/switch the previous (next) buffer. If `true` the last
    -- (first) buffers gets focused/switched, if `false` nothing happens.
    -- default: `true`.
    cycle_prev_next = true | false,

    -- Disables mouse mappings
    -- default: `false`.
    disable_mouse = true | false,
  },

  -- Maintains a history of focused buffers using a ringbuffer
  history = {
    enabled = true | false (default: true)
    size = int (default: 2)
  },

  rendering = {
    -- The maximum number of characters a rendered buffer is allowed to take
    -- up. The buffer will be truncated if its width is bigger than this
    -- value.
    -- default: `999`.
    max_buffer_width = int,
  },

  pick = {
    -- Whether to use the filename's first letter first before
    -- picking a letter from the valid letters list in order.
    -- default: `true`
    use_filename = true | false,

    -- The list of letters that are valid as pick letters. Sorted by
    -- keyboard reachability by default, but may require tweaking for
    -- non-QWERTY keyboard layouts.
    -- default: `'asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERTYQP'`
    letters = 'string',
  },

  -- The default highlight group values.
  -- The `fg` and `bg` keys are either colors in hexadecimal format or
  -- functions taking a `buffer` parameter and returning a color in
  -- hexadecimal format. Similarly, the `style` key is either a string
  -- containing a comma separated list of items in `:h attr-list` or a
  -- function returning one.
  default_hl = {
    -- default: `ColorColumn`'s background color for focused buffers,
    -- `Normal`'s foreground color for unfocused ones.
    fg = ('hlgroup' | '#rrggbb') | function(buffer) -> ('#rrggbb' | 'hlgroup'),

    -- default: `Normal`'s foreground color for focused buffers,
    -- `ColorColumn`'s background color for unfocused ones.
    -- default: `Normal`'s foreground color.
    bg = ('hlgroup' | '#rrggbb') | function(buffer) -> ('hlgroup' | '#rrggbb'),

    -- default: `'NONE'`.
    style = 'attr1,attr2,...' | function(buffer) -> 'attr1,attr2,...',
  },

  -- The highlight group used to fill the tabline space
  fill_hl = 'TabLineFill',

  -- A list of components to be rendered for each buffer. Check out the section
  -- below explaining what this value can be set to.
  -- default: see `/lua/cokeline/defaults.lua`
  components = {..},

  -- Custom areas can be displayed on the right hand side of the bufferline.
  -- They act identically to buffer components, except their methods don't take a Buffer object.
  -- If you want a rhs component to be stateful, you can wrap it in a closure containing state.
  rhs = {..},

  -- Tabpages can be displayed on either the left or right of the bufferline.
  -- They act the same as other components, except they are passed TabPage objects instead of
  -- buffer objects.
  tabs = {
    placement = "left" | "right",
    components = {..}
  },

  -- Left sidebar to integrate nicely with file explorer plugins.
  -- This is a table containing a `filetype` key and a list of `components` to
  -- be rendered in the sidebar.
  -- The last component will be automatically space padded if necessary
  -- to ensure the sidebar and the window below it have the same width.
  sidebar = {
    filetype = '<filetype>',
    components = {..},
  },
})

So what's function(buffer)?

Some of the configuration options can be functions that take a Buffer as a single parameter. This is useful as it allows users to set the values of components dynamically based on the buffer that component is being rendered for.

The Buffer type is just a Lua table with the following keys:

Buffer = {
  -- The buffer's order in the bufferline (1 for the first buffer, 2 for the
  -- second one, etc.).
  index = int,

  -- The buffer's internal number as reported by `:ls`.
  number = int,

  is_focused = true | false,

  is_modified = true | false,

  is_readonly = true | false,

  -- The buffer is the first visible buffer in the tab bar
  is_first    = true | false,

  -- The buffer is the last visible buffer in the tab bar
  is_last     = true | false,

  -- The mouse is hovering over the current component in the buffer
  -- This is a special variable in that it will only be true for the hovered *component*
  -- on render. This is to allow components to respond to hover events individually without managing
  -- component state.
  is_hovered  = true | false

  -- The mouse is hovering over the buffer (true for all components)
  buf_hovered = true | false

  -- The buffer's type as reported by `:echo &buftype`.
  type = 'string',

  -- The buffer's filetype as reported by `:echo &filetype`.
  filetype = 'string',

  -- The buffer's full path.
  path = 'string',

  -- The buffer's filename.
  filename = 'string',

  -- A unique prefix used to distinguish buffers with the same filename
  -- stored in different directories. For example, if we have two files
  -- `bar/foo.md` and `baz/foo.md`, then the first will have `bar/` as its
  -- unique prefix and the second one will have `baz/`.
  unique_prefix = 'string',

  -- The letter that is displayed when picking a buffer to either focus or
  -- close it.
  pick_letter = 'char',

  -- This needs the `kyazdani42/nvim-web-devicons` plugin to be installed.
  devicon = {
    -- An icon representing the buffer's filetype.
    icon = 'string',

    -- The colors of the devicon in hexadecimal format (useful to be passed
    -- to a component's `fg` field (see the `Components` section).
    color = '#rrggbb',
  },

  -- The values in this table are the ones reported by Neovim's built in
  -- LSP interface.
  diagnostics = {
    errors = int,
    warnings = int,
    infos = int,
    hints = int,
  },
}

It also has methods that can be used in component event handlers:

---@param self Buffer
---Deletes the buffer
function Buffer:delete()

---@param self Buffer
---Focuses the buffer
function Buffer:focus()

---@param self Buffer
---@return number
---Returns the number of lines in the buffer
function Buffer:lines()

---@param self Buffer
---@return string[]
---Returns the buffer's lines
function Buffer:text()

---@param buf Buffer
---@return boolean
---Returns true if the buffer is valid
function Buffer:is_valid()

What about TabPages?

Each method on a tab component is passed a TabPage object as an argument.

TabPage, like Buffer, is simply a Lua table with some relevant data attached.

TabPage = {
  -- The tabpage number, as reported by `nvim_list_tabpages`
  number = integer,
  -- A list of Window objects contained in the TabPage (see wiki for more info)
  windows = Window[],
  -- The currently focused window in the TabPage
  focused = Window,
  -- True if the TabPage is the current TabPage
  is_active = boolean,
  -- True if the TabPage is first in the list
  is_first = boolean,
  -- True if the TabPage is last in the list
  is_last = boolean
}

And components?

You can configure what each buffer in your bufferline will be composed of by passing a list of components to the setup function.

For example, let's imagine we want to construct a very minimal bufferline where the only things we're displaying for each buffer are its index, its filename and a close button.

Then in our setup function we'd have:

require('cokeline').setup({
  -- ...

  components = {
    {
      text = function(buffer) return ' ' .. buffer.index end,
    },
    {
      text = function(buffer) return ' ' .. buffer.filename .. ' ' end,
    },
    {
      text = 'σ°…–',
      on_click = function(buffer)
        buffer:delete()
      end
    },
    {
      text = ' ',
    }
  }
}

in this case every buffer would be composed of four components: the first displaying a space followed by the buffer index, the second one the filename padded by a space on each side, then a close button that allows us to :bdelete the buffer by left-clicking on it, and finally an extra space.

This way of dividing each buffer into distinct components, combined with the ability to define every component's text and color depending on some property of the buffer we're rendering, allows for great customizability.

Every component passed to the components list has to be a table of the form:

{
  text = 'string' | function(buffer) -> 'string',

  -- The foreground, backgrond and style of the component. `style` is a
  -- comma-separated string of values defined in `:h attr-list`.
  fg = '#rrggbb' | function(buffer) -> '#rrggbb',
  bg = '#rrggbb' | function(buffer) -> '#rrggbb',
  style = 'attr1,attr2,...' | function(buffer) -> 'attr1,attr2,...',

  -- Or, alternatively, the name of the highlight group
  highlight = 'string' | function(buffer) -> string | nil,

  -- If `true` the buffer will be deleted when this component is
  -- left-clicked (usually used to implement close buttons, overrides `on_click`).
  -- deprecated, it is recommended to use the Buffer:delete() method in an on_click event
  -- to implement close buttons instead.
  delete_buffer_on_left_click = true | false,

  -- Handles click event for a component
  -- If not set, component will have the default click behavior
  -- buffer is a Buffer object, not a bufnr
  on_click = nil | function(idx, clicks, buttons, modifiers, buffer)

  -- Called on a component when hovered
  on_mouse_enter = nil | function(buffer, mouse_col)

  -- Called on a component when unhovered
  on_mouse_leave = nil | function(buffer)

  truncation = {
    -- default: index of the component in the `components` table (1 for the
    -- first component, 2 for the second, etc.).
    priority = int,

    -- default: `right`.
    direction = 'left' | 'middle' | 'right',
  },
}

the text key is the only one that has to be set, all the others are optional and can be omitted.

The truncation table controls what happens when a buffer is too long to be displayed in its entirety.

More specifically, if a buffer's width (given by the sum of the widths of all its components) is bigger than the rendering.max_buffer_width config option, the buffer will be truncated.

The default behaviour is truncate the buffer by dropping components from right to left, with the text of the last component that's included also being shortened from right to left. This can be modified by changing the values of the truncation.priority and truncation.direction keys.

The truncation.priority controls the order in which components are dropped: the first component to be dropped will be the one with the lowest priority. If that's still not enough to bring the width of the buffer within the rendering.max_buffer_width limit, the component with the second lowest priority will be dropped, and so on. Note that a higher priority means a smaller integer value: a component with a priority of 5 will be dropped after a component with a priority of 6, even though 6 > 5.

The truncation.direction key simply controls from which direction a component is shortened. For example, you might want to set the truncation.direction of a component displaying a filename to 'middle' or 'left', so that if the filename has to be shortened you'll still be able to see its extension, like in the following example (where it's set to 'left'):

buffer-truncation

What about history?

The History keeps track of the buffers you access using a ringbuffer, and provides an API for accessing Buffer objects from the history.

You can access the history using require("cokeline.history"), or through the global _G.cokeline.history.

The History object provides these methods:

---Adds a Buffer object to the history
function History:push(bufnr: int)
end

---Removes and returns the oldest Buffer object in the history
function History:pop(): Buffer | nil
end

---Returns a list of Buffer objects in the history,
---ordered from oldest to newest
function History:list(): Buffer[]
end

---Returns an iterator of Buffer objects in the history,
---ordered from oldest to newest
function History:iter(): fun(): Buffer | nil
end

---Get a Buffer object by history index
function History:get(idx: int): Buffer | nil
end

---Get a Buffer object representing the last-accessed buffer (before the current one)
function History:last(): Buffer | nil
end

---Returns true if the history is empty
function History:is_empty(): boolean
end

---Returns the maximum number of buffers that can be stored in the history
function History:capacity(): int
end

---Returns true if the history contains the given buffer
function History:contains(bufnr: int): bool
end

---Returns the number of buffers in the history
function History:len(): int
end

:musical_keyboard: Mappings

You can use the mappings module to create mappings from Lua:

vim.keymap.set("n", "<leader>bp", function()
    require('cokeline.mappings').pick("focus")
end, { desc = "Pick a buffer to focus" })

-- etc....

Alternatively, we expose the following <Plug> mappings which can be used as the right hand side of other mappings:

-- Focus the previous/next buffer
<Plug>(cokeline-focus-prev)
<Plug>(cokeline-focus-next)

-- Switch the position of the current buffer with the previous/next buffer.
<Plug>(cokeline-switch-prev)
<Plug>(cokeline-switch-next)

-- Focuses the buffer with index `i`.
<Plug>(cokeline-focus-i)

-- Switches the position of the current buffer with the buffer of index `i`.
<Plug>(cokeline-switch-i)

-- Focus a buffer by its `pick_letter`.
<Plug>(cokeline-pick-focus)

-- Close a buffer by its `pick_letter`.
<Plug>(cokeline-pick-close)

A possible configuration could be:

local map = vim.api.nvim_set_keymap

map('n', '<S-Tab>',   '<Plug>(cokeline-focus-prev)',  { silent = true })
map('n', '<Tab>',     '<Plug>(cokeline-focus-next)',  { silent = true })
map('n', '<Leader>p', '<Plug>(cokeline-switch-prev)', { silent = true })
map('n', '<Leader>n', '<Plug>(cokeline-switch-next)', { silent = true })

for i = 1,9 do
  map('n', ('<F%s>'):format(i),      ('<Plug>(cokeline-focus-%s)'):format(i),  { silent = true })
  map('n', ('<Leader>%s'):format(i), ('<Plug>(cokeline-switch-%s)'):format(i), { silent = true })
end