From f7041625f1abe4e9bfd2461fef23d1d74dc75c29 Mon Sep 17 00:00:00 2001 From: Yochem van Rosmalen Date: Thu, 22 Jan 2026 13:22:35 +0100 Subject: refactor(lua): use vim.fs instead of fnamemodify Although powerful -- especially with chained modifiers --, the readability (and therefore maintainability) of `fnamemodify()` and its modifiers is often worse than a function name, giving less context and having to rely on `:h filename-modifiers`. However, it is used plenty in the Lua stdlib: - 16x for the basename: `fnamemodify(path, ':t')` - 7x for the parents: `fnamemodify(path, ':h')` - 7x for the stem (filename w/o extension): `fnamemodify(path, ':r')` - 6x for the absolute path: `fnamemodify(path, ':p')` - 2x for the suffix: `fnamemodify(path, ':e')` - 2x relative to the home directory: `fnamemodify(path, ':~')` - 1x relative to the cwd: `fnamemodify(path, ':.')` The `fs` module in the stdlib provides a cleaner interface for most of these path operations: `vim.fs.basename` instead of `':t'`, `vim.fs.dirname` instead of `':h'`, `vim.fs.abspath` instead of `':p'`. This commit refactors the runtime to use these instead of fnamemodify. Not all fnamemodify calls are removed; some have intrinsic differences in behavior with the `vim.fs` replacement or do not yet have a replacement in the Lua module, i.e. `:~`, `:.`, `:e` and `:r`. --- runtime/lua/vim/loader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/loader.lua') diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua index 187d7076de..c5279990d1 100644 --- a/runtime/lua/vim/loader.lua +++ b/runtime/lua/vim/loader.lua @@ -429,7 +429,7 @@ function M.enable(enable) M.enabled = enable if enable then - vim.fn.mkdir(vim.fn.fnamemodify(M.path, ':p'), 'p') + vim.fn.mkdir(vim.fs.abspath(M.path), 'p') _G.loadfile = loadfile_cached -- add Lua loader table.insert(loaders, 2, loader_cached) -- cgit