Theme doesn't load on startup
I'm using Lua and Packer to setup my Neovim 0.5. The theme installs and works great but when I launch nvim it gives this error
Vim(colorscheme):E185: Cannot find color scheme 'onehalfdark'
the weird thing is that the theme loads when I do :source $MYVIMRC
At first I thought it was because the scheme was being set before packer can load it (https://github.com/sonph/onehalf/issues/104) but that solution didn't work for me. Now I think it has something to do with my runtimepath.
Here's my config
init.lua
local cmd = vim.cmd
local opt = vim.opt
require('plugins')
-- set editor options
opt.termguicolors = true
-- opt.number = true
opt.smartindent = true
opt.tabstop = 4
opt.shiftwidth = 4
-- treesitter config
local ts = require('nvim-treesitter.configs')
ts.setup { ensure_installed = 'maintained', highlight = { enable = true }}
-- personalisation
cmd [[syntax on]]
cmd [[set t_Co=256]]
cmd [[set cursorline]]
cmd [[colorscheme onehalfdark]]
lua/plugins.lua
local fn = vim.fn
local cmd = vim.cmd
-- install packer if not present
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
end
cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerCompile
augroup end
]])
-- set up packer package manager
return require('packer').startup(function(use)
-- packer can manager itself
use { 'wbthomason/packer.nvim' }
-- fzf with preview window
-- use {'junegunn/fzf', dir = '~/.fzf', run = './install --all' }
--use {'junegunn/fzf.vim'}
-- treesitter
use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
-- themes
use { 'morhetz/gruvbox' }
use { 'sonph/onehalf', rtp = 'vim'}
if packer_bootstrap then
require('packer').sync()
end
end)
PS: I dont get this issue when I keep everything the same but set gruvbox as colorscheme instead of onehalfdark. which is why I think runtimepath could be an issue
@faraazahmad unfortunately this theme cannot be used in lua config, because 'rtp' option in packer will make it look for onehalf/vim/?.lua or onehalf/vim/init.lua. This is just how lua language works. I really like this theme, but without an entry point for lua interpreter it won't work. Plus, I doubt that this theme supports treesitter
@faraazahmad you can check the alternative though, please write back, if you have any success with it https://github.com/CodeGradox/onehalf-lush
@faraazahmad I tried the suggested to you theme, I can 100% say that it is robust. I compared it to a popular dracula theme, that some developers of treesitter use. Onehalf-lush gave me more clear syntax in tsx and typescript files. It was clear from far away what is html element, what is React Component, what is method call, what is constant, what is Type, what are JS keywords and operators. With the limited colorset of the onehalf theme I consider onehalf-lush theme do be a very good plugin
Treesitter config:
ensure_installed = {
"javascript",
"typescript",
"tsx",
"lua",
},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
As a workaround, you run can leverage packer's config stanza
use {
"sonph/onehalf",
rtp = "vim/",
config = function() vim.cmd("colorscheme onehalflight") end
}