Forced relative line numbers (Please no)

For the life of me I can’t turn off relative line numbers.

Sure when I type :lua vim.opt.relativenumber = false it turns them to absolute numbering, but then when I switch windows it goes right back to relative line numbers being true.

I don’t mean to offend anyone here, but I can’t stand relative line numbers. So I changed my init.lua to just be

-- Packer
-- require('plugins')
-- Config
-- require('settings')
-- require('settings.color')
-- require('settings.font')
-- require('settings.completion')
-- require('settings.filetype')
-- LSP Config
-- require('lsp')
-- Keymap
-- require('settings.keymap')
vim.opt.relativenumber = false

(which basically comments out everything but the last line) … And the relative line numbers still show up when I switch windows.

Does anyone know how to turn relative line numbers off in nvim? This behavior does not exist in vim.

Using nvim version

NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Monterey

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.7.0/share/nvim"

and vim version:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 14 2022 19:43:56)
macOS version - x86_64
Included patches: 1-4750
Compiled by Homebrew

Can you share your complete configuration ? it seems there are an autocmd that set the relativenumber option on BufEnter/WinEnter event

Yes, I’d be glad to … How do I dump that to the terminal?

IDK if there is a way to dump it into the terminal, usually we keep it in the git repository

You can try copy-pasting to something like gist

You can also inspect those autocommands by dumping the output with verbose autocmd BufEnter and verbose autocmd WinEnter. You could even put them into a buffer like this:

" Create a new buffer
bufnew

" Redirect all messages to `g:output`
redir => g:output
silent verbose autocmd BufEnter
silent verbose autocmd WinEnter
redir END

" Paste the contents of g:output into the buffer
put =g:output

Then you can search the output with something like /rnu\|relativenumber to see if any of the autocommands modify that setting.

relativenumber is disabled by default in nvim so it could be some plugin that is enabling it or somewhere in your config that you might’ve missed.

You can do :verbose set relativenumber? to check from where it was set from, but sometimes it doesn’t give great information if it was set from a lua file.

A better way would be to use the builtin :vimgrep to check for any references of relativenumber or rnu (its short name) within your config dir:

:vimgrep /relativenumber\|rnu/ ~/.config/nvim/**/*

Opening the quickfix list with :copen should show you references as to where it is defined.

If it’s not in your config at all, then my next guess would be some plugin so might have to go thru them to find out.

2 Likes

Glory Hallejulah! The “verbose set relativenumber?” informed me that GitHub - jeffkreeftmeijer/vim-numbertoggle: Toggles between hybrid and absolute line numbers automatically was installed and setting relativenumber. As soon as I uninstalled that plugin, then all line numbers in all buffers are absolute!! Yay!
Thanks everyone.

I think the toughest thing about nvim is the LARGE temptation of choosing someone else’s set of plugins and then not combing through it before starting to use them. There are some great “sets” out there though. One of these days I want to compare and contrast them all.

Thanks again creativenull

1 Like