noice.nvim

repository·main·Indexed 27 days ago

https://github.com/folke/noice.nvim

An experimental Neovim plugin that replaces the UI for messages, the command line, and the popup menu. It provides highly configurable views, enhanced filtering, and LSP integration, including hover documentation and signature help. It requires nui.nvim and supports optional integrations with nvim-notify, telescope, and fzf-lua for message history searching.

Tokens
11.3K
Snippets
18
Records
20
Agent score
41%

What's inside noice.nvim

  1. Check Noice.nvim requirements and health

    main

    Ensure your environment meets the following requirements:

    • Neovim: >= 0.9.0 (Neovim nightly is highly recommended).
    • nui.nvim: Required for rendering and multiple views.
    • nvim-notify (Optional): For the notification view.
    • Nerd Font (Optional): For icons.
    • nvim-treesitter (Highly Recommended): For cmdline and LSP doc highlighting. Ensure you have parsers installed for: vim, regex, lua, bash, markdown, and markdown_inline.

    After installation, run :checkhealth noice to identify and resolve common issues.

  2. Search Message History with Pickers

    main

    You can view and search through your message history using pickers.

    • Generic Picker: Run :Noice pick to open a picker (using telescope or fzf-lua) containing all messages in history.
    • Telescope: Run :Noice telescope or register the extension and use :Telescope noice.
    • Fzf Lua: Run :Noice fzf.
  3. Install Noice.nvim

    main

    Install Noice.nvim using your preferred package manager. It requires nui.nvim as a dependency. nvim-notify is optional and used for the notification view (if not present, mini is used as a fallback).

    -- lazy.nvim
    {
      "folke/noice.nvim",
      event = "VeryLazy",
      opts = {
        -- add any options here
      },
      dependencies = {
        -- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
        "MunifTanjim/nui.nvim",
        -- OPTIONAL:
        --   `nvim-notify` is only needed, if you want to use the notification view.
        --   If not available, we use `mini` as the fallback
        "rcarriga/nvim-notify",
        }
    }
  4. Configure Noice.nvim

    main

    Initialize Noice.nvim using require("noice").setup(). You can configure LSP markdown overrides and use presets to quickly enable common UI behaviors like a command palette or bottom search bar.

    require("noice").setup({
      lsp = {
        -- override markdown rendering so that **cmp** and other plugins use **Treesitter**
        override = {
          ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
          ["vim.lsp.util.stylize_markdown"] = true,
          ["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp
        },
      },
      -- you can enable a preset for easier configuration
      presets = {
        bottom_search = true, -- use a classic bottom cmdline for search
        command_palette = true, -- position the cmdline and popupmenu together
        long_message_to_split = true, -- long messages will be sent to a split
        inc_rename = false, -- enables an input dialog for inc-rename.nvim
        lsp_doc_border = false, -- add a border to hover docs and signature help
      },
    })
  5. Use Noice presets

    main

    Noice provides several presets that can be enabled by setting them to true or providing a table to override the default configuration:

    • bottom_search: Uses a classic bottom cmdline for search.
    • command_palette: Positions the cmdline and popupmenu together.
    • long_message_to_split: Sends long messages to a split.
    • inc_rename: Enables an input dialog for inc-rename.nvim.
    • lsp_doc_border: Adds a border to hover docs and signature help.
    {
      presets = {
        bottom_search = false,
        command_palette = false,
        long_message_to_split = false,
        inc_rename = false,
        lsp_doc_border = false,
      },
    }
  6. Configure Noice Routes

    main

    Routes allow you to direct messages to specific views based on filters. A route consists of a filter, a view, and optional opts.

    When passing routes to setup(), they are prepended to the default routes.

    Route Options:

    • view: The target view (built-in or custom).
    • filter: Criteria for matching messages.
    • opts.skip (boolean, default: false): If true, matching messages are skipped and not shown in any views.
    • opts.stop (boolean, default: true): If false, other routes can still process the message after this one matches. Set to false if you want a message to appear in multiple views.
    -- skip search_count messages instead of showing them as virtual text
    require("noice").setup({
      routes = {
        {
          filter = { event = "msg_show", kind = "search_count" },
          opts = { skip = true },
        },
      },
    })
    
    -- always route any messages with more than 20 lines to the split view
    require("noice").setup({
      routes = {
        {
          view = "split",
          filter = { event = "msg_show", min_height = 20 },
        },
      },
    })
  7. Configure the cmdline UI

    main

    The cmdline configuration block controls the Noice command line interface. You can enable/disable it, choose the rendering view (e.g., cmdline_popup or cmdline for a classic bottom bar), and customize the format for different command types like lua, help, or search. Each format entry can specify a pattern, icon, and lang (language) for syntax highlighting.

    {
      cmdline = {
        enabled = true,
        view = "cmdline_popup",
        opts = {},
        format = {
          cmdline = { pattern = "^:", icon = "", lang = "vim" },
          search_down = { kind = "search", pattern = "^/", icon = " ", lang = "regex" },
          search_up = { kind = "search", pattern = "^%?", icon = " ", lang = "regex" },
          filter = { pattern = "^:%s*!", icon = "$", lang = "bash" },
          lua = { pattern = { "^:%s*lua%s+", "^:%s*lua%s*=%s*", "^:%s*=%s*" }, icon = "", lang = "lua" },
          help = { pattern = "^:%s*he?l?p?%s+", icon = "" },
          input = { view = "cmdline_input", icon = "󰥻 " },
        },
      },
    }
  8. Configure Noice views

    main

    A View (config.views) combines a backend with specific options. You can override default views or create new ones. Built-in backends include popup, split, notify, virtualtext, mini, and notify_send.

    Built-in Views

    • notify: Uses nvim-notify.
    • split / vsplit: Horizontal or vertical splits.
    • popup: Simple popup.
    • mini: Minimal view (bottom right, right-aligned).
    • cmdline / cmdline_popup: Command line interfaces.
    • messages: Split used for :messages.
    • confirm: Popup for confirm events.
    • hover: Popup for LSP signature help/hover.
    • popupmenu: Special view for nui.menu.

    Backend-Specific Options

    Nui Options (popup, split)

    • size, position: Can be set to "auto" to use message dimensions.
    • win_options.winhighlight: Set window highlights (e.g., Normal, FloatBorder).
    • scrollbar: Set to false to hide.

    Notify Options (nvim-notify)

    • title: Notification title (defaults to "Notification").
    • replace: If true, replaces existing messages in the same instance.
    • merge: If true, merges messages into one notification.
    • level: Notification level.
    -- override the default split view to always enter the split when it opens
    require("noice").setup({
      views = {
        split = {
          enter = true,
        },
      },
    })
  9. Configure messages and notifications

    main

    The messages configuration controls how Neovim messages are displayed. Enabling messages automatically enables the cmdline. You can specify different views for different message types: view (default), view_error, view_warn, view_history (for :messages), and view_search (for search count messages).

    {
      messages = {
        enabled = true,
        view = "notify",
        view_error = "notify",
        view_warn = "notify",
        view_history = "messages",
        view_search = "virtualtext",
      },
    }
  10. Configure LSP features

    main

    The lsp configuration block provides granular control over Language Server Protocol integration, including:

    • progress: Controls the display of LSP progress messages (e.g., indexing).
    • hover: Configures the UI for LSP hover documentation.
    • signature: Configures automatic signature help when typing trigger characters or jumping through snippets.
    • message: Configures messages sent by LSP servers.
    • override: Allows overriding default LSP markdown formatters or cmp documentation behavior.
    {
      lsp = {
        progress = {
          enabled = true,
          format = "lsp_progress",
          format_done = "lsp_progress_done",
          throttle = 1000 / 30,
          view = "mini",
        },
        hover = {
          enabled = true,
          silent = false,
          view = nil,
          opts = {},
        },
        signature = {
          enabled = true,
          auto_open = {
            enabled = true,
            trigger = true,
            luasnip = true,
            throttle = 50,
          },
          view = nil,
          opts = {},
        },
        message = {
          enabled = true,
          view = "notify",
          opts = {},
        },
        documentation = {
          view = "hover",
          opts = {
            lang = "markdown",
            replace = true,
            render = "plain",
            format = { "{message}" },
            win_options = { concealcursor = "n", conceallevel = 3 },
          },
        },
      },
    }
  11. Define custom Noice commands

    main

    You can add custom commands to the commands table. These will be available via the :Noice command. Each command defines a view, opts, and a filter to determine which messages are captured by that command (e.g., history, last, errors, or all).

    {
      commands = {
        history = {
          view = "split",
          opts = { enter = true, format = "details" },
          filter = {
            any = {
              { event = "notify" },
              { error = true },
              { warning = true },
              { event = "msg_show", kind = { "" } },
              { event = "lsp", kind = "message" },
            },
          },
        },
        errors = {
          view = "popup",
          opts = { enter = true, format = "details" },
          filter = { error = true },
          filter_opts = { reverse = true },
        },
      },
    }
  12. Configure the popupmenu

    main

    The popupmenu configuration manages the UI for command line completions. You can choose between nui or cmp as the backend. You can also provide custom kind_icons for completion items or set kind_icons = false to disable them.

    {
      popupmenu = {
        enabled = true,
        backend = "nui",
        kind_icons = {},
      },
    }