init.lua icon indicating copy to clipboard operation
init.lua copied to clipboard

Undo doesn't work in Windows

Open jon49 opened this issue 2 years ago • 2 comments

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"

jon49 avatar Jan 02 '23 21:01 jon49

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.

simsrw73 avatar Jan 02 '23 22:01 simsrw73

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

jon49 avatar Jan 03 '23 17:01 jon49