mvllow / modes.nvim

Prismatic line decorations for the adventurous vim user

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cursor not resetting to normal color

franroa opened this issue · comments

Hi there! Nice plugin!

I like the plugin, and It works pretty well, except for the fact that the cursor color is not resetting to the default when I come from another mode (visual or yank)

Any clues why this might be happening?

THanks!

Can you provide your configuration along with the reproduction steps?

Hi, this is my config for this plugin:

return {
  "mvllow/modes.nvim",
  config = function()
    require("which-key").setup({
      plugins = {
        presets = {
          operators = false,
        },
      },
    })
    require("modes").setup({
      colors = {
        copy = "#f5c359",
        delete = "#c75c6a",
        insert = "#78ccc5",
        visual = "#9745be",
      },

      -- Set opacity for cursorline and number background
      line_opacity = 0.15,

      -- Enable cursor highlights
      set_cursor = true,

      -- Enable cursorline initially, and disable cursorline for inactive windows
      -- or ignored filetypes
      set_cursorline = false,

      -- Enable line number highlights to match cursorline
      set_number = false,

      -- Disable modes highlights in specified filetypes
      -- Please PR commonly ignored filetypes
      ignore_filetypes = { "NvimTree", "TelescopePrompt" },
    })
  end,
}

This is the only plugin I have installed with a fresh lazyvim installation. I am not able to figure out which causes the problem. I will dig deeper when I get time

Does your issue persist after removing which-key?

Hi, I just tried out. The issue is still there

im having the same issue. installed this along with a fresh lazyvim installation

I just tried lazyvim and still cannot reproduce the issue, what terminal emulator are you using?

im using wezterm on windows

the wezterm cursor colors are set like this:

[colors]
background = '#363646'
foreground = '#dcd7ba'
cursor_bg = '#c8c093'
cursor_fg = '#1f1f28'
cursor_border = '#c8c093'

plugin settings are pretty standard:

function M.config()
  require("modes").setup({
    colors = {
      copy = "red",
      delete = "yellow",
      insert = "green",
      visual = "blue",
    },
    -- Set opacity for cursorline and number background
    line_opacity = 0.20,

    -- Enable cursor highlights
    set_cursor = true,

    -- Enable cursorline initially, and disable cursorline for inactive windows
    -- or ignored filetypes
    set_cursorline = true,

    -- Enable line number highlights to match cursorline
    set_number = true,

    -- Disable modes highlights in specified filetypes
    ignore_filetypes = { "neo-tree", "NvimTree", "aerial", "OverseerList", "TelescopePrompt" },
  })
end

and for lazyvim, its a fresh install and the only files in lua/plugins is the settings for this plugin and a theme

Recording.2024-03-02.131147.mp4

I just tried wezterm + lazyvim on linux and macOS, and still cannot reproduce the issue, unfortunately I don't have a windows machine at the moment to test it, maybe this is windows related issue

@franroa are you also using windows? What terminal emulator are you using?

just tested this in neovide and it works ok. not sure what that might suggest...

@franroa are you also using windows? What terminal emulator are you using?
Also windows, with wsl

The problem appears on Powershell, Weztern and kitty (all that I use)

Having the same issue.

Env: Window terminal, and even exit neovim the color keeps. I am guessing the neovim cursor color is somehow bind with windows terminal cursor color.

GIF 3-7-2024 10-58-24 PM

I cannot reproduce the issue on the following platforms

  • Linux: alacritty, st, kitty, foot
  • macOS: alacritty, wezterm

I was able to reproduce the issue with macOS + iTerm, but this is a known limitation of iTerm regarding cursor shape manipulation

Can you guys reproduce the issue with the followning config @franroa @sho-87 @RayGuo-ergou

-- save as: guicursor.lua
local api = vim.api
local hi = api.nvim_set_hl

hi(0, "CursorRed", { bg = "Red" })

local i_cur = "i:ver20-CursorRed"

api.nvim_create_autocmd("InsertEnter", {
  callback = function()
    vim.opt.guicursor:append(i_cur)
  end,
})

api.nvim_create_autocmd("InsertLeave", {
  callback = function()
    vim.opt.guicursor:remove(i_cur)
  end,
})

Then open nvim with

