Skip to content
项目

关于

A Neovim plugin that repositions the cmdline as a centered floating window, powered by Neovim's native ui2 system.

开发工具

这些数字如何统计

224 星标7 复刻 +1 24小时

实测星标增长

24小时
+1
7天
+2
15天
+2
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

📍tiny-cmdline.nvim

Neovim

A Neovim plugin that repositions the cmdline as a centered floating window, powered by Neovim's native ui2 system.

image

Table of Contents

Requirements

  • Neovim >= 0.12
  • cmdheight=0 (better to have for ui2)
  • ui2 must be enabled explicitly:
    require("vim._core.ui2").enable({})
    

Installation

The plugin is setup-less: it auto-initializes on UIEnter with sensible defaults. No setup() call is required.

There are three ways to configure it:

  • Minimal: just install and set cmdheight=0
  • vim.g: set vim.g.tiny_cmdline before the plugin loads (no setup() needed)
  • setup(): explicit call, takes priority over vim.g

vim.pack (Neovim built-in, >= 0.12)

Minimal:

vim.o.cmdheight = 0
vim.pack.add({ "https://github.com/rachartier/tiny-cmdline.nvim" })

With vim.g:

vim.o.cmdheight = 0
vim.g.tiny_cmdline = {
    width = { value = "70%" },
}
vim.pack.add({ "https://github.com/rachartier/tiny-cmdline.nvim" })

With setup():

vim.pack.add({
    "https://github.com/rachartier/tiny-cmdline.nvim",
    config = function()
        vim.o.cmdheight = 0
        require("tiny-cmdline").setup()
    end,
})

lazy.nvim

Minimal:

{
    "rachartier/tiny-cmdline.nvim",
    init = function()
        vim.o.cmdheight = 0
    end,
}

With vim.g:

{
    "rachartier/tiny-cmdline.nvim",
    init = function()
        vim.o.cmdheight = 0
        vim.g.tiny_cmdline = {
            width = { value = "70%" },
        }
    end,
}

With setup():

{
    "rachartier/tiny-cmdline.nvim",
    config = function()
        vim.o.cmdheight = 0
        require("tiny-cmdline").setup()
    end,
}

Configuration

Full default configuration
require("tiny-cmdline").setup({
    -- Cmdline window width
    width = {
        value = "60%",  -- "N%" = fraction of editor columns, integer = absolute columns
        min = 40,       -- minimum width in columns
        max = 80,       -- maximum width in columns
    },

    -- Window position ("N%" = fraction of available space, integer = absolute columns/rows)
    position = {
        x = "50%",  -- horizontal: "0%" = left, "50%" = center, "100%" = right
        y = "50%",  -- vertical:   "0%" = top,  "50%" = center, "100%" = bottom
    },

    -- Border style for the floating window
    -- nil inherits vim.o.winborder at setup() time, falling back to "rounded"
    -- Set to "none" to disable the border
    border = nil,

    -- Horizontal offset of the completion menu anchor from the window's left inner edge
    -- Used to align blink.cmp / nvim-cmp menus with the cmdline window
    menu_col_offset = 3,

    -- Cmdline types rendered at the bottom of the screen instead of centered
    -- "/" and "?" (search) are kept native by default
    native_types = { "/", "?" },

    -- Dynamic popup title (rendered on the floating border)
    -- Disabled by default; set enabled = true to opt in
    -- Has no effect when border = "none" or when the cmdline is rendered via native_types
    title = {
        enabled = false,
        pos = "center",  -- "left" | "center" | "right"
    },

    -- Optional callback invoked after every reposition
    on_reposition = nil,
})

Highlight Groups

Group Default link Description
TinyCmdlineNormal MsgArea Background of the cmdline window
TinyCmdlineBorder FloatBorder Border of the cmdline window
TinyCmdlineTitle FloatTitle Title shown on the border

Override them in your colorscheme or config:

vim.api.nvim_set_hl(0, "TinyCmdlineBorder", { fg = "#your_color" })
vim.api.nvim_set_hl(0, "TinyCmdlineNormal", { bg = "#your_color" })

Events

Event Description
User TinyCmdlineMoved Fired after the cmdline window is moved or resized (position or width changed). vim.g.ui_cmdline_pos is already updated when it fires.

The event is triggered from within ui2's cmdline handlers, so wrap anything that redraws or feeds keys in vim.schedule():

vim.api.nvim_create_autocmd("User", {
    pattern = "TinyCmdlineMoved",
    callback = function()
        vim.schedule(function()
            -- e.g. reposition your own completion menu using vim.g.ui_cmdline_pos
        end)
    end,
})

On Neovim 0.12, tiny-cmdline itself listens to this event to move an open wildmenu popup (built-in completion) along with the window. From 0.13 the popup follows the window natively.

How It Works

tiny-cmdline hooks into Neovim's internal vim._core.ui2 system, which manages the floating cmdline window introduced in Neovim 0.12. It wraps ui2's cmdline_show and cmdline_hide handlers: on every show it repositions that window to the center of the editor, and once the last cmdline level is hidden it restores ui2's original window state so that post-command messages still render correctly at the bottom. Nested cmdlines (e.g. <C-r>=) and cmdline blocks (e.g. :function) keep the centered window until they are fully closed.

Cmdline types listed in native_types (search by default) are left to ui2, which renders them at the bottom at full width, preserving the native search experience.

The window position is also updated on VimResized and TabEnter to stay correctly centered after layout changes.

Integrations

tiny-cmdline is compatible with the most common completion plugins. The table below summarises compatibility details for each.

Plugin Menu repositions on open Menu repositions on window resize Extra config required
blink.cmp :heavy_check_mark: with adapter :heavy_check_mark: with adapter :heavy_check_mark: see below
nvim-cmp :heavy_check_mark: :x: (not yet supported) :x:
mini.cmdline :heavy_check_mark: :x: (not yet supported) :x:
Default (built-in) :heavy_check_mark: :x: (not yet supported) :x:

blink.cmp

blink.cmp manages its own menu position independently. Use the built-in adapter so it follows the repositioned cmdline window:

require("tiny-cmdline").setup({
    on_reposition = require("tiny-cmdline").adapters.blink,
})

Troubleshooting

  • Cmdline stays at the bottom: Ensure vim.o.cmdheight = 0 is set before the plugin initializes (use init in lazy.nvim, or set it early in your config).
  • Completion menu misaligned: Tune menu_col_offset to match your border/padding.
  • Border doesn't match the rest of Neovim: Leave border = nil to inherit vim.o.winborder.
  • Search feels different: / and ? are in native_types by default and rendered at the bottom; remove them from that list to also center them.
  • Pending keys not shown (e.g. d3, c3, y3): either move it to statusline with vim.o.showcmdloc = "statusline", or just show cmdline at the bottom. If you do choose statusline just remember to put the %S item into your statusline configuration.
  • Macro recording indicator not shown (recording @a): either add the vim.fn.reg_recording() in your statusline configuration, or just show cmdline at the bottom.

探索相关项目

加载中…