Automatically toggles smoothly between relative and absolute line numbers on various Neovim events. This is useful when you want to take advantage of both types of line numbers in different situations.
{
"cpea2506/relative-toggle.nvim"
}
- Neovim >= 0.8.0
Once installed, this plugin is activated automatically. No setup is required unless you want to customize the options.
Option | Description | Type | Note |
---|---|---|---|
pattern |
Patterns where the plugin should be enabled | string|table |
:h autocmd-pattern |
events.on |
Events that turn relative numbers on | string|table |
:h autocmd-events |
events.off |
Events that turn relative numbers off | string|table |
:h autocmd-events |
require("relative-toggle").setup({
pattern = "*",
events = {
on = { "BufEnter", "FocusGained", "InsertLeave", "WinEnter", "CmdlineLeave" },
off = { "BufLeave", "FocusLost", "InsertEnter", "WinLeave", "CmdlineEnter" },
},
})
-
The keymap
Ctrl-C
does not trigger theInsertLeave
event (:h i_CTRL-C
), so you’ll need to use another keymap that does. For example:- Built-in keymaps:
Esc
,Ctrl-[
,Ctrl-o
, ... - Escape-mapping plugins: better-escape, houdini, ...
- Built-in keymaps:
-
To ensure the numbers actually toggle (lol), when you define an event in the
events.on
table, you should also define its corresponding "off" event in theevents.off
table. For example:BufEnter
-BufLeave
,VimEnter
-VimLeave
, ... -
The
relativenumber
option is always enabled by default. So, based on the value ofvim.opt.number
, the line numbers displayed relative to the cursor will change as follows (:h number_relativenumber
):'nonu' 'nu' 'rnu' 'rnu' | 2 apple | 2 apple | 1 pear | 1 pear |0 nobody |3 nobody | 1 there | 1 there
For detailed instructions on how to contribute to this plugin, please see the contributing guidelines.