nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

[Question]: Disable Scrollbar

Open techtycho opened this issue 2 years ago • 6 comments

How to hide the scrollbar, because it looks very bad in my config:

2022-07-23_16-19

Can I hide the scrollbar, I want to still be able to scroll with keybindings, but with a hidden scrollbar.

techtycho avatar Jul 23 '22 14:07 techtycho

It would be really nice to bring back the thin scrollbar that was introduced during the development of floating window based completion window but later removed. thin scrollbar looks slick!

ratheesh avatar Jul 24 '22 05:07 ratheesh

Hey, can I even change the scrollbar characters?

techtycho avatar Jul 24 '22 22:07 techtycho

@techtycho, We had this option during the development of the the floating window based completion PR. But, it was removed before integration into the main branch.

ratheesh avatar Jul 25 '22 00:07 ratheesh

Is the scrollbar related to nvim-cmp specifically, or just a Neovim API feature?

techtycho avatar Jul 25 '22 07:07 techtycho

The scrollbar is the original feature in nvim-cmp.

Shougo avatar Jul 25 '22 07:07 Shougo

Is there anything I can do to get it right? At least make it look good on my config instead of entirely getting rid of it?

EDIT: I think I found the code responsible for drawing the scrollbar:

 if info.scrollable then
    -- Draw the background of the scrollbar

    if not info.border_info.visible then
      local style = {
        relative = 'editor',
        style = 'minimal',
        width = 1,
        height = self.style.height,
        row = info.row,
        col = info.col + info.width - info.scrollbar_offset, -- info.col was already contained the scrollbar offset.
        zindex = (self.style.zindex and (self.style.zindex + 1) or 1),
      }
      if self.sbar_win and vim.api.nvim_win_is_valid(self.sbar_win) then
        vim.api.nvim_win_set_config(self.sbar_win, style)
      else
        style.noautocmd = true
        self.sbar_win = vim.api.nvim_open_win(buffer.ensure(self.name .. 'sbar_buf'), false, style)
        vim.api.nvim_win_set_option(self.sbar_win, 'winhighlight', 'EndOfBuffer:PmenuSbar,NormalFloat:PmenuSbar')
      end
    end

    -- Draw the scrollbar thumb
    local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height()) + 0.5)
    local thumb_offset = math.floor(info.inner_height * (vim.fn.getwininfo(self.win)[1].topline / self:get_content_height()))

    local style = {
      relative = 'editor',
      style = 'minimal',
      width = 1,
      height = math.max(1, thumb_height),
      row = info.row + thumb_offset + (info.border_info.visible and info.border_info.top or 0),
      col = info.col + info.width - 1, -- info.col was already added scrollbar offset.
      zindex = (self.style.zindex and (self.style.zindex + 2) or 2),
    }
    if self.thumb_win and vim.api.nvim_win_is_valid(self.thumb_win) then
      vim.api.nvim_win_set_config(self.thumb_win, style)
    else
      style.noautocmd = true
      self.thumb_win = vim.api.nvim_open_win(buffer.ensure(self.name .. 'thumb_buf'), false, style)
      vim.api.nvim_win_set_option(self.thumb_win, 'winhighlight', 'EndOfBuffer:PmenuThumb,NormalFloat:PmenuThumb')
    end
  else
    if self.sbar_win and vim.api.nvim_win_is_valid(self.sbar_win) then
      vim.api.nvim_win_hide(self.sbar_win)
      self.sbar_win = nil
    end
    if self.thumb_win and vim.api.nvim_win_is_valid(self.thumb_win) then
      vim.api.nvim_win_hide(self.thumb_win)
      self.thumb_win = nil
    end
  end

I think PmenuThumb is the highlight group for the scrollbar thumb, but the rest of the code is messy, I'll try to read and understand it, in case a pull request is necessary.

techtycho avatar Jul 25 '22 07:07 techtycho

Any news on this?

AlexvZyl avatar Oct 04 '22 21:10 AlexvZyl

@Alex-vZyl I just deleted the if statement on my copy of nvim-cmp. All seems to work for me. I guess we just wait if this is every implemented but it should be pretty trivial if dodging the if block is the solution.

barrett-ruth avatar Nov 14 '22 01:11 barrett-ruth

https://github.com/hrsh7th/nvim-cmp/pull/1308 should answer this:

cmp.setup({
  window = {
    completion = {
      scrollbar = false,
    },
  },
})

pure-bliss avatar Nov 18 '22 14:11 pure-bliss