4

I'm totally new to neovim. I already snap-installed neovim (Ubuntu) and I want now to install nvim-tree.

The documentation confuses me.

Here is my file .config/nvim/init.vim

call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
Plug 'nvim-tree/nvim-tree.lua'
call plug#end()

Now calling :PlugInstall in neovim seems to install something.

But in the "Setup" part of the doc, it is said to add this in init.lua:

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.opt.termguicolors = true
require("nvim-tree").setup()

Since init.vim and init.lua are exclusive, I do not know what to do.

If I remove init.vim and create the file init.lua, I get this error:

E5113: Error while calling lua chunk: /home/laurent/.config/nvim/init.lua:4: module 'nvim-tree' not foun
d:
        no field package.preload['nvim-tree']
        no file './nvim-tree.lua'
        no file '/build/nvim/parts/nvim/build/.deps/usr/share/luajit-2.1.0-beta3/nvim-tree.lua'
        no file '/usr/local/share/lua/5.1/nvim-tree.lua'
        no file '/usr/local/share/lua/5.1/nvim-tree/init.lua'
        no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/nvim-tree.lua'
        no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/nvim-tree/init.lua'
        no file './nvim-tree.so'
        no file '/usr/local/lib/lua/5.1/nvim-tree.so'
        no file '/build/nvim/parts/nvim/build/.deps/usr/lib/lua/5.1/nvim-tree.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        /home/laurent/.config/nvim/init.lua:4: in main chunk

QUESTIONS:

  • Do I have to stick with init.vim or init.lua (or is it a choice with no consequences ?)
  • How do I install/use the plugin nvim-tree ?

2 Answers 2

5

Answer to myself. It turns out that this works:

In ~/.config/nvim/init.vim:

call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
Plug 'nvim-tree/nvim-tree.lua'
call plug#end()

lua << EOF
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.opt.termguicolors = true
require("nvim-tree").setup()
EOF

Then in neovim: :PlugInstall.

But I'm far from being sure that this is a good solution.

Sign up to request clarification or add additional context in comments.

4 Comments

as in the doc, it can also be installed with packer. then you only need init.lua.
I have similar problem. My question is: did you give up init.vim? Because I have more configurations there and if possible, I would prefer to not move to Lua yet.
@VictorHMartin I continued like that with init.vim. When I need to add lua code, I put it in lua << EOF ... EOF and it works. As an example, I recently added ~30 lines of lua to configure indent-blankline and it works perfectly well.
@LaurentClaessens I've faced the same issue on my machine ubuntu 22.04, when I had my file named init.lua, but when I changed to init.vim it worked fine. I completely gave up on nvim-tree cuz it requires .lua, and switched to preservim/nerdtree.
2

I ran into this same issue and found the following to be a cleaner solution:

  • rename my init.lua file to something else (I used myinit.lua)
  • add source ~/.config/nvim/myinit.lua to the end of my init.vim file (alternatively you can use luafile instead of source)

This way I can keep all the lua code contained to it's own file and don't have to use that ugly lua << EOF ... EOF syntax, but it's functionally equivalent anyway

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.