Coder Social home page Coder Social logo

ghillb / cybu.nvim Goto Github PK

View Code? Open in Web Editor NEW
305.0 305.0 5.0 58 KB

Neovim plugin that offers context when cycling buffers in the form of a customizable notification window.

License: MIT License

Lua 96.42% Makefile 3.58%
lua neovim neovim-plugin nvim plugin

cybu.nvim's Introduction

cybu.nvim's People

Contributors

dich0tomy avatar ghillb avatar ziboh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cybu.nvim's Issues

Cybu mixes buffers from different nvim instances

Hello!

I generally have several nvim instances running in a multiplexer, as I work on different projects concurrently. I noticed that cybu lists all buffers open in any of my nvim instances, instead of listing the buffers open only in the current instance. Do you think this could be fixed?

Change the buffer order to most recently used

Since you are basically implementing a kind of Alt-Tab within Neovim, how would you think of changing the order of the displayed buffers to most recently used. This would then refelect the Alt-Tab Behaviour to 100% :)

Cycle buffers in an MRU fashion

Is is possible to configure Cybu to cycle buffers in an MRU fashion? Similar to what Telescope is doing

For example, with sort_mru=true:

:Telescope buffers path=%:p:h initial_mode=insert select_buffer=true sort_mru=true<CR>

Feature request/question: show Cybu window on any buffer switch, not just on `CybuPrev`/`CybuNext`

Option to show Cybu window on <C-i>. <C-o>, Telescope jumps, as well as vanilla :bprev/:bnext etc, instead of hardcoded CybuPrev/CybuNext commands.


Can i maybe hack that behavior somehow without changing the code?
I've tried the following:

vim.api.nvim_create_autocmd('BufWinEnter', {
  group = vim.api.nvim_create_augroup('nrv#cybu_show_on_buffer_switch', {}),
  callback = function()
    require('cybu').populate_state()
    require('cybu').show_cybu_win(require('cybu').get_cybu_win_pos())
  end,
})

And it sort of works, but the current file displays incorrectly: if i switch between two files multiple times like with <C-o><C-i><C-o><C-i> the highlighted file cycles bottom-up indefinitely instead of highlighting two files back and forth. Jumping to a file with Telescope, gf etc. also selects file incorrectly.
And then if i open unusual buffer like help or lsp hover, the error is thrown: init.lua:357: attempt to perform arithmetic on a nil value.

Absolute path not working

When i set:

style = {
	path = "absolute",
}

The i see this error:

E5108: Error executing lua ...re/nvim/site/pack/packer/opt/cybu.nvim/lua/cybu/init.lua:68: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: in function 'ipairs'
        ...re/nvim/site/pack/packer/opt/cybu.nvim/lua/cybu/init.lua:68: in function 'get_widths'
        ...re/nvim/site/pack/packer/opt/cybu.nvim/lua/cybu/init.lua:273: in function 'populate_state'
        ...re/nvim/site/pack/packer/opt/cybu.nvim/lua/cybu/init.lua:289: in function 'cycle'
        [string ":lua"]:1: in main chunk

How can I use vim-unimpaired but map [b and ]b to cybu.nvim in init.lua with packer.nvim?

init.lua:

local use = require('packer').use

