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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ require('nvim-cursorline').setup {
enable = true,
timeout = 1000,
number = false,
disable_filetypes = {
'neo-tree'
},
},
cursorword = {
enable = true,
Expand Down
27 changes: 27 additions & 0 deletions lua/nvim-cursorline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ local wo = vim.wo
local fn = vim.fn
local hl = a.nvim_set_hl
local au = a.nvim_create_autocmd
local ag = a.nvim_create_augroup
local timer = vim.loop.new_timer()

local DEFAULT_OPTIONS = {
cursorline = {
enable = true,
timeout = 1000,
number = false,
disable_filetypes = {
'neo-tree'
},
},
cursorword = {
enable = true,
Expand Down Expand Up @@ -50,20 +54,32 @@ end
function M.setup(options)
M.options = vim.tbl_deep_extend("force", DEFAULT_OPTIONS, options or {})

local disabled_filetype_lookup = {}
for _, ft in ipairs(M.options.cursorline.disable_filetypes) do
disabled_filetype_lookup[ft] = true
end

local group_id = ag('nvim-cursorline', { clear = true })
if M.options.cursorline.enable then
wo.cursorline = true
au("WinEnter", {
group = group_id,
callback = function()
wo.cursorline = true
end,
})
au("WinLeave", {
group = group_id,
callback = function()
wo.cursorline = false
end,
})
au({ "CursorMoved", "CursorMovedI" }, {
group = group_id,
callback = function()
if disabled_filetype_lookup[vim.bo.filetype] then
return
end
if M.options.cursorline.number then
wo.cursorline = false
else
Expand All @@ -82,16 +98,27 @@ function M.setup(options)
)
end,
})
au("BufEnter", {
group = group_id,
callback = function()
if disabled_filetype_lookup[vim.bo.filetype] then
wo.cursorline = true
wo.cursorlineopt = "both"
end
end
})
end

if M.options.cursorword.enable then
au("VimEnter", {
group = group_id,
callback = function()
hl(0, "CursorWord", M.options.cursorword.hl)
matchadd()
end,
})
au({ "CursorMoved", "CursorMovedI" }, {
group = group_id,
callback = function()
matchadd()
end,
Expand Down