mikavilpas / yazi.nvim

A Neovim Plugin for the yazi terminal file manager
MIT License
217 stars 7 forks source link

Escape file name special characters #60

Closed tomsjansons closed 2 months ago

tomsjansons commented 2 months ago

I've encountered an issue where an unescaped $ character in a file name prevents nvim from opening a file from yazi.

In Remix $ is used for a dynamic url path element so this character often shows up in file names.

When the default config in the plugin calls vim.cmd(string.format('edit %s', chosen_file)), https://github.com/mikavilpas/yazi.nvim/blob/01e4685b197bf09b7b41c9ab4b170f50692d0394/lua/yazi/openers.lua#L5 nvim ends up stripping the segment so routes/posts.$postId/route.tsx ends up being routes/posts./route.tsx

I am not familiar enough with nvim's special characters so for my purposes I've managed to solve the problem by escaping only the $ character

     open_file_function = function(chosen_file, config)
        local escaped_chosen_file = string.gsub(chosen_file, "%$", "\\$")
        vim.cmd(string.format('edit %s', escaped_chosen_file))
      end,

happy to do a PR, I'd just need to do a bit of research on nvim and special chars in file names

mikavilpas commented 2 months ago

Thanks for the bug report! I was able to reproduce this, and I think I found a fix. Will PR soon.

mikavilpas commented 2 months ago

Ok it now works at least for single files. I'm not sure if opening multiple file like this works yet, I might have to look into that later.