Fix nvim shortcuts for files with non-English characters

- Add Unicode-safe Lua functions for file operations
- Replace shell commands with proper escaping using vim.fn.shellescape()
- Update <leader>o and <leader>f keymaps to use new Lua functions
- Fixes issues with Chinese and other Unicode characters in filenames

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yan Lin 2025-07-30 18:36:36 +02:00
parent cc0b8450e0
commit 1b9cb26015

View file

@ -163,13 +163,13 @@
{ {
mode = "n"; mode = "n";
key = "<leader>o"; key = "<leader>o";
action = ":silent !open %<CR>"; action = ":lua open_file_with_system_app()<CR>";
options = { desc = "Open file with system default app"; }; options = { desc = "Open file with system default app"; };
} }
{ {
mode = "n"; mode = "n";
key = "<leader>f"; key = "<leader>f";
action = ":silent !open -R %<CR>"; action = ":lua show_file_in_finder()<CR>";
options = { desc = "Show current file in Finder"; }; options = { desc = "Show current file in Finder"; };
} }
@ -220,6 +220,27 @@
}, },
}, },
}) })
-- Unicode-safe file operations for macOS
function open_file_with_system_app()
local filepath = vim.fn.expand('%:p')
if filepath ~= "" then
local escaped_path = vim.fn.shellescape(filepath)
vim.fn.system('open ' .. escaped_path)
else
print("No file to open")
end
end
function show_file_in_finder()
local filepath = vim.fn.expand('%:p')
if filepath ~= "" then
local escaped_path = vim.fn.shellescape(filepath)
vim.fn.system('open -R ' .. escaped_path)
else
print("No file to show")
end
end
''; '';
}; };
} }