0

Nvim breaks the color of white space.

I did it with vim.opt.termguicolors = true in nvim init.lua. But the colors don't look right in my old oh-my-zsh.

The weird thing is that if I run nvim in a shell with tmux, it works fine. I don't know why. Is there a solution?

Below is my lua file. After that is an example of what happens when I try to use my old zsh shell. Last is the result of running the shell through tmux and then running nvim.

Here is my setting lua file:

local o = vim.o
vim.opt.cursorline = true      --show current cursor line
if vim.opt.termguicolors then
  vim.opt.termguicolors = true --use true color -> true color is wide color of standard 257 color in vim
else
  vim.opt.termguicolors = false
end

vim.opt.winblend    = 0 -- option controls the transparency of floating windows.(like lsp command gp window)
-- when you're typing file names or directory paths in Vim's command-line.
-- p - Show the preview window when multiple matches are found
-- u - Auto-insert characters that can complete the match
-- m - Show matches in a pop-up menu
vim.opt.wildoptions = 'pum'
-- set transparency popup
vim.opt.pumblend    = 5
vim.opt.background  = 'dark'

-- blew is base.lua
vim.cmd('autocmd!')        -- remove auto cmd (after clear and start setting)
vim.scriptencoding = 'utf-8'
vim.opt.encoding = 'utf-8' -- user interface encoding
vim.opt.fileencoding = 'utf-8'

vim.wo.number = true                             -- display line num
vim.opt.title = true                             -- set title of ternimal window to file name
vim.opt.autoindent = true                        -- if you enter newline cursor automatically move indent level
vim.opt.hlsearch = true                          --  search highlighting
vim.opt.backup = false                           -- not use backup
vim.opt.showcmd = true                           -- display last cmd after exit command mode
vim.opt.cmdheight = 1                            -- display cmd line height
vim.opt.laststatus = 2                           -- 2 is alway show bottom status
vim.opt.expandtab = true                         -- change tab to sevral space
vim.opt.scrolloff = 10                           -- keep screen number below and above

vim.opt.backupskip = '/tmp/*,/private/tmp/*'     -- skip backup when file locate "/tmp/*" and "/private/tmp/*"
vim.opt.icm = 'split'                            -- method to enter Non ASCII character
vim.opt.ignorecase = true                        -- when search for text
vim.opt.smarttab = true                          -- when press tab-key , based on the existing indentation of the current line.
vim.opt.breakindent = true                       -- whether vim adds extra indentation to wrapped lines of text.
vim.opt.shiftwidth = 2                           -- '>>' '<<' press set line
vim.opt.tabstop = 2                              -- control tab the number of space
vim.opt.ai = true                                -- Auto indent when press 'enter'
vim.opt.si = true                                -- Smart indent based space lever like '{}'
vim.opt.wrap = true                              -- if text line is very long to fit within current monitor width, fit or not
vim.opt.mouse = ''                               -- set no use mouse in vim
vim.opt.backspace =
'start,eol,indent'                               --if press 'backspace' when position beginning-line, move to end of previous line ,cuntinue delete
vim.opt.path:append { '**' }                     -- Finding files - Search down into subfolders
vim.opt.wildignore:append { '*/node_modules/*' } -- ignore subfolders 'node_modules'

-- Turn off paste mode when leaving insert
-- nopaste is set pastemode off -> This will disable certain features like autoindenting and mappings, which can prevent unintended side effects while pasting.
vim.cmd([[let &t_Cs = "\e[4:3m" ]])
vim.cmd([[let &t_Ce = "\e[4:0m"]])

vim.api.nvim_create_autocmd("InsertLeave", {
  pattern = '*',
  command = "set nopaste"
})

-- Add asterisks in block comments
-- create insert a closing bracket or quote
vim.opt.formatoptions:append { 'r' }

without tmux

with tmux

5
  • if vim.opt.termguicolors then vim.opt.termguicolors = true else vim.opt.termguicolors = false end This looks wrong: it says if the variable is true, make it true. That's a no-op, and might be what's causing the problem. You need to set termguicolors if-and-only-if the underlying terminal emulator supports truecolor
    – D. Ben Knoble
    Commented Apr 14, 2023 at 13:09
  • I would "Debug" this by commenting out vim.opt.background & then commenting out the paste-mode stuff. BTW , it is not white-space here. It is just the Part outside the "Editable Area" , you should Insert new-lines , spaces & tabs in the "Editable Area" to check what you get.
    – Prem
    Commented Apr 15, 2023 at 9:05
  • D.Ben Knoble => I corrected the code, but it still indicates the problem. What does it mean if the underlying terminal emulator supports truecolor? I'm using the default terminal app on a mac. But in that terminal app, inside a shell with tmux, nvim's theme works fine. It doesn't work in oh-my-zsh, which is not tmux. Prem => When I insert enter, space inside the editable area, the black background comes out fine. In the non-editable area, it appears red. It also appears with background=dark.
    – 주경진
    Commented Apr 15, 2023 at 22:53
  • I ran it with the same terminal emulator and was wondering why it works fine with tmux but not with the default shell (oh-my-zsh). Isn't the shell that tmux runs the same oh-my-zsh? I don't know why the two modern ones would make a difference.
    – 주경진
    Commented Apr 15, 2023 at 23:00
  • Looks like you've found the trouble spot. curl -s https://raw.githubusercontent.com/JohnMorales/dotfiles/master/colors/24-bit-color.sh | bash When I run the above syntax in TMUX, the colors come out fine. However, when I run it in the default terminal (not tmux), the colors don't come out well. What should I check?
    – 주경진
    Commented Apr 15, 2023 at 23:15

1 Answer 1

0

I can't be sure because I can't reproduce your problem but I would pay particular attention to the following:

  • The wincolor color that contains an alternative highlight group to color Normal
  • The Terminal highlighting groups

A test worth doing is probably:

set wincolor=
highlight! link Terminal Normal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.