github github
stars 27
issues 0
subscribers 1
forks 1



2 months ago

🎚️ relative-toggle.nvim

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.


📦 Installation

use "cpea2506/relative-toggle.nvim"


  • Neovim >= 0.7.2

⚙️ Setup

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" },

💡 Tips

  1. 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:

  2. 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,...

  3. 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.