• Stars
    star
    1,382
  • Rank 32,716 (Top 0.7 %)
  • Language
    Lua
  • License
    MIT License
  • Created almost 3 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UI Component Library for Neovim.

GitHub Workflow Status: CI Coverage Version License

nui.nvim

UI Component Library for Neovim.

Requirements

Installation

Install the plugins with your preferred plugin manager. For example, with vim-plug:

Plug 'MunifTanjim/nui.nvim'

Blocks

NuiText

Quickly add highlighted text on the buffer.

Check Detailed Documentation for nui.text

Check Wiki Page for nui.text

NuiLine

Quickly add line containing highlighted text chunks on the buffer.

Check Detailed Documentation for nui.line

Check Wiki Page for nui.line

NuiTable

Quickly render table-like structured content on the buffer.

Check Detailed Documentation for nui.table

Check Wiki Page for nui.table

NuiTree

Quickly render tree-like structured content on the buffer.

Check Detailed Documentation for nui.tree

Check Wiki Page for nui.tree

Components

Layout

Layout GIF

local Popup = require("nui.popup")
local Layout = require("nui.layout")

local popup_one, popup_two = Popup({
  enter = true,
  border = "single",
}), Popup({
  border = "double",
})

local layout = Layout(
  {
    position = "50%",
    size = {
      width = 80,
      height = "60%",
    },
  },
  Layout.Box({
    Layout.Box(popup_one, { size = "40%" }),
    Layout.Box(popup_two, { size = "60%" }),
  }, { dir = "row" })
)

local current_dir = "row"

popup_one:map("n", "r", function()
  if current_dir == "col" then
    layout:update(Layout.Box({
      Layout.Box(popup_one, { size = "40%" }),
      Layout.Box(popup_two, { size = "60%" }),
    }, { dir = "row" }))

    current_dir = "row"
  else
    layout:update(Layout.Box({
      Layout.Box(popup_two, { size = "60%" }),
      Layout.Box(popup_one, { size = "40%" }),
    }, { dir = "col" }))

    current_dir = "col"
  end
end, {})

layout:mount()

Check Detailed Documentation for nui.layout

Check Wiki Page for nui.layout

Popup

Popup GIF

local Popup = require("nui.popup")
local event = require("nui.utils.autocmd").event

local popup = Popup({
  enter = true,
  focusable = true,
  border = {
    style = "rounded",
  },
  position = "50%",
  size = {
    width = "80%",
    height = "60%",
  },
})

-- mount/open the component
popup:mount()

-- unmount component when cursor leaves buffer
popup:on(event.BufLeave, function()
  popup:unmount()
end)

-- set content
vim.api.nvim_buf_set_lines(popup.bufnr, 0, 1, false, { "Hello World" })

Check Detailed Documentation for nui.popup

Check Wiki Page for nui.popup

Input

Input GIF

local Input = require("nui.input")
local event = require("nui.utils.autocmd").event

local input = Input({
  position = "50%",
  size = {
    width = 20,
  },
  border = {
    style = "single",
    text = {
      top = "[Howdy?]",
      top_align = "center",
    },
  },
  win_options = {
    winhighlight = "Normal:Normal,FloatBorder:Normal",
  },
}, {
  prompt = "> ",
  default_value = "Hello",
  on_close = function()
    print("Input Closed!")
  end,
  on_submit = function(value)
    print("Input Submitted: " .. value)
  end,
})

-- mount/open the component
input:mount()

-- unmount component when cursor leaves buffer
input:on(event.BufLeave, function()
  input:unmount()
end)

Check Detailed Documentation for nui.input

Check Wiki Page for nui.input

Menu

Menu GIF

local Menu = require("nui.menu")
local event = require("nui.utils.autocmd").event

local menu = Menu({
  position = "50%",
  size = {
    width = 25,
    height = 5,
  },
  border = {
    style = "single",
    text = {
      top = "[Choose-an-Element]",
      top_align = "center",
    },
  },
  win_options = {
    winhighlight = "Normal:Normal,FloatBorder:Normal",
  },
}, {
  lines = {
    Menu.item("Hydrogen (H)"),
    Menu.item("Carbon (C)"),
    Menu.item("Nitrogen (N)"),
    Menu.separator("Noble-Gases", {
      char = "-",
      text_align = "right",
    }),
    Menu.item("Helium (He)"),
    Menu.item("Neon (Ne)"),
    Menu.item("Argon (Ar)"),
  },
  max_width = 20,
  keymap = {
    focus_next = { "j", "<Down>", "<Tab>" },
    focus_prev = { "k", "<Up>", "<S-Tab>" },
    close = { "<Esc>", "<C-c>" },
    submit = { "<CR>", "<Space>" },
  },
  on_close = function()
    print("Menu Closed!")
  end,
  on_submit = function(item)
    print("Menu Submitted: ", item.text)
  end,
})

-- mount the component
menu:mount()

Check Detailed Documentation for nui.menu

Check Wiki Page for nui.menu

Split

Split GIF

local Split = require("nui.split")
local event = require("nui.utils.autocmd").event

local split = Split({
  relative = "editor",
  position = "bottom",
  size = "20%",
})

-- mount/open the component
split:mount()

-- unmount component when cursor leaves buffer
split:on(event.BufLeave, function()
  split:unmount()
end)

Check Detailed Documentation for nui.split

Check Wiki Page for nui.split

Extendibility

Each of the blocks and components can be extended to add new methods or change their behaviors.

local Timer = Popup:extend("Timer")

