0

I'm trying to use nvim on Ubuntu WSL. I installed it with AppImage because with apt it seems to be quite old version.

curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
chmod u+x nvim.appimage
./nvim.appimage

Then I'm trying to install packer etc to customize it following this blogpost: Turning Neovim into a Full-Fledged Code Editor with Lua

Every time I open nvim ./nvim.appimage I get this:

Error detected while processing /home/rr/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/rr/.config/nvim/lua/vars.lua:4: attempt to index local 'g' (a function value)
stack traceback:
        /home/rr/.config/nvim/lua/vars.lua:4: in main chunk
        [C]: in function 'require'
        /home/rr/.config/nvim/init.lua:10: in main chunk
Error detected while processing /tmp/.mount_nvim.aiftKrm/usr/share/nvim/runtime/filetype.lua:
E5113: Error while calling lua chunk: .../.mount_nvim.aiftKrm/usr/share/nvim/runtime/filetype.lua:1: attempt to index field 'g' (a function value)
stack traceback:
        .../.mount_nvim.aiftKrm/usr/share/nvim/runtime/filetype.lua:1: in main chunk
E5113: Error while calling lua chunk: .../.mount_nvim.aiftKrm/usr/share/nvim/runtime/filetype.lua:1: attempt to index field 'g' (a function value)
stack traceback:
        .../.mount_nvim.aiftKrm/usr/share/nvim/runtime/filetype.lua:1: in main chunk
Error detected while processing /tmp/.mount_nvim.aiftKrm/usr/share/nvim/runtime/syntax/syntax.vim:
line   42:
E121: Undefined variable: s:did_ft
Error detected while processing /tmp/.mount_nvim.aiftKrm/usr/share/nvim/runtime/plugin/man.lua:
E5113: Error while calling lua chunk: ...mount_nvim.aiftKrm/usr/share/nvim/runtime/plugin/man.lua:1: attempt to index field 'g' (a function value)
stack traceback:
        ...mount_nvim.aiftKrm/usr/share/nvim/runtime/plugin/man.lua:1: in main chunk
Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: ...m.aiftKrm/usr/share/nvim/runtime/plugin/editorconfig.lua:6: attempt to index field 'g' (a function value)
stack traceback:
        ...m.aiftKrm/usr/share/nvim/runtime/plugin/editorconfig.lua:6: in function <...m.aiftKrm/usr/share/nvim/runtime/plugin/editorconfig.lua:4>
Press ENTER or type command to continue

My current set up is:

.config/nvim/
├── init.lua
├── lua
│   ├── keys.lua
│   ├── opts.lua
│   ├── plug.lua
│   └── vars.lua
└── site
    └── pack
        └── packer

init.lua

cat .config/nvim/init.lua
--[[ init.lua ]]

-- LEADER
-- These keybindings need to be defined before the first
-- is called; otherwise, it will default to "\"
vim.g.mapleader = ","
vim.g.localleader = "\\"

-- IMPORTS
require("vars")      -- Variables
require('opts')      -- Options
require('keys')      -- Keymaps
require('plug')      -- Plugins

plug.lua

cat .config/nvim/lua/plug.lua
-- [[ plug.lua ]]

return require("packer").startup(function(use)
    use "wbthomason/packer.nvim"
    use "nvim-tree/nvim-tree.lua"
end
)

vars.lua

 cat .config/nvim/lua/vars.lua
--[[ vars.lua ]]
vim.g = vim.api.nvim_set_var
local g = vim.g
g.t_co = 256
g.background = "dark"

-- Update the packpath
local packer_path = vim.fn.stdpath("config") .. "/site"
vim.o.packpath = vim.o.packpath .. "," .. packer_path

I am new in using vim/nvim and lua, what am I doing wrong?

1 Answer 1

2

There are couple of things I want to point out.

  • Don't use appimage of neovim because sometimes it does not work very well the plugin managers and also with some plugins, instead build it from source.
  • For building from source and modern configuration of neovim (with lazy.nvim, lsp, linting) you can checkout my github repo for that.
  • Third thing is that you don't have to set variables like this instead
-- Don't do like this(it's a mess).
vim.g = vim.api.nvim_set_var
local g = vim.g
g.t_co = 256
g.background = "dark"
-- You can easily set variables using nvim api like this
vim.opt.background = "dark"
  • Let me know if you encounter any issue.
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer, in the end I deleted nvim and vim and reinstalled nvim from source. I would like to why you think it is a mess to add these local g variables. Many guides use them. It helps to type less.
No no I was not talking about setting a variable local g = , I was talking about using vim.g instead of vim.opt.

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.