R-nvim/R.nvim

hook defined in the config r.nvim works for only the first opened *.r file

samtrek opened this issue · 4 comments

The hook defined in the r.nvim config file works only for the first opened *.r files (not tested in *.rmd), without closing the first file, other opened *.r files do not respond to the keybinds within the hook.

Anyway to implement it in such a way that the hook applies to all *.r files and possibly *.rmd files?

Are you using the new hook on_filetype?

the hook defined in my config looks like this, lifted directly form the suggested config, I did not use the on_filetype, it only has the after_config (I have little knowledge of lua, so I try to keep my config similar to the suggested config). All the other localleader+other keybindings work as they should, just that the config below is very continent and I have gotten used to it.

hook = {
after_config = function()
-- This function will be called at the FileType event
-- of files supported by R.nvim. This is an
-- opportunity to create mappings local to buffers.
if vim.o.syntax ~= "rbrowser" then
vim.api.nvim_buf_set_keymap(0, "n", "", "RDSendLine", {})
vim.api.nvim_buf_set_keymap(0, "v", "", "RSendSelection", {})
end
-- Pipe operator
vim.api.nvim_buf_set_keymap(0, "i", "", " |>", {})
end,
},

I forgot to update the README. But I will change the example to:

hook = {
  on_filetype = function ()
    -- This function will be called at the FileType event
    -- of files supported by R.nvim. This is an
    -- opportunity to create mappings local to buffers.
    vim.api.nvim_buf_set_keymap(0, "n", "<Enter>", "<Plug>RDSendLine", {})
    vim.api.nvim_buf_set_keymap(0, "v", "<Enter>", "<Plug>RSendSelection", {})
  end
},

Yes that did the trick thank you once again for your efforts.