Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme doesn't load automatically upon start up when using a lua config #36

Closed
eduardo-antunes opened this issue Apr 22, 2021 · 8 comments

Comments

@eduardo-antunes
Copy link

I'm using a lua config in the nightly build of neovim. For some reason, neovim loads the default theme instead of gruvbox8 whenever I start it up; I have to do a ":luafile ~/.config/nvim/init.lua" for it to load. I've done some testing, and this problem only happens with gruvbox8 and only when using an init.lua. Here's the line I use to set the colorscheme in my config:

vim.api.nvim_command "colors gruvbox8"

Any idea of what's going on?

(P.S.: english is not my native language, sorry if I've made some mistake)

@jojoyuji
Copy link

Hi @edu-ant-vi ,
Could you try instead:

vim.cmd([[colorscheme gruvbox8]])

And see if it works?

@eduardo-antunes
Copy link
Author

eduardo-antunes commented Apr 22, 2021

I tried it now, but the same thing happens. I believe they are actually the same function under the hood.

@jojoyuji
Copy link

how are you installing gruvbox8?
I think it is a loading order issue. I imagine you're setting the colorscheme before loading gruvbox8.

I'm using packer.nvim and this is how it is for me:

  use {
    'lifepillar/vim-gruvbox8',
    setup = function()
      vim.g.gruvbox_contrast_dark='hard'
      vim.cmd([[colorscheme gruvbox8_hard]])
    end
  }

@eduardo-antunes
Copy link
Author

I'm using packer too. I was setting the colorscheme after loading gruvbox8, but outside of packer.startup. I rearranged my config to do it the way you showed, but it didn't work, even after I tried reinstalling it.

@jojoyuji
Copy link

Can you share your init.lua and related nvim dotfiles?

@eduardo-antunes
Copy link
Author

Sure. My only dotfile at the moment is the init.lua:

-- Initial setup ---------------------------------------------------------------
-- vim.o for setting global options
-- vim.bo for setting buffer-scoped options
-- vim.wo for setting window-scoped options

local viml = vim.api.nvim_command    -- to execute vim commands 
local g    = vim.g                   -- a table of global variables

local scopes = {o = vim.o, b = vim.bo, w = vim.wo}

local function opt(scope, key, value)
  scopes[scope][key] = value
  if scope ~= "o" then scopes["o"][key] = value end
end

local function map(mode, lhs, rhs, opts)
  local options = {noremap = true}
  if opts then options = vim.tbl_extend("force", options, opts) end
  vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end

-- Plugin declarations ---------------------------------------------------------

viml "packadd packer.nvim"

require("packer").startup(function()

  use {"wbthomason/packer.nvim", opt = true} -- packer itself

  use "lifepillar/vim-gruvbox8" -- gruvbox but faster

  use "pbrisbin/vim-colors-off" -- good ol' grey scale

  use "arcticicestudio/nord-vim" -- blue-ish, icy theme

  use  "sheerun/vim-polyglot" -- extra language support

  use  "ms-jpq/chadtree" -- file manager

  -- use  "nvim-treesitter"

  -- use "neovim/nvim-lspconfig"

  use "ryanoasis/vim-devicons" -- pretty icons

end)


-- General settings ------------------------------------------------------------

viml "syntax on"
viml "colorscheme gruvbox8"
viml "filetype plugin indent on"

opt("o", "hidden", true)
opt("w", "wrap", false)
opt("o", "hlsearch", false)
opt("o", "errorbells", false)
opt("w", "number", true)
opt("w", "relativenumber", true)
opt("o", "incsearch", true)
opt("o", "scrolloff", 8)
opt("o", "sidescrolloff", 8 )
opt("o", "lazyredraw", true)
opt("o", "mouse", "a")
opt("o", "termguicolors", true)

local indent = 4
opt("b", "tabstop", indent)
opt("b", "softtabstop", indent)
opt("b", "expandtab", true)
opt("b", "shiftwidth", indent)
opt("b", "smartindent", true)

opt("o", "ignorecase", true)
opt("o", "joinspaces", false)
opt("o", "shiftround", true)
opt("o", "smartcase", true)
opt("o", "splitbelow", true)
opt("o", "splitright", true)
opt("o", "wildmode", "list:longest")
opt("w", "list", true)

-- General key bindings --------------------------------------------------------

g.mapleader      = " "
g.maplocalleader = " m"

map("n", "<leader>w",        "<C-w>")
map("n", "<leader><leader>", "<cmd>bnext<cr>")
map("n", "<leader>ec",       "<cmd>edit $MYVIMRC<cr>")
map("n", "<leader>lc",       "<cmd>luafile $MYVIMRC<cr>")

-- çç to switch to normal mode
map("i", "çç", "<esc>")
map("v", "çç", "<esc>")
map("t", "çç", "<C-\\><C-n>")

-- Paste to and from the system"s clipboard
map("", "<C-y>", "\"+y")
map("", "<C-p>", "\"+p")

-- Plugin configuration ----------------------------------------------------------

-- Plugin-specific maps ----------------------------------------------------------

map("n", "<leader>.", "<cmd>CHADopen<cr>")

@jojoyuji
Copy link

I think I got the problem, somehow setting termguicolors after colorscheme gruvbox messed up the colorscheme,
try setting the colorscheme after termguicolors:

...
opt("o", "termguicolors", true)
viml "colorscheme gruvbox8"

@eduardo-antunes
Copy link
Author

It worked, thank you very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants