ITADN

`<c-v>`, `<c-x>`, `<c-t>` open files with absolute paths instead of relative to cwd

#1712Openbign0name 创建于 2026-03-20
stale
B
bign0namecommented
### Problem When opening files via `<c-v>` (vertical split), `<c-x>` (horizontal split), or `<c-t>` (new tab), the buffer name is set to the absolute path (e.g. `/Users/me/project/src/foo.lua`). This means the tabline and statusline show the full path. Opening the same file via `<CR>` with a custom `open_file_function` allows using relative paths, and other plugins like Telescope and oil.nvim open buffers with paths relative to cwd by default (e.g. `src/foo.lua`). ### Expected behavior When opening a file that is under Neovim's cwd, the buffer should be opened with a relative path, consistent with how Telescope and other file pickers behave. ### Steps to reproduce 1. `cd ~/project && nvim` 2. Open yazi with `:Yazi cwd` 3. Navigate to `src/foo.lua` 4. Press `<c-v>` to open in vertical split 5. `:echo expand('%')` shows `/Users/me/project/src/foo.lua` instead of `src/foo.lua` Compare with `<CR>` using this `open_file_function` which works correctly: ```lua open_file_function = function(chosen_file, config, state) local cwd = vim.fn.getcwd() .. "/" local path = chosen_file if path:sub(1, #cwd) == cwd then path = path:sub(#cwd + 1) end vim.cmd("edit " .. vim.fn.fnameescape(path)) end, ``` ### Suggested fix Wherever the `<c-v>`, `<c-x>`, and `<c-t>` handlers call `:vsplit`, `:split`, or `:tabedit` with the chosen path, convert to relative first: ```lua local function relative_path(absolute) local cwd = vim.fn.getcwd() .. "/" if absolute:sub(1, #cwd) == cwd then return absolute:sub(#cwd + 1) end return absolute end -- then in each handler: vim.cmd("vsplit " .. vim.fn.fnameescape(relative_path(chosen_file))) ``` ### Environment - macOS, zsh - Neovim stable - yazi.nvim latest stable
1 条评论