Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install nvim-tree.lua init.vim or init.lua?

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 ?
like image 300
Laurent Claessens Avatar asked Oct 30 '25 12:10

Laurent Claessens


2 Answers

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.

like image 119
Laurent Claessens Avatar answered Nov 03 '25 10:11

Laurent Claessens


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

like image 40
TheodorusMajorus Avatar answered Nov 03 '25 11:11

TheodorusMajorus