toppair / reach.nvim

Buffer, mark, tabpage, colorscheme switcher for Neovim
MIT License
239 stars 7 forks source link

Search by name #4

Closed nicoe closed 2 years ago

nicoe commented 2 years ago

Thank you for this plugin, it's very cool, it does one thing and does it well :+1:

This is a feature request: I am wondering if it would be possible to search for a buffer name (currently I type :b name and then choose the right one), I know there is telescope and so on but I wouldn't use all their options so …

toppair commented 2 years ago

You're welcome

If I understand correctly, you want a command that works like :b pattern<Tab> but with results displayed in this plugin's popup?

You could write your own wrapper around require('reach').buffers() and use filter option.

Came up with something like this:

-- init.lua

vim.api.nvim_command('command -nargs=1 B lua require("file").buffers("<args>")')

-- file.lua

local module = {}

module.buffers = function(pattern)
  local output = vim.api.nvim_exec(string.format('filter %s ls', pattern), true)
  local bufnrs = vim.tbl_map(function(row)
    return tonumber(vim.split(row, '[ \t]+', { trimempty = true })[1])
  end, vim.split(output, '\n', { trimempty = true }))

  vim.api.nvim_command('redraw')

  require('reach').buffers({
    filter = function(bufnr)
      return vim.tbl_contains(bufnrs, bufnr)
    end,
  })
end

return module

You need to update your plugins, because small fix was needed for it to work well.

nicoe commented 2 years ago

If I understand correctly, you want a command that works like :b pattern<Tab> but with results displayed in this plugin's popup?

Yes kind of that. But I would start with the full list of buffers and filter them on the fly. But I'll test the code you posted, it will probably be enough anyway.

Thank you very much