Since Neovim is rapidly moving in a direction of lua instead of vimscript, is there a need for all lua files to be in .config/nvim/lua
directory?
If it is already possible to require files just from .config/nvim
directory, please guide me how.
If it’s not - than why not? This lua
directory seems really excessive.
clason
January 6, 2022, 10:13pm
2
It is indeed possible to put Lua files (almost) anywhere in your config directory where you can put vimscript files: plugin
, after
, ftplugin
, even colors
– no require
required (ha!)
The only thing you might want to be aware of that in each directory, Lua files are sourced after all vimscript files (so it’s a.vim
→ b.vim
→ a.lua
→ b.lua
).
But I want to use require
, just from other folders. E,g, .config/nvim/lsp/tsserver.lua
clason
January 7, 2022, 9:20am
5
Then you have to manually add these folders to the Lua package.path
; by default, only the lua/
folder is in that list.
I am trying to do the following, but unsuccessful. The file is in ~/.config/nvim/visual-multi.lua
package.path = "~/.config/nvim/;" .. package.path
require("visual-multi")
module 'visual-multi' not found:
no field package.preload['visual-multi']
no file '~/.config/nvim/'
no file './visual-multi.lua'
I don’t think lua interprets the ~
the way you want. Usually, that’s your shell’s doing, and it’s not involved here. Try the full path.
Unfortunately, it didn’t help
E5113: Error while calling lua chunk: error loading module 'visual-multi' from file '/home/user/.config/nvim/':
cannot read /home/user/.config/nvim/: Is a directory
Ha, progress At Programming in Lua : 8.1 one can see that you probably want to use
package.path = "/home/user/.config/nvim/?.lua;" .. package.path
1 Like
sarmong
January 7, 2022, 11:41am
10
That worked, thanks!
Do you have any idea how to make it work with relative to home directory path? I want to make it reusable across other devices.
sarmong
January 7, 2022, 11:44am
11
Found. Shell variables can be used
local home_dir = os.getenv("HOME")
If you’re interested in making this portable you might want to look at Nvim documentation: eval (I’m sure there’s a lua variant somewhere)
1 Like