require('packer').startup(function()
  use 'tpope/vim-unimpaired'
  use({
    "ghillb/cybu.nvim",
    branch = "main", -- timely updates
    -- branch = "v1.x", -- won't receive breaking changes
    requires = { "kyazdani42/nvim-web-devicons", "nvim-lua/plenary.nvim"}, -- optional for icon support
    config = function()
      local ok, cybu = pcall(require, "cybu")
      if not ok then
        return
      end
      cybu.setup()
      vim.keymap.set("n", "[b", "<Plug>(CybuPrev)")
      vim.keymap.set("n", "]b", "<Plug>(CybuNext)")
      vim.keymap.set({"n", "v"}, "<c-s-tab>", "<plug>(CybuLastusedPrev)")
      vim.keymap.set({"n", "v"}, "<c-tab>", "<plug>(CybuLastusedNext)")
    end,
  })
end)
:Verbose nmap [b

n  [b            <Plug>(unimpaired-bprevious)
	Last set from ~/.local/share/nvim/site/pack/packer/start/vim-unimpaired/plugin/unimpaired.vim line 51

Support for grapple.nvim

It would be great to support grapple.nvim (alternative to Harpoon). This could be done by considering the grapple tags instead of open buffers. Additionally, it could be better to just allow the user to provide a function which returns a list of buffers in cybu's config (the default would be nvim's internal buffer list), so that grapple, harpoon and any other similar plugins can be integrated by the user in the config, instead of having specific integrations with each possible plugin.

The buffer becomes invalid when switching session

In my setup, I use neovim-session-manager to manage my session,When switching sessions, the buffer of buye becomes invalid.
The specific errors are shown below:

E5108: Error executing lua: vim/_editor.lua:0: nvim_exec2(): Vim:Error executing Lua callback: .../.local/share/AstroNvim/lazy/cybu.nvim/lua/cybu/init.lua:228: Invalid buffer id: 15
stack traceback:
	[C]: in function 'nvim_buf_set_lines'
	.../.local/share/AstroNvim/lazy/cybu.nvim/lua/cybu/init.lua:228: in function 'get_cybu_buf'
	.../.local/share/AstroNvim/lazy/cybu.nvim/lua/cybu/init.lua:376: in function 'populate_state'
	.../.local/share/AstroNvim/lazy/cybu.nvim/lua/cybu/init.lua:394: in function 'cycle'
	...bo/.local/share/AstroNvim/lazy/cybu.nvim/plugin/cybu.lua:13: in function <...bo/.local/share/AstroNvim/lazy/cybu.nvim/plugin/cybu.lua:12>
	[C]: in function 'nvim_exec2'
	vim/_editor.lua: in function 'cmd'
	/home/zibo/.config/astronvim/lua/user/lsp/mappings.lua:25: in function </home/zibo/.config/astronvim/lua/user/lsp/mappings.lua:23>
stack traceback:
	[C]: in function 'nvim_exec2'
	vim/_editor.lua: in function 'cmd'
	/home/zibo/.config/astronvim/lua/user/lsp/mappings.lua:25: in function </home/zibo/.config/astronvim/lua/user/lsp/mappings.lua:23>

I found that these changes fixed the issue for me:

diff --git a/lua/cybu/init.lua b/lua/cybu/init.lua
index 79a25c2..7af13a3 100644
--- a/lua/cybu/init.lua
+++ b/lua/cybu/init.lua
@@ -208,7 +208,7 @@ end

 cybu.get_cybu_buf = function()
   local cybu_buf
-  if not _state.cybu_buf then
+  if not _state.cybu_buf or not vim.api.nvim_buf_is_valid(_state.cybu_buf) then
     cybu_buf = vim.api.nvim_create_buf(false, true)
     vim.api.nvim_buf_set_option(cybu_buf, "filetype", "cybu")
     vim.api.nvim_buf_set_option(cybu_buf, "buftype", "nofile")

Question/feature request: change buffer on key release

Thanks for the really useful plugin, I've been enjoying it a lot! :)

Is it possible to switch to the buffer immediately after releasing all keys? I'm using the 'most recent' feature with the default keybinds ("J", "K"), which means I press shift+j/k to select the entry. What would be brilliant is if I could keep shift pressed while moving up/down the list with j/k. Once I have arrived at the desired entry, I release shift and cybu switches to the selected buffer. In this case the limited display_time would also not be needed, making things easier if you're having to hunt a bit for the relevant buffer name. Can this already be achieved? If not, would this be a feature you'd like to see in your plugin?

Thanks!

Exclude settings not being respected

I noticed that if I have a quickfix window open, then it will show up in the cycle list and then I won't be able to cycle out of that buffer when it's selected. I think that this is because the exclude settings are not being taken into account when populating the list of buffers to cycle through. I found that these changes fixed the issue for me:

diff --git a/lua/cybu/init.lua b/lua/cybu/init.lua
index 3a384be..f02ac14 100644
--- a/lua/cybu/init.lua
+++ b/lua/cybu/init.lua
@@ -30,6 +30,9 @@ cybu.get_bufs = function()
     if 1 ~= vim.fn.buflisted(id) then
       return false
     end
+    if vim.tbl_contains(c.opts.exclude, vim.fn.getbufvar(id, "&filetype")) then
+      return false
+    end
     return true
   end, vim.api.nvim_list_bufs())

Love the plugin btw 🙂

Handle unlisted buffers while Cybu window is open

