ThePrimeagen / init.lua

3.34k stars 592 forks source link

Nill value when try to get vim undo directory #77

Open waleedrana777 opened 1 year ago

waleedrana777 commented 1 year ago

I try to copy Prime's config from YT tutorial, When I try to :so the set.lua file, it gives me the following error on windows:

Error detected while processing :source (no file):
E5108: Error executing lua [string ":source (no file)"]:17: attempt to concatenate a nil value
stack traceback:
        [string ":source (no file)"]:17: in main chunk

Line number 17 is: vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"

Also I have a question: why Prime doesn't have autosave enabled as some one coming from vscode, it has autosave, so I am wondering if there is some kind of advantage to that?! If so what is it?

If not, why Prime doesn't talk about autosave, what's the easiest way to enable autosave without going into plugins, I explored options like autowrite and autowritedelay but couldn't get them to work!

Will I lose all my work if I forget to save it without autosave, I understand buffers keep your text but even after machine restart?

Sorry for asking too many question! I am just a newbie!

mrs4ndman commented 1 year ago

I also followed a few weeks ago the tutorial, and the undo history has worked with this set of options (it is also on my dotfiles):

vim.o.swapfile = false
vim.o.backup = false
vim.o.undodir = os.getenv("HOME") .. "/.vim/undodir"
vim.o.undofile = true

If you are on Windows, you could try inverting the slashes on /.vim/undodir and see if It makes a difference. About the autosave, you could bind Leader + Q to write and then quit all buffers (:wqa). I have found a solution that allows me to create sessions that auto-save them when I need to, and load with a keybind. The cool thing is that, after created, they auto-save! The plugin I used: rmagatti/auto-session The code I used: here and the following keybinds (the first is from my dashboard plugin):

dashboard.button( "v", "    Source session",        ":SessionRestore<CR>"),

vim.keymap.set("n", "<leader>sd", "<cmd>SessionDelete<CR>", { desc = "Saved current session" })
vim.keymap.set("n", "<leader>sr", "<cmd>SessionRestore<CR>", { desc = "Restore session for CWD" })
vim.keymap.set("n", "<leader>ss", "<cmd>SessionSave<CR>", { desc = "Saved current session" })

Hope this helps! :)

S3cBar0n commented 11 months ago

To fix the "attempt to concatenate a nil value" on Windows, you need to create an environment variable set to your home directory; I recommend you make this under your User environment variables rather than System environment variables.

Something like "C:\Users\waleedrana777". Once you have the "HOME" environment variable set, you can restart your terminal, and it will work just fine. You don't need to create the "/.vim/undodir" folder either; once your HOME env variable is set, nvim will automatically create those folders for you.

In case you haven't worked with environment variables in Windows before, I recommend following this video to accomplish what I described above: https://www.youtube.com/watch?v=5BTnfpIq5mI