From c501a53e0700da6a8623e2509b33d4d583dde6af Mon Sep 17 00:00:00 2001 From: Jakson Alves de Aquino Date: Sat, 27 Jun 2026 07:20:33 -0300 Subject: [PATCH 1/2] New option: `rconsole_pos` Close #598 --- README.md | 5 +++++ doc/R.nvim.txt | 9 +++++++-- lua/r/config.lua | 4 ++++ lua/r/term/builtin.lua | 10 ++++++---- lua/r/term/wezterm.lua | 6 +++--- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0667ea69..204d335c 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,11 @@ firm commitment to backwards compatibility. - `R_source` and `after_R_start` have been replaced with more powerful `hook` options. +- When running R in the Neovim built-in terminal or in a WezTerm split pane, + the `R.nvim` config option `rconsole_pos` should be used to define the + position of the R Console. The Vim options 'splitright' and 'splitbelow' are + ignored. + - `nvimpager`, which controls how R documentation is displayed, now has possible options `"split_h"`, `"split_v"`, `"tab"`, `"float"` (not implemented yet), and `"no"`. diff --git a/doc/R.nvim.txt b/doc/R.nvim.txt index ab23ec93..16805484 100644 --- a/doc/R.nvim.txt +++ b/doc/R.nvim.txt @@ -975,6 +975,7 @@ You may close the window opened by `:RConfigShow` by simply pressing `q`. |config_tmux| Don't use a specially built Tmux config file |rconsole_height| Number of lines of R Console |rconsole_width| Number of columns of R Console +|rconsole_pos| Position of the R Console relative to the editor window |register_treesitter| Register treesitter parsers for quarto and rmd files |min_editor_width| Minimum number of columns of editor after R start |RStudio_cmd| Run RStudio instead of R. @@ -1867,8 +1868,12 @@ For a horizontal split, you can set the number of lines of the R window: >lua rconsole_height = 15 < -You should set 'nosplitright' if you wanted the R Console on the left side, -and 'nosplitbelow' if you wanted it above the R script. + +By default, in a vertical split, the R Console opens on the right of the +editor window; in a horizontal split, it opens below the editor window. You +can set the value of `rconsole_pos` to get the R Console in a different +position. Valid values are "below,right", "below,left", "above,right", and +"above,left". Note: If running R in a Neovim buffer, the number of lines and columns will automatically change if you switch between horizontal and vertical splits (see diff --git a/lua/r/config.lua b/lua/r/config.lua index 0dc4e726..c92f6152 100644 --- a/lua/r/config.lua +++ b/lua/r/config.lua @@ -348,6 +348,9 @@ local hooks = require("r.hooks") ---Do `:help rconsole_width` for more information. ---@field rconsole_width? integer --- +--- Position of the R Console relative to the editor window. +---@field rconsole_pos? '"below,right"' | '"below,left"' | "above,right" | '"above,left"' +--- ---Whether to register the Markdown parser for Quarto and RMarkdown documents; ---defaults to `true`. Do `:help register_treesitter` for more information. ---@field register_treesitter? boolean @@ -576,6 +579,7 @@ local config = { roxygen_hl = false, rconsole_height = 15, rconsole_width = 80, + rconsole_pos = "below,right", register_treesitter = true, remote_compl_dir = "", remote_R_host = "", diff --git a/lua/r/term/builtin.lua b/lua/r/term/builtin.lua index 3dc48eb2..05c052bc 100644 --- a/lua/r/term/builtin.lua +++ b/lua/r/term/builtin.lua @@ -72,22 +72,24 @@ local split_window = function() local nw = vim.o.number and vim.o.numberwidth or 0 local sw = config.rconsole_width + config.min_editor_width + 1 + nw if config.rconsole_width > 0 and vim.fn.winwidth(0) > sw then + local pos = config.rconsole_pos:find("left") and "aboveleft" or "belowright" if config.rconsole_width > 16 and config.rconsole_width < (vim.fn.winwidth(0) - 17) then - vim.cmd("silent exe 'belowright " .. config.rconsole_width .. "vnew'") + vim.cmd("silent exe '" .. pos .. " " .. config.rconsole_width .. "vnew'") else - vim.cmd("silent belowright vnew") + vim.cmd("silent " .. pos .. " vnew") end else + local pos = config.rconsole_pos:find("above") and "aboveleft" or "belowright" if config.rconsole_height > 0 and config.rconsole_height < (vim.fn.winheight(0) - 1) then - vim.cmd("silent exe 'belowright " .. config.rconsole_height .. "new'") + vim.cmd("silent exe '" .. pos .. " " .. config.rconsole_height .. "new'") else - vim.cmd("silent belowright new") + vim.cmd("silent " .. pos .. " new") end end end diff --git a/lua/r/term/wezterm.lua b/lua/r/term/wezterm.lua index 425948b9..29af73ff 100644 --- a/lua/r/term/wezterm.lua +++ b/lua/r/term/wezterm.lua @@ -27,15 +27,15 @@ M.start = function() } else ed_pane = vim.env.WEZTERM_PANE - local location = "--right" + local location = config.rconsole_pos:find("left") and "--left" or "--right" local nw = vim.o.number and vim.o.numberwidth or 0 local swd = config.rconsole_width + config.min_editor_width + 1 + nw if config.rconsole_width == 0 or (vim.fn.winwidth(0) < swd) then - location = "--bottom" + location = config.rconsole_pos:find("above") and "--top" or "--bottom" end local prcnt - if location == "--right" then + if location == "--right" or location == "--left" then prcnt = vim.fn.round(100 * config.rconsole_width / vim.fn.winwidth(0)) else prcnt = vim.fn.round(100 * config.rconsole_height / vim.fn.winheight(0)) From 573080cc9a2a28e613772fd2a1cc5dc02e34c80a Mon Sep 17 00:00:00 2001 From: Jakson Alves de Aquino Date: Sat, 27 Jun 2026 07:58:25 -0300 Subject: [PATCH 2/2] Add missing anchor --- doc/R.nvim.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/R.nvim.txt b/doc/R.nvim.txt index 16805484..9c5d188f 100644 --- a/doc/R.nvim.txt +++ b/doc/R.nvim.txt @@ -976,7 +976,6 @@ You may close the window opened by `:RConfigShow` by simply pressing `q`. |rconsole_height| Number of lines of R Console |rconsole_width| Number of columns of R Console |rconsole_pos| Position of the R Console relative to the editor window -|register_treesitter| Register treesitter parsers for quarto and rmd files |min_editor_width| Minimum number of columns of editor after R start |RStudio_cmd| Run RStudio instead of R. |listmethods| Do `nvim.list.args()` instead of `args()` @@ -1002,6 +1001,7 @@ You may close the window opened by `:RConfigShow` by simply pressing `q`. |open_html| Open HTML after processing Rmd or Quarto |insert_mode_cmds| Allow R commands in insert mode |rmhidden| Remove hidden objects from R workspace +|register_treesitter| Register treesitter parsers for quarto and rmd files |set_params| Control setting `params` in `.GlobalEnv` |wait| Time to wait for nvimcom loading |wait_reply| Time to wait for R reply @@ -1843,6 +1843,7 @@ file (~/.tmux.conf). ------------------------------------------------------------------------------ 6.14. Control of R window *rconsole_height* *rconsole_width* + *rconsole_pos* *min_editor_width* When starting R, Neovim's buffer is split vertically if its width is larger @@ -1868,7 +1869,6 @@ For a horizontal split, you can set the number of lines of the R window: >lua rconsole_height = 15 < - By default, in a vertical split, the R Console opens on the right of the editor window; in a horizontal split, it opens below the editor window. You can set the value of `rconsole_pos` to get the R Console in a different