👋🏼,

First off, I want to say thank you - I'm really loving this plugin!


In my setup, I use bufignore.nvim to unlist Git ignored buffers once they are hidden. However, I've encountered an issue with Cybu when I move through the entire list of buffers it provides. When it encounters an unlisted buffer, Cybu silently stops working, and I have to use bnext to move to another listed buffer.

This behavior can be easily replicated with the following steps:

  1. Open multiple buffers.
  2. Use vim.defer.fn to unlist one of the buffers with a delay of 1-2 seconds.
  3. Continuously cycle through the items in the Cybu window.
  4. Once it reaches the unlisted buffer, Cybu fails to go to the next buffer silently.

Feature request: option to control icon size

It would be great if you could add an option in the setup() to control the allowed maxsize of icons and shift the file_name to the right accordingly. Currently with the plenary truncate, 2col wide icons can get truncated to nothingness.

Great plugin, thanks a lot :)

Feature request: Add "touched" flag to last_used

This plugin is perfect for my worfklow, but there is one thing missing that I would love to see.

I would love to be able to change how the plugin determines if a file is "Used" for the buffer cycle next and prev commands

The problem

Given the following open buffers in order of recently used

file1 < open
file2
file3

I have been editting file1, and I now want to jump back and forth between file1 and file3 with a single cycle next.

In other words I want to have the following buffers

Desired worfklow

  1. Cycle next
file1
file2 < open
file3
  1. Cycle next
file1
file2
file3 < open
  1. Move my cursor in file 3
file3 < open
file1
file2
  1. Now I can Cycle next and jump back and forth between file1 and file3 as long as i want

As you can see this will only move the buffer to MRU if you have actually moved your cursor in that buffer.

The problem right now with how last_used and immediate works is that cybu considers a file to be "used" as soon as BufEnter is called. And obviously with immediate mode this happens for every file you cycle to.

So with this current setup, it will be impossible for me to get my buffers the way that I want.

Workaround

Using switch: on_close and tweaking the display_time but this is not ideal, as it doesn't feel as responsive to me.

Additional comments

This is kind of how iPhones work. If you swap between open apps, it will only consider the app you just opened to be the MRU if you actually did something on that app.

Disable popup while switching

I am struggling with customization. I want to switch between history without a popup window.
Is it possible? How I can achieve this?

PS For what is the auto mode?

Cycling through last x number of buffers

Bufstop plugin has a "speed" mode which lets user cycle through last specified number of buffers viewed, so I can do things like

  • use F2 to F12 keys to back-cycle through the specified number of buffers
  • tap <leader><leader> to cycle back and then <leader><leader> to cycle forward between the last 2 buffers
    without displaying a menu.

https://github.com/mihaifm/bufstop

This is fast and puts convenient limit on a list of buffers to cycle through when there are many open.
Any thoughts about implementing a similar approach in this plugin?

Feature request: be able to keep the buffers at the same place in the list

Hi, thank you for your plugin, it works very well.

When using it, I have some trouble to focus on the filenames, as they are always change when cycling through the list. For me at least, it would be more interesting to keep the names at the same position in the list, and change the position of the highlight instead.

I guess it would still have to keep the same behavior when the buffer list is longer than the window height.

Error executing lua vim/shared.lua:0: t: expected table, got nil

Just did a fresh install of Cybu.nvim on latest stable nvim 0.9.0

nnoremap <tab> <Plug>(CybuPrev)
nnoremap <S-tab> <Plug>(CybuNext)

Then I get this error:

E5108: Error executing lua vim/shared.lua:0: t: expected table, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_contains'
        ...r/.local/share/nvim/plugged/cybu.nvim/lua/cybu/utils.lua:87: in function 'is_filter_
active'
        ...er/.local/share/nvim/plugged/cybu.nvim/lua/cybu/init.lua:389: in function 'cycle'
        [string ":lua"]:1: in main chunk

docs: use `function() require('cybu').cycle('prev') end` instead of `<Plug>` for lazy-loading

The <Plug>… mappings look nicer, but they prevent the plugin from being lazy-loaded. By directly using function() require('cybu').cycle('prev') end instead, it is possible to lazy-load the plugin.

While I got those from searching the code base, I think it might make sense to replace <Plug>… everywhere with require…, so users can get the benefit of quicker loading.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.