0

I have the following problem:

I want to write a vim command to render the current (.rmd) file I'm working on.

My attempt is the following:

I put this into my init.lua

vim.cmd('call nvim_create_user_command(\'Render\', \'! R -e \"rmarkdown::render("´realpath %´")\" \', {})')

notice that I change this (` = ´) for the example to view the code snippet properly

Okay so technically it's working ...

Thats the errorcode

Error: unexpected '/' in "rmarkdown::render(/"

The command is not recognize the " aroud the path.

Would be glad if anyone come up with an idea

alex
  • 89
  • 7

1 Answers1

0

Found a solution:

vim.cmd('call nvim_create_user_command(\'Render\', \'! R -e \"rmarkdown::render(\\"`realpath %`\\")\" \', {})')

The Problem was that the argument for the render function was not recognized as a string. I had to put \\ before the "

alex
  • 89
  • 7
  • The standard way to define a Vim command is something like this: `command! Render !R -e "rmarkdown::render(\"...\")"` (`:help user-commands`). If you'd like to use it in a lua config file, you can wrap it in `vim.cmd`. But you don't need to use `nvim_create_user_command` -- that just adds more nested quotes you need to escape. The nvim function is meant for defining commands programmatically -- say, if the name is in a user-defined variable, or maybe you have a loop with multiple variations of the name. If this is a command you're just defining in your config, there's no need for it. – Andrew Radev Jul 17 '22 at 07:58