๐๏ธ relative-toggle.nvim
April 7, 2025 ยท View on GitHub
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.
๐ Installation
{
"cpea2506/relative-toggle.nvim"
}
Requirements
- Neovim >= 0.8.0
โ๏ธ Setup
Once installed, this plugin is activated automatically. No setup is required unless you want to customize the options.
Available 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 |
Default Configuration
require("relative-toggle").setup({
pattern = "*",
events = {
on = { "BufEnter", "FocusGained", "InsertLeave", "WinEnter", "CmdlineLeave" },
off = { "BufLeave", "FocusLost", "InsertEnter", "WinLeave", "CmdlineEnter" },
},
})
๐ก Tips
-
The keymap
Ctrl-Cdoes not trigger theInsertLeaveevent (: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.ontable, you should also define its corresponding "off" event in theevents.offtable. For example:BufEnter-BufLeave,VimEnter-VimLeave, ... -
The
relativenumberoption 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
:eyes: Inspiration
:scroll: Contribution
For detailed instructions on how to contribute to this plugin, please see the contributing guidelines.