function Timer:init(popup_options)
  local options = vim.tbl_deep_extend("force", popup_options or {}, {
    border = "double",
    focusable = false,
    position = { row = 0, col = "100%" },
    size = { width = 10, height = 1 },
    win_options = {
      winhighlight = "Normal:Normal,FloatBorder:SpecialChar",
    },
  })

  Timer.super.init(self, options)
end

function Timer:countdown(time, step, format)
  local function draw_content(text)
    local gap_width = 10 - vim.api.nvim_strwidth(text)
    vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, {
      string.format(
        "%s%s%s",
        string.rep(" ", math.floor(gap_width / 2)),
        text,
        string.rep(" ", math.ceil(gap_width / 2))
      ),
    })
  end

  self:mount()

  local remaining_time = time

  draw_content(format(remaining_time))

  vim.fn.timer_start(step, function()
    remaining_time = remaining_time - step

    draw_content(format(remaining_time))

    if remaining_time <= 0 then
      self:unmount()
    end
  end, { ["repeat"] = math.ceil(remaining_time / step) })
end

local timer = Timer()

timer:countdown(10000, 1000, function(time)
  return tostring(time / 1000) .. "s"
end)

nui.object

A small object library is bundled with nui.nvim. It is, more or less, a clone of the kikito/middleclass library.

Check Wiki Page for nui.object

License

Licensed under the MIT License. Check the LICENSE file for details.

More Repositories

1

minimo

Minimo - Minimalist theme for Hugo
HTML
531
star
2

prettier.nvim

Prettier plugin for Neovim's built-in LSP client.
Lua
262
star
3

nougat.nvim

🍫 Hyperextensible Statusline / Tabline / Winbar for Neovim 🚀
Lua
185
star
4

tmux-suspend

Plugin that lets you suspend local tmux session, so that you can work with nested remote tmux session painlessly.
Shell
114
star
5

tmux-mode-indicator

Plugin that displays prompt indicating currently active Tmux mode.
Shell
108
star
6

node-bitbucket

Bitbucket API client for Browser and Node.js
JavaScript
95
star
7

exrc.nvim

Secure Project Local Config for Neovim
Lua
56
star
8

tree-sitter-lua

Lua grammar for tree-sitter.
C
40
star
9

eslint.nvim

ESLint plugin for Neovim's built-in LSP client.
Lua
35
star
10

gatsby-theme-dox

Documentation made easy with Gatsby. 🎉
JavaScript
31
star
11

scripts.sh

Handy Shell Scripts
Shell
21
star
12

luver

Version manager for Lua, built with ❤️
Shell
21
star
13

zed

ZSH Plugin Manager
Shell
20
star
14

node-bkash

bKash API client for Browser & Node.js
JavaScript
17
star
15

nvim-treesitter-lua

Tree-sitter Lua parser integration for nvim-treesitter.
Scheme
12
star
16

oclif-plugin-completion

oclif plugin for generating shell completions
TypeScript
10
star
17

stapsher

API service for handling user-generated contents on static sites
JavaScript
9
star
18

gmail-oauth2-script

Script to get OAuth2 Access Token for Gmail.
Shell
6
star
19

express-zod-openapi

Express + Zod + OpenAPI
TypeScript
6
star
20

express-joi-openapi

Express + Joi + OpenAPI
TypeScript
6
star
21

regio

University Department Information Management Software
JavaScript
4
star
22

anontius

Personal Asking Portal (like ASK.fm)
JavaScript
4
star
23

draft-js-modules

Draft.js Modules
TypeScript
4
star
24

octoherd-script-set-pr-merge-config

An octoherd script to set pull request merge config
JavaScript
4
star
25

setup-neovim-action

🚀 Setup Neovim on Github Actions.
Shell
4
star
26

luver-action

🌛 Set up your GitHub Actions workflow with specific versions of Lua, LuaJIT, LuaRocks using Luver ❤️
Shell
3
star
27

llhttp.lua

Lua interface for https://github.com/nodejs/llhttp
C
3
star
28

is-mobile-phone-number-bd

Mobile phone number validator for Bangladesh
TypeScript
3
star
29

lua-evdev

LuaJIT FFI Bindings for libevdev.
Lua
3
star
30

rofunicode

Unicode Character Picker for Rofi
JavaScript
2
star
31

gist-embedder

Library for Embedding GitHub Gist
JavaScript
2
star
32

lua-udev

LuaJIT FFI Bindings for libudev.
Lua
2
star
33

kee

🖱 ⌨ Do amazing things with Keys...
Shell
1
star
34

middleware-pipeline

Simple Middleware Pipeline
TypeScript
1
star
35

js-set-time

Sets time to Date instance.
TypeScript
1
star
36

hashicorp-vault

HashiCorp Vault API client for Node.js
JavaScript
1
star
37

unoti

Unified Notification
TypeScript
1
star
38

npm-package-template

NPM Package Template
JavaScript
1
star
39

luarocks-publish-action

🌛 Publish to LuaRocks using GitHub Actions
JavaScript
1
star
40

Exercism

👨‍💻 Exercism Solutions
Rust
1
star
41

freeCodeCamp-FrontEnd-Projects

freeCodeCamp Front End Development Projects
JavaScript
1
star
42

x-git-hooks

Git Hooks Handler
Rust
1
star
43

bitbucket-api-routes

Machine-readable, Bitbucket API routes specifications
JavaScript
1
star
44

freeCodeCamp-React-Projects

(freeCodeCamp) React Projects
JavaScript
1
star