Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Use your favorite package manager. Example config with [packer.nvim](https://git
use { "sitiom/nvim-numbertoggle" }
```

## Disabling

This plugin can be disabled in two ways:

- Globally: set `vim.g.numbertoggle_disable` to `true`.
- Locally for a buffer: set `vim.b.numbertoggle_disable` to `true`.

## Acknowledgment

https://github.com/jeffkreeftmeijer/vim-numbertoggle
22 changes: 19 additions & 3 deletions plugin/numbertoggle.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
local augroup = vim.api.nvim_create_augroup("numbertoggle", {})

local function is_disabled(buf)
if vim.g.numbertoggle_disable then
return true
end
if not vim.api.nvim_buf_is_valid(buf) then
return nil
end
return vim.b[buf or 0].numbertoggle_disable
end

vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "CmdlineLeave", "WinEnter" }, {
pattern = "*",
group = augroup,
callback = function()
callback = function(args)
if is_disabled(args.buf) then
return
end
if vim.o.nu and vim.api.nvim_get_mode().mode ~= "i" then
vim.opt.relativenumber = true
end
Expand All @@ -13,12 +26,15 @@ vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "Cmdline
vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "CmdlineEnter", "WinLeave" }, {
pattern = "*",
group = augroup,
callback = function()
callback = function(args)
if is_disabled(args.buf) then
return
end
if vim.o.nu then
vim.opt.relativenumber = false
-- Conditional taken from https://github.com/rockyzhang24/dotfiles/commit/03dd14b5d43f812661b88c4660c03d714132abcf
-- Workaround for https://github.com/neovim/neovim/issues/32068
if not vim.tbl_contains({"@", "-"}, vim.v.event.cmdtype) then
if not vim.tbl_contains({ "@", "-" }, vim.v.event.cmdtype) then
vim.cmd "redraw"
end
end
Expand Down