Skip to content
Jakson Alves de Aquino edited this page Jan 17, 2024 · 1 revision

It is possible to add the status of Nvim-R to Vim/Neovim status line. The example below is for lualine.nvim and will display the following states:

  • nothing: Nvim-R not enabled.
  • - (grey): An R file is being edited, but the nvimrserver is not running yet.
  • S (grey): The nvimrserver started, but did not finish loading omni-completion data yet.
  • S (green): The nvimrserver loaded the omni-completion data.
  • R (orange): R was started, but nvimcom is not loaded yet.
  • R (blue): nvimcom is loaded and connected to nvimrserver.
    {
        "nvim-lualine/lualine.nvim",
        config = function()
            local rstatus = function ()
                if not vim.g.rplugin then
                    -- No R file type (R, Quarto, Rmd, Rhelp) opened yet
                    return ""
                end
                if vim.g.rplugin.jobs.R ~= 0 then
                    -- R was launched and nvimrserver started its TCP server
                    return "R"
                end
                if vim.g.rplugin.jobs.Server ~= 0 then
                    -- nvimrserver was started
                    return "S"
                else
                    -- nvimrserver was not started yet
                    return "-"
                end
            end

            local rsttcolor = function ()
                if not vim.g.rplugin then
                    return {fg = "#000000"}
                end
                if vim.g.rplugin.jobs.R ~= 0 then
                    if vim.g.rplugin.R_pid == 0 then
                        -- R was launched
                        return {fg = "#ff8833"}
                    else
                        -- R started and informed its PID.
                        -- This means nvimcom is running.
                        return {fg = "#3388ff"}
                    end
                end
                if vim.g.rplugin.jobs.Server ~= 0 and #vim.g.rplugin.libs_in_nrs > 0 then
                    -- nvimrserver finished reading omni completion files
                    return {fg = "#33ff33"}
                end
                return {fg = "#aaaaaa"}
            end

            require("lualine").setup({
                options = {
                    section_separators = "",
                    component_separators = "",
                    globalstatus = true,
                },
                sections = {
                    lualine_y = { {rstatus, color = rsttcolor }},
                    lualine_z = { "progress", "location" },
                },
            })
        end,
    },