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
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,29 @@ return {
fg = palette.mantle,
bold = true,
},
}
},
hide_inactive_cursorline = false,
})
end
}
```

## Hiding inactive cursorlines

It's off by defaut, but if you set `hide_inactive_cursorline = true`, then this plugin will hide the cursorline for inactive windows so the mode highlight will only be shown in the currently active window:

![Screenshot 2024-10-24 at 12 16 58](https://github.com/user-attachments/assets/2286df66-af72-43e7-b4fc-305f696ad206)

Note: if you're lazy loading this plugin and want to hide inactive window cursorlines, make sure `event` is either set to `VeryLazy` or as follows:

```lua
return {
'sethen/line-number-change-mode.nvim',
event = { 'ModeChanged', 'WinEnter', 'WinLeave' },
...
}
```

# Similar Plugins ❤️
* [Moody](https://github.com/svampkorg/moody.nvim)
* [Modicator](https://github.com/mawkler/modicator.nvim)
52 changes: 52 additions & 0 deletions lua/line-number-change-mode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function M.setup(opts)
vim.cmd.redraw()
end
end

-- Keep track of mode because we don't get a ModeChanged event when
-- opening a file from Telescope. See:
-- https://github.com/sethen/line-number-change-mode.nvim/issues/7
M.mode = mode
end

set_hl_for_mode(va.nvim_get_mode().mode)
Expand All @@ -33,6 +38,53 @@ function M.setup(opts)
set_hl_for_mode(new_mode)
end,
})

if opts.hide_inactive_cursorline then
vim.api.nvim_create_autocmd({ "WinEnter" }, {
group = group,
callback = function(_)
local win = vim.api.nvim_get_current_win()
-- vim.notify(e.event..', win: '..win..' cl: '..vim.inspect(vim.wo.cursorline)..' had: '..vim.inspect(vim.w[win].hadcursorline))

-- if the cursorline was supposed to be on, turn it back on
if vim.w[win].hadcursorline and not vim.wo.cursorline then
vim.wo.cursorline = true
end
end,
})
end

vim.api.nvim_create_autocmd({ "WinLeave" }, {
group = group,
callback = function(_)
if opts.hide_inactive_cursorline then
-- vim.notify(e.event..', win: '..win..' cl: '..vim.inspect(vim.wo.cursorline)..' had: '..vim.inspect(vim.w[win].hadcursorline))

-- If the cursorline is on, turn it off but remember that we turned it off
if vim.wo.cursorline then
local win = vim.api.nvim_get_current_win()
vim.wo.cursorline = false
vim.w[win].hadcursorline = true

-- vim.notify('turning off cursorline for: '..win..' hadcursorline: '..vim.inspect(vim.w[win].hadcursorline))
end
end

-- If we're leaving a window and we're still in insert mode, schedule
-- a callback for the next run of the event loop to make sure the
-- correct mode highlight is displayed. See:
-- https://github.com/sethen/line-number-change-mode.nvim/issues/7
if M.mode == 'i' then
vim.schedule(function()
if opts.debug then
vim.notify('in insert mode, will schedule mode set')
end
set_hl_for_mode(vim.api.nvim_get_mode().mode)
end)
end
end,
})

end

return M