0

I currently have the following keymap:

vim.keymap.set('n', '<leader>sr', function() return ":vs | term " end, { expr = true })

This drops me into a vim command where I can complete the invocation of term by typing in the terminal command I'd like to run. The nice thing about this is that I get all kinds of nice completions while I'm finishing the command invocation. Shell commands will tab-complete as well as file paths, and I'm sure other things.

I'd like to something that's more "pure lua" while also utilizing vim.ui.input. I've developed the following:

vim.keymap.set('n', '<leader>sr', function()
    vim.ui.input({
        prompt = 'Run shell command: ',
        completion = 'shellcmd',
    }, function(command)
        if command ~= nil and command ~= "" then
            vim.cmd.split()
            vim.cmd.term(command)
        else
            vim.notify("command aborted")
        end
    end)
end)

This mostly works, however the completion isn't as good. Only the names of shell commands will auto complete, file paths and other entities that would complete if I were just doing :term don't seem to want to complete.

Is there a way I can get better completion here? Even just being able to do shellcmd and file completion would be great.

0

Your Answer

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

Browse other questions tagged or ask your own question.