Scrollview hides text at the end of a line
Hello!
I'm not sure if it is a bug or not but the scrollbar hides text at the end of a line. Is there any way to wrap text before scrollbar?
Steps to reproduce
nvim -u min.lua:e somefile.txt- Add a window or resize it so that text is wrapped.
- Observe how letters at the end of a line are hidden behind the scrollbar (screenshot below).
Minimal config
local root = '/tmp/nvim'
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end
local lazy_path = root .. '/plugins/lazy.nvim'
if not vim.uv.fs_stat(lazy_path) then
vim.api.nvim_cmd({
cmd = '!',
args = {
'git',
'clone',
'--filter=blob:none',
'--single-branch',
'https://github.com/folke/lazy.nvim.git',
lazy_path,
},
}, {})
end
vim.opt.runtimepath:prepend(lazy_path)
local plugins = {
{ 'folke/lazy.nvim' },
{ 'rebelot/kanagawa.nvim' },
-- plugins
{
'dstein64/nvim-scrollview',
dependencies = { 'lewis6991/gitsigns.nvim', config = true },
config = function()
vim.cmd([[let g:scrollview_mode = 'proper']])
require('scrollview.contrib.gitsigns').setup()
end,
},
}
vim.g.mapleader = ' '
require('lazy').setup(plugins, {
root = root .. '/plugins',
})
vim.opt.termguicolors = true
vim.cmd({ cmd = 'colorscheme', args = { 'kanagawa' } })
Below the letters ex are hidden:
Hi @lostl1ght. I don't know of a Neovim option for specifying where text should wrap when wrap is set.
The plugin has options for controlling the transparency of its windows. If you're using termguicolors or a GUI, the option is scrollview_winblend_gui, otherwise the option is scrollview_winblend. They can be set between 0 and 100 (0 for full opacity and 100 for full transparency).
However, transparency only works if there is no text (on scrollbars and/or signs). By default, the scrollbar has no text (this can be changed with the scrollview_character option). By default, the built-in signs all include text. To make them transparent, they'd have to be configured to have no symbol, and a highlight that has a background color (the foreground highlight would only be applied to text).
Here's an example showing how the scrollbar and search signs could be made partially transparent.
let g:scrollview_winblend = 80
let g:scrollview_winblend_gui = 80
highlight ScrollViewSearch ctermbg=159 guibg=LightCyan
let g:scrollview_search_symbol = ''
But removing the text from signs makes them less useful. They'd have to be differentiated based on their color only.
So, it appears that there's no option to wrap before EOL. And, unfortunately, the suggested plugin setting are not ideal.
Other option is to toggle the scrollbar on InsertEnter & InsertLeave, so that it does not obstruct text in insert mode, but, again, it's not ideal.
You can close as not planned if you'd like.
I think we are missing this feature: https://github.com/neovim/neovim/issues/4386.
Other option is to toggle the scrollbar on
InsertEnter&InsertLeave, so that it does not obstruct text in insert mode
That's interesting, I will try this, but sometimes I have to edit in normal mode, so this can still be a problem, but less. Yeah, not ideal.
BTW, my problem is that sometimes some signs (?) are blocking the cell completely, like here:
So the fact that I have a transparent scrollbar doesn't mean anything. But now that I disable diagnostics on InsertEnter:
So at least entering and leaving the insert mode is much easier than pure pain of not seeing what is behind there. And I think this problem will only happen in text files (plain, Typst, Markdown etc.) and not in code files. Basically in half of the cases for me. ;)
I've added a new option, scrollview_hide_for_insert, for hiding scrollbars and signs for insert mode.
Vimscript:
let g:scrollview_hide_for_insert = v:true
Lua:
vim.g.scrollview_hide_for_insert = true
-- Or with a setup function:
require('scrollview').setup({
...
hide_for_insert = true,
...
})
Another workaround could be to use a mapping that toggles the plugin. For example, the following sets <ctrl-v> to toggle the plugin, including in insert mode.
noremap <c-v> <Plug>(ScrollViewToggle)
inoremap <c-v> <Plug>(ScrollViewToggle)
That's a good addition, but can you expand it to be able to customize which part gets hidden? I tried it, and I don't like that it also hides an already semitransparent scrollbar.
Instead, I use:
local scrollview_group = vim.api.nvim_create_augroup("scrollview", {})
vim.api.nvim_create_autocmd({ "InsertEnter" }, {
callback = function()
vim.cmd [[silent ScrollViewDisable diagnostics]]
end,
group = scrollview_group,
})
vim.api.nvim_create_autocmd({ "InsertLeave" }, {
callback = function()
vim.cmd [[silent ScrollViewEnable diagnostics]]
end,
group = scrollview_group,
})
Like, it can be true for everything or can be a table with a list of things to disable individually. So for me, it would be:
require("scrollview").setup {
hide_for_insert = { "diagnostics" },
}
Hi @Andrew15-5. I've replaced scrollview_hide_for_insert with two separate options, scrollview_signs_hidden_for_insert and scrollview_hide_bar_for_insert. The first specifies a list of sign groups that will be hidden for insert mode. 'all' can be used to represent all sign groups. The second option uses a boolean to indicate whether the scrollbar will be hidden for insert mode.
The following examples will hide all signs and the scrollbar.
Vimscript:
let g:scrollview_signs_hidden_for_insert = ['all']
let g:scrollview_hide_bar_for_insert = v:true
Lua:
vim.g.scrollview_signs_hidden_for_insert = {'all'}
vim.g.scrollview_hide_bar_for_insert = true
-- Or with a setup function:
require('scrollview').setup({
...
signs_hidden_for_insert = {'all'},
hide_bar_for_insert = true,
...
})
The following examples will hide just the diagnostics signs.
Vimscript:
let g:scrollview_signs_hidden_for_insert = ['diagnostics']
Lua:
vim.g.scrollview_signs_hidden_for_insert = {'diagnostics'}
-- Or with a setup function:
require('scrollview').setup({
...
signs_hidden_for_insert = {'diagnostics'},
...
})
Thank you very much. My config is now much cleaner.
While it being hidden in insert mode is great, still the characters aren't visible in normal mode.
Is it possible to not render the bar / symbols when there are non-whitespace characters in those cells?
Something similar to how hide_on_cursor_intersect works?
e.g. hide_on_character_intersect?
Hi @stankovictab. When hide_on_cursor_intersect was implemented, I also considered adding a hide_on_text_intersect option, which was the same type of option as the hide_on_character_intersect option you proposed. I tried implementing it using the screenstring function, but didn't achieve the intended functionality. Perhaps there's some alternative approach. I just created Issue #146.