Giter VIP home page Giter VIP logo

buftabline.nvim's Introduction

buftabline.nvim

A low-config, minimalistic buffer tabline Neovim plugin written in Lua, shamelessly inspired by vim-buftabline.

Screen Shot 2021-07-25 at 5 50 38 PM

Setup

Install using your favorite plugin manager and call the following Lua code somewhere in your configuration:

require("buftabline").setup {}

If you're using packer.nvim, you can install and set up buftabline simultaneously:

use {
    "jose-elias-alvarez/buftabline.nvim",
    requires = {"kyazdani42/nvim-web-devicons"}, -- optional!
    config = function() require("buftabline").setup {} end
}

Features

Buftabline shows your open buffers in your tabline with (optional) filetype icons and applies highlighting to each tab based its buffer's state. If you want, it'll also show your tabpages (:help tabpages). That's pretty much it.

For convenience, the plugin exposes a function, buftarget(number, command) which will target a buffer in the tabline with a command:

require("buftabline").buftarget(1, "rightbelow sb")

Buftabline includes a built-in buftarget command, go_to_buffer(number), which does what you'd imagine. By default, the plugin maps <Leader>0-9 to the corresponding go_to_buffer command (0 gets converted to 10), but you can disable this by setting go_to_maps to false (see Options).

To simplify the creation of custom commands, buftabline also exposes a map method. The following example will map <Leader>c1 through Leader<c9> to the corresponding bdelete command:

require("buftabline").map({ prefix = "<Leader>c", cmd = "bdelete" })

Lastly, the plugin adds the following Vim commands:

  • :ToggleBuftabline (useful for smaller screens / focus sessions)

  • :BufNext and :BufPrev (like :bnext and :bprev, but they correspond to bufferline indexes.

Options

For most users, everything should work out-of-the-box, but the plugin exposes the following options (defaults shown):

local options = {
    tab_format = " #{n}: #{b}#{f} ",
    buffer_id_index = false,
    icon_colors = true,
    start_hidden = false,
    auto_hide = false,
    disable_commands = false,
    go_to_maps = true,
    flags = {
        modified = "[+]",
        not_modifiable = "[-]",
        readonly = "[RO]",
    },
    hlgroups = {
        current = "TabLineSel",
        normal = "TabLine",
        active = nil,
        spacing = nil,
        modified_current = nil,
        modified_normal = nil,
        modified_active = nil,
        tabpage_current = nil,
        tabpage_normal = nil
    },
    show_tabpages = true,
    tabpage_format = " #{n} ",
    tabpage_position = "right",
    tabpage_buffers = false
}
Option Description
tab_format Defines how the plugin formats buffer tabs (see Format below for details).
buffer_id_index Uses buffer numbers (the ones shown in :ls) instead of sequential indexes.
icon_colors Shows icon colors in your tabline. Can be true (always show), current (show for current tab), and normal (show for background tabs).
start_hidden Hides the tabline when Neovim starts.
auto_hide Shows the tabline when you have more than one buffer open and hides it when you don't. Not compatible with start_hidden.
disable_commands Stops the plugin from defining commands.
go_to_maps Maps <Leader>0-9 to the corresponding go_to_buffer command.
flags Sets the flags used to mark a buffer's status.
hlgroups Sets highlight groups (see Colors below for details).
show_tabpages Shows tabpages (:h tabpages) in your bufferline. Can be true (show if more than one tabpage), always (always show), and false (disable). If you don't use tabpages, there's no need to change this.
show_tabpages Defines how the plugin formats tabpages (see Format below for details).
tabpage_position Determines where the plugin shows tabpages. Can be right or left. Does nothing if you've set show_tabpages to false.
tabpage_buffers Associates buffers with tabpages, meaning the current tabpage only shows buffers opened in that tabpage.

Format

The tab_format string accepts the following special options and replaces them with the corresponding buffer information. The plugin won't do anything to other characters, including spaces and separators.

Option Information
#{n} The buffer's index. Modified by buffer_id_index.
#{b} The buffer's filename. If two or more buffers share a filename, it'll add the name of each buffer's enclosing directory.
#{f} The buffer's flags (modified, modifiable, and read-only).
#{i} The buffer's filetype icon.

The tabpage_format string accepts the following option:

Option Information
#{n} The tabpage's index.

Colors

The hlgroups option is a table that accepts the following keys to allow setting highlight groups based on buffer state. Leaving a value empty will cause the plugin to fall back to the next available group.

Key Condition
current The current buffer.
normal The buffer is not current visible in any window.
active The buffer is visible in another window.
spacing Applied to the empty space between buffer tabs and any right-aligned tabs (or the end of the viewport).
modified_current Same as current, but the buffer is modified.
modified_normal Same as normal, but the buffer is modified.
modified_active Same as active, but the buffer is modified.
tabpage_current The current tabpage. Falls back to current if not defined.
tabpage_normal Tabpages other than the current. Falls back to normal if not defined.

FAQ

How do I enable icons?

Add #{i} to tab_format. For example, to keep the default format but show icons after the buffer's filename:

tab_format = " #{n}: #{b}#{f} #{i} "

Non-goals

  • Vim support. Use vim-buftabline!
  • Mouse support.
  • Visual customization beyond what's available with tab_format.

Aside from these, I'm open to PRs.

Tests

Run make test from the plugin's root directory. Depends on plenary.nvim.

Inspiration

  • vim-buftabline, the direct inspiration for this plugin and a solid plugin if you don't mind Vimscript.

  • nvim-bufbar by @ojroques, who directed me to his plugin and encouraged me to use it as a starting point.

  • lightline-bufferline, which gave me the idea to "target" buffers in the tabline with commands.

  • nvim-bufferline and barbar.nvim, two tabline plugins that are far and away better than this one but are a little too much for my simple needs. (Thanks to barbar.nvim for its implementation of colored icons, which provided the basis for the implementation in this plugin.)

buftabline.nvim's People

Contributors

cuducos avatar jdrouhard avatar mroavi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.