Neovim plugin to improve the default vim.ui interfaces
Go to file
Steven Arcangeli 7f6cf7fb80 Initial commit 2021-12-02 19:30:27 -08:00
.github Initial commit 2021-12-02 19:30:27 -08:00
autoload Initial commit 2021-12-02 19:30:27 -08:00
doc Initial commit 2021-12-02 19:30:27 -08:00
lua/dressing Initial commit 2021-12-02 19:30:27 -08:00
plugin Initial commit 2021-12-02 19:30:27 -08:00
.gitignore Initial commit 2021-12-02 19:30:27 -08:00
.luacheckrc Initial commit 2021-12-02 19:30:27 -08:00
.stylua.toml Initial commit 2021-12-02 19:30:27 -08:00
LICENSE Initial commit 2021-12-02 19:30:27 -08:00
README.md Initial commit 2021-12-02 19:30:27 -08:00

README.md

Dressing.nvim

With the release of Neovim 0.6 we were given the start of extensible core UI hooks (vim.ui.select and vim.ui.input). They exist to allow plugin authors to override them with improvements upon the default behavior, so that's exactly what we're going to do.

It is a goal to match and not extend the core Neovim API. All options that core respects will be respected, and we will not accept any custom parameters or options in the functions. Customization will be done entirely using a separate configuration method.

Requirements

Neovim 0.5+

On versions prior to 0.6, this plugin will act as a polyfill for vim.ui

Installation

dressing.nvim supports all the usual plugin managers

Packer
require('packer').startup(function()
    use {'stevearc/dressing.nvim'}
end)
Paq
require "paq" {
    {'stevearc/dressing.nvim'};
}
vim-plug
Plug 'stevearc/dressing.nvim'
dein
call dein#add('stevearc/dressing.nvim')
Pathogen
git clone --depth=1 https://github.com/stevearc/dressing.nvim.git ~/.vim/bundle/
Neovim native package
git clone --depth=1 https://github.com/stevearc/dressing.nvim.git \
  "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/dressing.nvim/start/dressing.nvim

Configuration

If you're fine with the defaults, you're good to go after installation. If you want to tweak, call this function:

require('dressing').setup({
  input = {
    -- Default prompt string
    default_prompt = "➤ ",

    -- These are passed to nvim_open_win
    anchor = "SW",
    relative = "cursor",
    row = 0,
    col = 0,
    border = "rounded",

    -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
    prefer_width = 40,
    max_width = nil,
    min_width = 20,

    -- see :help dressing_get_config
    get_config = nil,
  },
  select = {
    -- Priority list of preferred vim.select implementations
    backend = { "telescope", "fzf", "builtin", "nui" },

    -- Options for telescope selector
    telescope = {},

    -- Options for fzf selector
    fzf = {
      width = 0.5,
      height = 0.4,
    },

    -- Options for nui Menu
    nui = {
      position = "50%",
      size = nil,
      relative = "editor",
      border = {
        style = "rounded",
      },
      max_width = 80,
      max_height = 40,
    },

    -- Options for built-in selector
    builtin = {
      -- These are passed to nvim_open_win
      anchor = "NW",
      relative = "cursor",
      row = 0,
      col = 0,
      border = "rounded",

      -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
      width = nil,
      max_width = 0.8,
      min_width = 40,
      height = nil,
      max_height = 0.9,
      min_height = 10,
    },

    -- see :help dressing_get_config
    get_config = nil,
  },
})

Custom config per usage

For each of the input and select configs, there is an option get_config. This can be a function that accepts the opts parameter that is passed in to vim.select or vim.input. It must return either nil (to no-op) or config values to use in place of the global config values for that module.

For example, if you want to use a specific configuration for code actions:

require('dressing').setup({
  select = {
    get_config = function(opts)
      if opts.kind == 'codeaction' then
        return {
          backend = 'nui',
          nui = {
            relative = 'cursor',
            max_width = 40,
          }
        }
      end
    end
  }
})

Similar projects

  • nvim-notify - doing pretty much the same thing but for vim.notify
  • nui.nvim - provides common UI components for plugin authors