1

I am using Neovim and I use this code to get the full path of the current file.

local currnetPath=vim.api.nvim_buf_get_name(0)

I want to use this variable for opening the current HTML file, so I need to pass it to my browser (chrome.exe in Windows). It works but for some directories, it gets into problems. If the path has space, this method does not work perfectly, for example, Course - Python Data Structures 2023-8 for folder name. And this is my whole code:

local function run_google_for_current_file()
  -- add chrome folder to your path
  local currnetPath=vim.api.nvim_buf_get_name(0)
  vim.api.nvim_feedkeys(":!chrome "..currnetPath.."\n","n", false)
end
vim.keymap.set({'n'}, '<space>rg', '', { 
    desc = "run_google_for_current_file", 
    callback = run_google_for_current_file
})

How can I handle all paths in Lua even with whitespaces?

1
  • 1
    In Vim I would suggest system or similar: the problem is that you try to rely on the shell processing your arguments without quoting them. It’ll be easier to invoke program you need with exactly the right arguments.
    – D. Ben Knoble
    Dec 17, 2023 at 2:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.