0

My init.vim is placed in ~/.config/nvim/ and has the following in it:

call plug#begin()

Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
Plug 'nvim-tree/nvim-tree.lua'
Plug 'nvim-tree/nvim-web-devicons'

call plug#end()

" plugin configs
lua require('nerd-tree')
lua require('tokyonight')

I also have the directory ~/.config/nvim/lua/ and in there I have the files nerd-tree.lua and tokyonight.lua. Inside tokyonight.lua I have the line vim.cmd[[colorscheme tokyonight]]. The plugin is successfully installed and also nerd-tree is working fine, it is just the color scheme. When I open nvim I get the error message

Error detected while processing /Users/nickeisenberg/.config/nvim/init.vim:
line   12:
E5108: Error executing lua /Users/nickeisenberg/.config/nvim/lua/tokyonight.lua:1: Vim(colorscheme):E5113: Error while calling lua chunk: ...share/nvim/plugged/tokyonight.nvim/colors/t
okyonight.lua:1: loop or previous error loading module 'tokyonight'
stack traceback:
        [C]: in function 'require'
        ...share/nvim/plugged/tokyonight.nvim/colors/tokyonight.lua:1: in main chunk
        [C]: in function 'cmd'
        /Users/nickeisenberg/.config/nvim/lua/tokyonight.lua:1: in main chunk
        [C]: in function 'require'
        [string ":lua"]:1: in main chunk
stack traceback:
        [C]: in function 'cmd'
        /Users/nickeisenberg/.config/nvim/lua/tokyonight.lua:1: in main chunk
        [C]: in function 'require'
        [string ":lua"]:1: in main chunk
Press ENTER or type command to continue

I also tried the gruvbox color scheme and I got the same error message. How can I fix this?

1 Answer 1

0

From the Usage, you need only :colorscheme tokyonight or vim.cmd[[colorscheme tokyonight]] directly. It's probably not worth putting in a separate special file (and if it is, I recommend plugin/ directories on 'runtimepath', since they are executed automatically).

The error looks like require('tokyonight') triggered loading colors/tokyonight.lua via the colorscheme command, which contains the same require, thereby introducing a cycle. The latter require is intended to load the plugin code, but instead finds your code because they have the same filename.

In short, don't name your custom files after plugins.

4
  • I ended up realizing that after I posted. However I tried both things that you suggested, either just putting colorscheme tokyonight inside my init.vim and also creating a plugin directory within the lua directory and doing both ways lead to the same result where the color scheme does not seem to be loading correctly. It just gives a dark background and dark blue text. See both of these for what I mean imgur.com/a/EbMLhzq, imgur.com/a/GCdjZ7S. Do you know what is causing this?
    – alpastor
    Commented Dec 23, 2022 at 20:31
  • @alpastor that I don't have an answer for.
    – D. Ben Knoble
    Commented Dec 24, 2022 at 1:03
  • If you are curious, it was because the stock mac terminal does not support the colors needed for, what I'm guessing is, most neovim color schemes. I downloaded iTerm2 and everything worked perfectly with what you said above.
    – alpastor
    Commented Dec 28, 2022 at 1:20
  • That's because Terminal.app does not support truecolor (aka 24-bit color). iTerm2, Alacritty, etc., all do.
    – D. Ben Knoble
    Commented Dec 28, 2022 at 15:26

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.