Automatically toggling smoothly between relative and absolute line numbers in various Neovim events. This is useful when you want to take advantage of the information on those types of numbers in different situations.
use "cpea2506/relative-toggle.nvim"
- Neovim >= 0.7.2
After installed, this plugin will automatically active so no setup statement is required unless you want to custom some options.
Option | Description | Type | Note |
---|---|---|---|
pattern |
pattern where the plugin should be enable | string/table |
:h autocmd-pattern |
events.on |
event to toggle relative number on | string/table |
:h autocmd-events |
events.off |
event to toggle relative number 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 need to use another keymap that has a capability to do it. For ex:- Builtin keymap:
Esc
,Ctrl-[
,Ctrl-o
,... - Escape mapping plugins: better-escape, houdini,...
- Builtin keymap:
-
To make sure the numbers really toggle (lol), when you define an event in
events.on
table, you should define its opposite event inevents.off
table. For ex:BufEnter - BufLeave
,VimEnter - VimLeave
,... -
The
relativenumber
is always on by default. So based on the value ofvim.opt.number
, the displayed number to be relative to the cursor will be changed 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
Please see the contributing guidelines for detailed instructions on how to contribute to this project.