Skip to main content
add link to related issue
Source Link

Depending on what you're trying to do, a viable alternative might be running the system command inside Vim to generate the locations and populating the quickfix list with the result. See How to create qf or location list from results of shell command for some ideas. Here's a Neovim/Lua example for inspiration:

vim.api.nvim_create_user_command('TorgleFlidgets',
    function()
        vim.cmd.cclose()
        print('🐰 torgling the flidgets ...')
        local out = vim.fn.systemlist("torgle ./flidgets.txt")
        if vim.v.shell_error == 0 then
            print('nothing to see here')
            return
        end
        local files = {}
        for _, file in pairs(out) do
            local parts = {}
            for part in string.gmatch(file, "%S+") do
                table.insert(parts, part)
            end
            table.insert(files, {filename = parts[1], lnum = parts[2], col = parts[3]})
        end
        vim.fn.setqflist(files)
        vim.cmd.copen()
    end,
    {nargs = 0}
)

In this notional example, the output of torgle ./flidgets.txt looks like:

/path/to/file1.txt 25 19
/path/to/file2.txt 44 37

(In my actual case, I used some combination of awk and sed to massage the output of my system command into this format. This particular example won't work if filenames may contain whitespace.)

Depending on what you're trying to do, a viable alternative might be running the system command inside Vim to generate the locations and populating the quickfix list with the result. Here's a Neovim/Lua example for inspiration:

vim.api.nvim_create_user_command('TorgleFlidgets',
    function()
        vim.cmd.cclose()
        print('🐰 torgling the flidgets ...')
        local out = vim.fn.systemlist("torgle ./flidgets.txt")
        if vim.v.shell_error == 0 then
            print('nothing to see here')
            return
        end
        local files = {}
        for _, file in pairs(out) do
            local parts = {}
            for part in string.gmatch(file, "%S+") do
                table.insert(parts, part)
            end
            table.insert(files, {filename = parts[1], lnum = parts[2], col = parts[3]})
        end
        vim.fn.setqflist(files)
        vim.cmd.copen()
    end,
    {nargs = 0}
)

In this notional example, the output of torgle ./flidgets.txt looks like:

/path/to/file1.txt 25 19
/path/to/file2.txt 44 37

(In my actual case, I used some combination of awk and sed to massage the output of my system command into this format. This particular example won't work if filenames may contain whitespace.)

Depending on what you're trying to do, a viable alternative might be running the system command inside Vim to generate the locations and populating the quickfix list with the result. See How to create qf or location list from results of shell command for some ideas. Here's a Neovim/Lua example for inspiration:

vim.api.nvim_create_user_command('TorgleFlidgets',
    function()
        vim.cmd.cclose()
        print('🐰 torgling the flidgets ...')
        local out = vim.fn.systemlist("torgle ./flidgets.txt")
        if vim.v.shell_error == 0 then
            print('nothing to see here')
            return
        end
        local files = {}
        for _, file in pairs(out) do
            local parts = {}
            for part in string.gmatch(file, "%S+") do
                table.insert(parts, part)
            end
            table.insert(files, {filename = parts[1], lnum = parts[2], col = parts[3]})
        end
        vim.fn.setqflist(files)
        vim.cmd.copen()
    end,
    {nargs = 0}
)

In this notional example, the output of torgle ./flidgets.txt looks like:

/path/to/file1.txt 25 19
/path/to/file2.txt 44 37

(In my actual case, I used some combination of awk and sed to massage the output of my system command into this format. This particular example won't work if filenames may contain whitespace.)

Source Link

Depending on what you're trying to do, a viable alternative might be running the system command inside Vim to generate the locations and populating the quickfix list with the result. Here's a Neovim/Lua example for inspiration:

vim.api.nvim_create_user_command('TorgleFlidgets',
    function()
        vim.cmd.cclose()
        print('🐰 torgling the flidgets ...')
        local out = vim.fn.systemlist("torgle ./flidgets.txt")
        if vim.v.shell_error == 0 then
            print('nothing to see here')
            return
        end
        local files = {}
        for _, file in pairs(out) do
            local parts = {}
            for part in string.gmatch(file, "%S+") do
                table.insert(parts, part)
            end
            table.insert(files, {filename = parts[1], lnum = parts[2], col = parts[3]})
        end
        vim.fn.setqflist(files)
        vim.cmd.copen()
    end,
    {nargs = 0}
)

In this notional example, the output of torgle ./flidgets.txt looks like:

/path/to/file1.txt 25 19
/path/to/file2.txt 44 37

(In my actual case, I used some combination of awk and sed to massage the output of my system command into this format. This particular example won't work if filenames may contain whitespace.)