-
Notifications
You must be signed in to change notification settings - Fork 52
Description
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
cd ~/project && nvim- Open yazi with
:Yazi cwd - Navigate to
src/foo.lua - Press
<c-v>to open in vertical split :echo expand('%')shows/Users/me/project/src/foo.luainstead ofsrc/foo.lua
Compare with <CR> using this open_file_function which works correctly:
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:
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