ThePrimeagen/init.lua

Undo doesn't work in Windows

jon49 opened this issue · 2 comments

jon49 commented

There is no environment variable HOME in windows. So, this fails vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir".

This is the solution:

local home = os.getenv("HOME")
if (home == nil) then
    home = os.getenv("UserProfile")
end
opt.undodir = home .. "/.vim/undodir"

Or vim.fn.expand('~/.vim/undodir')

Better: use vim.fn.stdpath('config') or vim.fn.stdpath('state'). These will also seem to respect $XDG paths, which I define on my Windows as well as Linux machines to keep them similarly organized.

jon49 commented

vim.fn.expand('~/.vim/undodir') works well. A much better solution!