file init.lua script in neovim not working
Asked Answered
C

8

14

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

Cutlery answered 1/4, 2023 at 14:38 Comment(0)
S
13

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
Subsume answered 1/6, 2023 at 5:41 Comment(1)
In addition to copying the binary, I also needed to copy the runtime files too. sudo cp squashfs-root/usr/* /usr/ -r, as I was having error caused by those files missing.Overwork
D
5

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?).

Dhumma answered 1/4, 2023 at 21:3 Comment(1)
I have the same problem as the question have. the init.lua does not execute when opening nvim.Oriya
H
3

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)

Howlyn answered 1/4, 2023 at 19:38 Comment(0)
T
1

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
Town answered 16/4, 2023 at 18:36 Comment(1)
I have 0.9 and it still does not work, is this a ubuntu only thing? does it not work properly on windows?Oriya
P
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.

Proofread answered 15/6, 2023 at 2:3 Comment(0)
K
1

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.

Kaolin answered 15/8, 2023 at 19:50 Comment(0)
F
1

I had this exact same problem on Ubuntu, WSL2. I don't know why this works, but the fix was:

  1. Reinstall neovim (for me appimage didn't work, but building from source did)
  2. Next, create your nvim folder not in $XDG_CONFIG_HOME which was ~, but in ~/.config.
Fatima answered 14/10, 2023 at 18:16 Comment(0)
I
0

Had the same issue on WSL (Ubuntu)

Install a more recent version of neovim from neovim-ppa/unstable according to the instructions in the repo https://github.com/neovim/neovim/wiki/Installing-Neovim

Idell answered 4/12, 2023 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.