0

I'm on macOS Ventura with iTerm2.

I've made a color scheme for Vim in ~/.vim/colors/myowncolorscheme.vim.
Is it possible to use it in Neovim? If yes, how do I do that?

In my ~.vimrc I integrate it this way:

" Set the color scheme of Vim:
colorscheme myowncolorscheme
set termguicolors

In Vim, my own color scheme works properly.

Regards, Manny

3
  • This should be entirely possibly by putting the colorscheme in NeoVim's runtimepath (probably ~/.config/nvim/colors/xy.vim or something; use stdpath or similar to find the appropriate place)
    – D. Ben Knoble
    Commented Nov 17, 2022 at 22:59
  • Thanks @D.BenKnoble, but that didn’t worked for me :/
    – Manny
    Commented Nov 19, 2022 at 14:10
  • You need to call the colorscheme command correctly. Try the :help
    – D. Ben Knoble
    Commented Nov 19, 2022 at 16:47

2 Answers 2

2

Yes. simply create the this directory:

mkdir -p ~/.config/nvim/colors

Then move/copy your colorsheme file into the directory:

mv ~/.vim/colors/xy.vim ~/.config/nvim/colors/xy.vim


In case you have changed the XDG_CONFIG_HOME variable, put it in accordingly...

0
0

Solution 1 - .vimrc as source

If in Vim everything works properly and if you have Neovim already installed, create the file init.vim in Neovim directory with the command:

touch ~/.config/nvim/init.vim

Now open this file with any editor you like (I use Neovim for this example):

nvim ~/.config/nvim/init.vim

...and put following content into it:

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc

Safe and close init.vim with shift + ZZ or :wq.
If you now open a file with Neovim, the color scheme that is activated in Vim is activated in Neovim too.

Maybe this way can lead into trouble if you have already an init.lua file in ~/.config/nvim/ directory.
If so, just rename init.lua to foobarinit.lua to see if your init.vim works. Keep in mind, that everything of *.vim is more important than *.lua. So if you have, your Neovim plugins get disabled.

Solution 2 - init.lua as source

Like @Pixelbog said (tanks by the way), create a color directory in ~/.config/nvim/ directory:

mkdir -p ~/.config/nvim/colors

Copy your Vim color scheme into that directory:

cp ~/.vim/colors/myowncolorscheme.vim ~/.config/nvim/colors/myowncolorscheme.vim

Now open your init.lua in ~/config/nvim/ with any editor you like (I use Neovim for this example):

nvim ~/.config/nvim/init.lua

...and put following content into it:

vim.opt.termguicolors = true
vim.cmd("colorscheme myowncolorscheme")

Safe and close init.vim with shift + ZZ or :wq.
If you now open a file with Neovim, the color scheme is activated in Neovim.
The two vim.* lines of init.lua you can write in any *.lua file in ~/.config/nvim/lua/* directory, but then you have to require that file in init.lua:

require("settings.core.options")

For this example the absolute path is ~/.config/nvim/lua/settings/core/options.lua.

1
  • I think the vim.cmd to call :colorscheme is the most important part of this answer to the question
    – D. Ben Knoble
    Commented Nov 20, 2022 at 20:17

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.