6

so i decided to use neovim instead of vscode, im a beginner to that, i created the init.lua file on ~/.config/nvim/, with simple script :

print("hello world")

the script never executed, i also tried this way on this video https://youtu.be/w7i4amO_zaE and nothing works for me

i want the file init.lua to be executed, i need your help

romainl
  • 186,200
  • 21
  • 280
  • 313
kxown
  • 95
  • 1
  • 6

6 Answers6

6

TLDR:

Install version 0.5 or greater, debian as of right now installs v0.4.4

Hey, I experienced this same thing just now and looked here for answers (they were not helpful).

Neovim v0.5.0+ has added supporting ~/.config/nvim/init.lua directly. I think there are some workarounds for v0.4 and below, but I don't know since today is the beginning of my neovim journey. Anyways do the following:

make sure that you are at least v0.5 by running:

nvim --version | head -n 1

if you are not v0.5+ then do the following:

** NOTE: as of writing this v0.9.1 is the latest, check the github for the latest and change where it says v0.9.1: https://github.com/neovim/neovim/releases

Download the appimage

wget https://github.com/neovim/neovim/releases/download/v0.9.1/nvim.appimage

Extract the appimage

chmod u+x nvim.appimage && ./nvim.appimage

** If this fails because of FUSE then do the following (mine failed)

./nvim.appimage --appimage-extract
./squashfs-root/usr/bin/nvim

Copy the binary

cp ./squashfs-root/usr/bin/nvim usr/bin/nvim

Set an alias if needed or use a symlink

Alias

# in your bashrc
alias vim='nvim'

symlink (it will fail if vim is already installed, I suggest an alias)

ln -s /usr/bin/nvim /usr/bin/vim
4

Neovim will load $XDG_CONFIG_HOME/nvim/ as a lua module, thus loading init.lua in that folder for you.

print statements inside Neovim lua modules are placed into the Neovim message area (accessible with :messages), so you should check there to see your output. Additionally, if there are any errors with the lua code, they are displayed there.

As a debugging step, you should go to the config directory and ensure the init.lua file exists and actually has content (did you save?).

amycodes
  • 902
  • 14
2

init.vim will be automatically executed in

~/.config/nvim/

init.lua (all Lua Files) will be found (for require()) in

~/.config/nvim/lua/

So do in init.vim

" Load some Lua specific custom stuff
lua require("init")

Also type in nvim command mode: :h init and :h lua for first level support ;-)
(If that was not on your 'nothing works' list)

koyaanisqatsi
  • 2,585
  • 2
  • 8
  • 15
2

Check your nvim version. I had the same problem, then I upgraded from v0.3.4 to v.0.9 and it worked.

vim -v
Veglos
  • 458
  • 4
  • 8
1

Here is how to solve this if you are using Windows and trying to make your innit.lua work.

The reason why you are not able to make innit.lua work might be because you tried to create it somewhere else. For default installations, you need to create a file called nvim inside the AppData/Local folder and then create your innit.lua file inside of the freshly created folder nvim.

0

The Re-Install Strategy

I had this exact problem. I forgot that months or years ago I installed Neovim maybe in a different way and added a different configuration. I probably uninstalled it as well, so go uninstall Neovim and then make sure to go to $env:LOCALAPPDATA (powershell) delete nvim and nvim-data. Then install again. ...Then smack your palm to your forehead, like I did.

Gabriel Kunkel
  • 2,643
  • 5
  • 25
  • 47