Closed gueyenono closed 2 months ago
Vim/Neovim has key bindings to move from one window to another. From Neovim help:
CTRL-W h move to the window on the left
CTRL-W j move to the window below
CTRL-W k move to the window above
CTRL-W l move to the window on the right
You can change these key bindings to whatever you want in your Neovim configuration.
You may create an auto command to switch to Insert mode if the buffer you are entering is the R Console.
Thank you for your recommendation @jalvesaq The idea behind my code was to be able to switch to the R Console automatically even if I had a multitude of open windows. With Ctrl-W, I have to navigate to the R console manually. Also, the idea about the auto command is very well noted. I will try to work on it. Thank you.
Maybe something like that where buffer_number = require('r.term').get_buf_nr()
-- Define a function to focus on the window corresponding to a buffer number
function focus_window_by_buffer(buffer_number)
-- Iterate over all windows in the current tabpage
for _, win_id in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
-- Get the buffer number of the window
local buf_nr = vim.api.nvim_win_get_buf(win_id)
-- If the buffer number matches the one provided, focus on that window
if buf_nr == buffer_number then
vim.api.nvim_set_current_win(win_id)
return
end
end
print("Window for buffer " .. buffer_number .. " not found.")
end
Greetings,
I very recently started learning Neovim and Lua and, as an R user, also recently installed the R.nvim plugin. I have been exploring the documentation to learn more and more.
I am trying to set a key binding that will: (i) focus on the R console, (ii) in insert mode. This would be an implementation of "Ctrl + 2" in RStudio. I want the key binding to be:
<localleader>ri
. Here is my (failed) attempt below:I would appreciate your guidance.