nvim --clean -S guicursor.lua -- guicursor.lua

The expected behavior would be to set the cursor to red vertical line in insert mode and reset to default after leaving insert mode

macOS, wezterm

Screen.Recording.2024-03-08.at.21.11.53.mov

If you can reproduce the issue with the steps above, I would assume it is an upstream (OS and/or terminal emulator) limitation/issue

Also let me know if you are able to reproduce the issue on windows with alacritty, I don't have a windows machine at the moment to test it

hmm when I try that my cursor doesnt change colour to red at all. Ive tried this in wezterm, powershell and cmd

wsl (ubuntu) + windows terminal cannot see red cursor.

GIF 3-8-2024 7-20-27 PM

neovim version:

nvim -V1 -v
NVIM v0.10.0-dev-2508+ga8131aee9
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634
Compilation: /usr/bin/cc -O2 -g -Og -g -flto -fno-fat-lto-objects -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fsigned-char -fstack-protector-strong -Wno-conversion -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=auto  -DUNIT_TESTING -DHAVE_UNIBILIUM -D_GNU_SOURCE -DINCLUDE_GENERATED_DECLARATIONS -I/home/raydev/git/neovim/.deps/usr/include/luajit-2.1 -I/home/raydev/git/neovim/.deps/usr/include -I/home/raydev/git/neovim/build/src/nvim/auto -I/home/raydev/git/neovim/build/include -I/home/raydev/git/neovim/build/cmake.config -I/home/raydev/git/neovim/src -I/usr/include

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

Run :checkhealth for more info

Found two relative issues in neovim:
neovim/neovim#18053 (comment)
neovim/neovim#23094

Thinking this is an upstream issue.

For me I can live without cursor color change.

And I have to say this is a very amazing plugin and thank you so much for your work and help @fitrh

Found two relative issues in neovim: neovim/neovim#18053 (comment) neovim/neovim#23094

Thinking this is an upstream issue.

For me I can live without cursor color change.

And I have to say this is a very amazing plugin and thank you so much for your work and help @fitrh

Same here

I have this Problem too.
I could replicate it with guicursor.lua
Howether i found a workaround if i know what color i want the cursor to be, then i can always set it.

-- save as: guicursor.lua
local api = vim.api
local hi = api.nvim_set_hl

hi(0, "CursorRed", { bg = "Red" })
hi(0, "CursorWhite", {bg= "White"})

 
local i_cur = "i:ver20-CursorRed"
local n_cur = "i:ver20-CursorWhite"

api.nvim_create_autocmd("InsertEnter", {
	callback = function()
		vim.opt.guicursor:remove(n_cur)
		vim.opt.guicursor:append(i_cur)
	end,
})

api.nvim_create_autocmd("InsertLeave", {
	callback = function()
		vim.opt.guicursor:remove(i_cur)
		vim.opt.guicursor:append(n_cur)
	end,
})
commented

simple little workaround

require("modes").setup()
vim.opt.guicursor:append("n-c:Cursor") -- you can have it before or after setup, doesn't matter

the reason this solution works is because modes.nvim does not handle n-c in guicursor

the only issue (i can find) with this solution is that if you leave the window without being in normal mode, the cursor will remain the same. for example, you are in insert mode, but you switch to a different tmux panel.

using Windows Terminal WSL2

After looking deeper, i found that the fix from @zahimeen works on tokyo-night theme, but not on gruvbox.

commented

After looking deeper, i found that the fix from @zahimeen works on tokyo-night theme, but not on gruvbox.

For my solution, the Cursor highlight bg must be defined.
The reason it works in the tokyonight.nvim theme is because of this line.

https://github.com/folke/tokyonight.nvim/blob/b9b494fa7f7bbf2fe0747b47fa290fb7a4eddcc7/lua/tokyonight/theme.lua#L34

There are many gruvbox ports so I don't know which one you are talking about, but as far as I am concerned, I bet they do not explicitly overwrite the Cursor highlight, instead just inheriting from the terminal.

require("modes").setup()
vim.opt.guicursor:append("n-c:Cursor") -- you can have it before or after setup, doesn't matter

the highlight group for this can be anything you want. you could replace Cursor with SignColumn or something if you want to. do as you please.

commented

Happy to accept a PR for a note under our known issues section :)