Skip to content

Commit

Permalink
feat: add option to disable cursor highlights
Browse files Browse the repository at this point in the history
fixes #11
  • Loading branch information
mvllow committed Feb 26, 2022
1 parent d4a9f65 commit 57fb7a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
16 changes: 12 additions & 4 deletions lua/modes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ function modes.set_colors()
normal = util.get_bg_from_hl('Normal', 'Normal'),
}
colors = {
copy = config.colors.copy or util.get_bg_from_hl('ModesCopy', '#f5c359'),
copy = config.colors.copy or util.get_bg_from_hl(
'ModesCopy',
'#f5c359'
),
delete = config.colors.delete or util.get_bg_from_hl(
'ModesDelete',
'#c75c6a'
Expand Down Expand Up @@ -114,6 +117,8 @@ end
---@class Config
---@field colors Colors
---@field line_opacity Opacity
---@field set_cursor boolean
---@field focus_only boolean

---@param opts Config
function modes.setup(opts)
Expand All @@ -126,6 +131,7 @@ function modes.setup(opts)
insert = 0.15,
visual = 0.15,
},
set_cursor = true,
focus_only = false,
}
opts = opts or default_config
Expand Down Expand Up @@ -156,9 +162,11 @@ function modes.setup(opts)
vim.cmd('hi Visual guibg=' .. dim_colors.visual)

-- Set guicursor modes
vim.opt.guicursor:append('v-sm:block-ModesVisual')
vim.opt.guicursor:append('i-ci-ve:ver25-ModesInsert')
vim.opt.guicursor:append('r-cr-o:hor20-ModesOperator')
if config.set_cursor then
vim.opt.guicursor:append('v-sm:block-ModesVisual')
vim.opt.guicursor:append('i-ci-ve:ver25-ModesInsert')
vim.opt.guicursor:append('r-cr-o:hor20-ModesOperator')
end

local on_key = vim.on_key or vim.register_keystroke_callback
on_key(function(key)
Expand Down
14 changes: 10 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Highlight UI elements based on current mode. Inspired by the recent addition of
```lua
use({
'mvllow/modes.nvim',
event = 'BufRead', -- optional lazy loading
config = function()
vim.opt.cursorline = true
require('modes').setup()
Expand All @@ -26,19 +25,27 @@ use({
Default colors can be overridden by passing values to the setup function or updating highlight groups.

```lua
-- Pass colors through setup
require('modes').setup({
colors = {
copy = "#f5c359",
delete = "#c75c6a",
insert = "#78ccc5",
visual = "#9745be",
},

-- Cursorline highlight opacity
line_opacity = 0.1,

-- Highlight cursor
set_cursor = true,

-- Highlight in active window only
focus_only = false
})
```

-- Or use highlight groups (useful for themes)
```lua
-- Exposed highlight groups, useful for themes
vim.cmd('hi ModesCopy guibg=#f5c359')
vim.cmd('hi ModesDelete guibg=#c75c6a')
vim.cmd('hi ModesInsert guibg=#78ccc5')
Expand All @@ -55,7 +62,6 @@ _Workaround:_
require('which-key').setup({
plugins = {
presets = {
-- Disable operators
operators = false,
},
},
Expand Down

0 comments on commit 57fb7a8

Please sign in to comment.