Closed fhill2 closed 1 year ago
Are you running nvim with tmux? When the option mouse=
is the default value, I can scroll in ranger inside nvim, but can't inside nvim with tmux unless set mouse off
for tmux.
If you run nvim without tmux, make sure that option mouse
excluded [a|h|n]
, https://github.com/vim/vim/issues/2841
I have no idea how to solve this issue perfectly, but I have a workaround, add below script in your config:
function s:set_mouse_with_rnvimr() abort
let n_mouse = &mouse
augroup RnvimrMouse
autocmd!
autocmd FileType rnvimr call <SID>set_mouse_with_rnvimr()
augroup end
if match(n_mouse, '[a|h|n]') >= 0
augroup RnvimrMouse
autocmd TermEnter,WinEnter <buffer> call nvim_set_option('mouse', '')
execute printf("autocmd WinLeave <buffer> call nvim_set_option('mouse', '%s')", n_mouse)
augroup END
endif
if exists('$TMUX')
if system('tmux display -p "#{mouse}"')[0]
augroup RnvimrMouse
autocmd TermEnter,WinEnter <buffer> call system('tmux set mouse off')
autocmd WinLeave <buffer> call system('tmux set mouse on')
augroup END
endif
endif
endfunction
augroup RnvimrMouse
autocmd FileType rnvimr call <SID>set_mouse_with_rnvimr()
augroup END
I am not using Tmux.
Posting again for anyone else having issues with Mouse Scrolling inside Rnvimr, as the function provided by @kevinhwang91 has fixed the issue on my system.
The problem was starting neovim with set mouse=a
, opening Rnvimr, scrolling using the mouse wheel scrolled the whole floating window and not the individual folder list inside ranger.
Including the above config to init.vim enabled mouse scrolling of the ranger folder/file list while still being able to use set mouse=a
Thank you let me know this script works for you, although it's a bit late, it's better to be late than never.
@kevinhwang91 your code works as expected. Why not merging it? I tested it both on foot terminal and then on foot terminal+tmux.
I ported it to lua for my settings. But it is your code.
-- 16. Ranger rnvim enable mouse support
local augroup = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd
local rnvimr_mouse_group = augroup("RnvimrMouse", { clear = true })
-- Enables mouse support for rnvimr
local function set_mouse_with_rnvimr()
local n_mouse = vim.o.mouse
-- Disable nvim mouse support while we are on the rnvimr buffer
if string.match(n_mouse, "[a|h|n]") then
autocmd({ "TermEnter", "WinEnter <buffer>" }, {
desc = "Disable nvim mouse support while we are on the rnvimr buffer",
group = rnvimr_mouse_group,
callback = function() vim.api.nvim_set_option("mouse", "") end,
})
-- Restore mouse mode on exiting rnvimr
autocmd({ "TermLeave", "WinLeave <buffer>" }, {
desc = "Disable nvim mouse support while we are on the rnvimr buffer",
group = rnvimr_mouse_group,
callback = function() vim.api.nvim_set_option("mouse", n_mouse) end,
})
end
-- Extra mouse fix for tmux
-- If tmux mouse mode is enabled
if os.getenv('TMUX') then
local output = vim.fn.system 'tmux display -p "#{mouse}"'
if output:sub(1, 1) == "1" then
-- Disable tmux mouse while using rnvimr
autocmd({ "TermEnter", "WinEnter <buffer>" }, {
desc = "Disable tmux mouse while using rnvimr",
group = rnvimr_mouse_group,
callback = function() vim.fn.system "tmux set mouse off" end,
})
-- Enable tmux mouse when mouse leaves rnvimr
autocmd({ "WinLeave <buffer>" }, {
desc = "Enable tmux mouse when mouse leaves rnvimr",
group = rnvimr_mouse_group,
callback = function() vim.fn.system "tmux set mouse on" end,
})
end
end
end
-- Entry point
autocmd({ "FileType rnvimr" }, {
desc = "If we are on the rnvimr buffer, execute the callback",
group = rnvimr_mouse_group,
callback = function()
if vim.bo.filetype == "rnvimr" then set_mouse_with_rnvimr() end
end,
})
end,
@kevinhwang91 your code works as expected. Why not merging it? I tested it both on foot terminal and then on foot terminal+tmux.
Thanks to remind me for this idea. At the time of opening this issue, the mouse
option is empty by default. I will merge this script into rnvimr if it works fine for me.
Is scrolling files/directories using mouse wheel implemented/working from within the rnvimr floating window?