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"
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 the InsertLeave
event (:h i_CTRL-C
) so you need to use another keymap that has a capability to do it. For ex:
Esc
, Ctrl-[
, Ctrl-o
,...To make sure the numbers really toggle (lol), when you define an event in events.on
table, you should define its opposite event in events.off
table. For ex: BufEnter - BufLeave
, VimEnter - VimLeave
,...
The relativenumber
is always on by default. So based on the value of vim.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.