modes.nvim icon indicating copy to clipboard operation
modes.nvim copied to clipboard

Cursor not resetting to normal color

Open franroa opened this issue 1 year ago • 19 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!

franroa avatar Oct 29 '23 07:10 franroa

Can you provide your configuration along with the reproduction steps?

fitrh avatar Oct 29 '23 13:10 fitrh

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

franroa avatar Oct 30 '23 09:10 franroa

Does your issue persist after removing which-key?

fitrh avatar Oct 30 '23 09:10 fitrh

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

franroa avatar Oct 30 '23 10:10 franroa

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

sho-87 avatar Mar 02 '24 10:03 sho-87

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

fitrh avatar Mar 02 '24 14:03 fitrh

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

https://github.com/mvllow/modes.nvim/assets/5199715/4e8d20d2-d5ca-4168-a234-1f386e5cfdb9

sho-87 avatar Mar 02 '24 21:03 sho-87

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

fitrh avatar Mar 03 '24 08:03 fitrh

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

fitrh avatar Mar 03 '24 08:03 fitrh

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

sho-87 avatar Mar 03 '24 10:03 sho-87

@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)

franroa avatar Mar 03 '24 15:03 franroa

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

RayGuo-ergou avatar Mar 07 '24 12:03 RayGuo-ergou

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

https://github.com/mvllow/modes.nvim/assets/55179750/1a020b4b-eaca-4e82-9946-0d3cf59f126d

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

fitrh avatar Mar 08 '24 07:03 fitrh

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

sho-87 avatar Mar 08 '24 07:03 sho-87

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

RayGuo-ergou avatar Mar 08 '24 08:03 RayGuo-ergou

Found two relative issues in neovim: https://github.com/neovim/neovim/issues/18053#issuecomment-1094302350 https://github.com/neovim/neovim/issues/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

RayGuo-ergou avatar Mar 08 '24 08:03 RayGuo-ergou

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

franroa avatar Mar 08 '24 13:03 franroa

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,
})

OdysseusOperator avatar May 10 '24 22:05 OdysseusOperator

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

zahimeen avatar May 11 '24 03:05 zahimeen

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

OdysseusOperator avatar May 25 '24 05:05 OdysseusOperator

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.

zahimeen avatar May 25 '24 06:05 zahimeen

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

mvllow avatar Jun 09 '24 17:06 mvllow