How do I translate this VimL code into Lua?
if executable('rg') set grepprg=rg\ --vimgrep endif
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
The answer below assumes you are running neovim and not vim.
:h vim.cmd() lets you execute a vimscript command from lua. It takes the command as a string. So you can wrap any vimscript in a string and pass it to
:lua vim.cmd() and it should work.
vim.cmd[[ if executable('rg') set grepprg=rg\ --vimgrep endif ]]
On the other hand, if you want a more lua-like approach, you can use
:h vim.fn to call any vim function, both user-defined and built-in. With
:h vim.o or
:h vim.opt you can set the vim options.
if vim.fn.executable('rg') == 1 then vim.o.grepprg = 'rg --vimgrep' end