folke / noice.nvim
- четверг, 6 октября 2022 г. в 00:33:44
💥 Highly experimental plugin that completely replaces the UI for messages, cmdline and the popupmenu.
Highly experimental plugin that completely replaces the UI for messages, cmdline and the popupmenu.
:hi):Noice command to show a full message historyvim and lua on the cmdlineWIP
Install the plugin with your preferred package manager:
-- Packer
use({
"folke/noice.nvim",
event = "VimEnter",
config = function()
require("noice").setup()
end,
requires = {
-- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
"MunifTanjim/nui.nvim",
"rcarriga/nvim-notify",
}
})noice.nvim comes with the following defaults:
Check the wiki for configuration recipes.
{
cmdline = {
view = "cmdline_popup", -- view for rendering the cmdline. Change to `cmdline` to get a classic cmdline at the bottom
opts = { buf_options = { filetype = "vim" } }, -- enable syntax highlighting in the cmdline
icons = {
["/"] = { icon = " ", hl_group = "DiagnosticWarn" },
["?"] = { icon = " ", hl_group = "DiagnosticWarn" },
[":"] = { icon = " ", hl_group = "DiagnosticInfo", firstc = false },
},
},
popupmenu = {
enabled = true, -- disable if you use something like cmp-cmdline
---@type 'nui'|'cmp'
backend = "nui", -- backend to use to show regular cmdline completions
-- You can specify options for nui under `config.views.popupmenu`
},
history = {
-- options for the message history that you get with `:Noice`
view = "split",
opts = { enter = true },
filter = { event = "msg_show", ["not"] = { kind = { "search_count", "echo" } } },
},
throttle = 1000 / 30, -- how frequently does Noice need to check for ui updates? This has no effect when in blocking mode.
---@type table<string, NoiceViewOptions>
views = {}, -- @see the section on views below
---@type NoiceRouteConfig[]
routes = {}, -- @see the section on routes below
---@type table<string, NoiceFilter>
status = {}, --@see the section on statusline components below
}Noice uses filters to route messages to specific views.
| Name | Type | Description |
|---|---|---|
| cleared | boolean |
checks if the message is cleared, meaning it's in the history |
| mode | string |
checks if vim.api.nvim_get_mode() contains the given mode |
| blocking | boolean |
are we in blocking mode? |
| event | string or string[] |
any of the events from ext_messages or cmdline. See :h ui-messages |
| kind | string or string[] |
any of the kinds from ext_messages. See :h ui-messages |
| error | boolean |
all error-like kinds from ext_messages |
| warning | boolean |
all warning-like kinds from ext_messages |
| find | string |
uses lua string.find to match the pattern |
| min_height | number |
minimum height of the message |
| max_height | number |
maximum height of the message |
| not | filter |
checks wether the filter matches or not |
| any | filter[] |
checks that at least one of the filters matches |
-- all messages over 10 lines, excluding echo and search_count
local filter = {
event = "msg_show",
min_height = 10,
["not"] = { kind = { "search_count", "echo" } },
}
Noice comes with the following built-in backends:
search_count)A View (config.views) is a combination of a backend and options.
Noice comes with the following built-in views with sane defaults:
| View | Backend | Description |
|---|---|---|
| notify | notify |
nvim-notify with level=true, replace=true, merge=true |
| split | split |
horizontal split |
| vsplit | split |
vertical split |
| popup | popup |
simple popup |
| cmdline | popup |
bottom line, similar to the classic cmdline |
| cmdline_popup | popup |
fancy cmdline popup, with different styles according to the cmdline mode |
| popupmenu | nui.menu |
special view with the options used to render the popupmenu when backend is nui |
Please refer to noice.config.views
to see the options.
Any options passed to existing views in config.views, will override those options only.
You can configure completely new views and use them in custom routes.
-- override the default split view to always enter the split when it opens
require("noice").setup({
views = {
split = {
enter = true
}
}
})See the Nui documentation for Popup and Split.
| Option | Description |
| size, position | Size, position and their constituents can additionally be specified as "auto", to use the message height and width. |
| win_options.winhighlight |
String or can also be a table like:
{
win_options = {
winhighlight = {
Normal = "NormalFloat",
FloatBorder = "FloatBorder"
},
}
} |
| Option | Type | Default | Description |
|---|---|---|---|
| title | string |
nil |
title to be used for the notification. Uses Message.title if available. |
| replace | boolean |
true |
when true, messages routing to the same notify instance will replace existing messages instead of pushing a new notification every time |
| merge | boolean |
true |
Merge messages into one Notification or create separate notifications |
| level | `number\ | string` | "info" |
| highlight | boolean |
true |
Highlight message or render as plain text |
Right now there's only an option to set the hl_group used to render the virtual text.
A route has a filter, view and optional opts attribute.
Route options can be any of the view options above, or one of:
| Option | Type | Default | Description |
|---|---|---|---|
| skip | boolean |
false |
messages matching this filter will be skipped and not shown in any views |
| stop | boolean |
true |
When false and a route matches the filter, then other routes can still process the message too. Useful if you want certain messages to be shown in multiple views. |
Please refer to noice.config.routes
for an overview of the default routes.
Routes passed to setup() will be prepended to the default routes.
-- 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 },
},
},
})Noice comes with the following statusline components:
event=show_msg)showcmdshowmode (@recording messages)See noice.config.status for the default config.
You can add custom statusline components in setup under the status key.
Statusline components have the following methods:
require("lualine").setup({
sections = {
lualine_x = {
{
require("noice.status").message.get_hl,
cond = require("noice.status").message.has,
},
{
require("noice.status").command.get,
cond = require("noice.status").command.has,
color = { fg = "#ff9e64" },
},
{
require("noice.status").mode.get,
cond = require("noice.status").mode.has,
color = { fg = "#ff9e64" },
},
{
require("noice.status").search.get,
cond = require("noice.status").search.has,
color = { fg = "#ff9e64" },
},
},
},
})
:Noice shows the message history:Noice disable disables Noice:Noice enable enables Noice:Noice stats shows debugging statsNoice is using the new experimental vim.ui_attach API, so issues are to be expected.
During setup, we apply a bunch of Hacks
to work around some of the current issues.
For more details, see this tracking issue