GithubHelp home page GithubHelp logo

el-iot / buffer-tree-explorer Goto Github PK

View Code? Open in Web Editor NEW
21.0 1.0 4.0 1.89 MB

A simple vim-plugin for rendering your open buffers into an interactive ascii-tree to allow for easy navigation / management.

License: Other

Vim Script 100.00%
vim-buffers buffer-tree ascii-tree vim-plugin

buffer-tree-explorer's Introduction

                                                 &&& &&  & &&
                                              && &\/&\|& ()|/ @, &&
                                             &\/(/&/&||/& /_/)_&/_&
 ╔╗ ┬ ┬┌─┐┌─┐┌─┐┬─┐╔╦╗┬─┐┌─┐┌─┐            &() &\/&|()|/&\/ '%" & ()
 ╠╩╗│ │├┤ ├┤ ├┤ ├┬┘ ║ ├┬┘├┤ ├┤            &_\_&&_\ |& |&&/&__%_/_& &&
 ╚═╝└─┘└  └  └─┘┴└─ ╩ ┴└─└─┘└─┘         &&   && & &| &| /& & % ()& /&&
         ╔═╗─┐ ┬┌─┐┬  ┌─┐┬─┐┌─┐┬─┐        ()&_---()&\&\|&&-&&--%---()~
         ║╣ ┌┴┬┘├─┘│  │ │├┬┘├┤ ├┬┘               && \|||
         ╚═╝┴ └─┴  ┴─┘└─┘┴└─└─┘┴└─                   |||
                                                     |||
                                                     |||
                                               , -=-~  .-^- _

buffer-tree-explorer

A vim-plugin for exploring vim-buffers, rendered as an ascii-tree. An adaptation / extension of the buffer-tree vim plugin.

Why?

I recently wrote a vim-plugin (buffer-tree) that renders your vim-buffers as an ascii tree. While I liked the plugin, I found its lack of persistence made it difficult to use (it was only rendered in the echo area). This plugin will instead create a persistent buffer which displays your existing buffers and makes navigating easier.

Given a list of buffers,

:buffers
 22  h   "~/media/videos/video.html"    line 4
 26  h   "autoload/explorer.vim"        line 14
 27  h   "autoload/tree.vim"            line 1
 29  h   "autoload/buffer.vim"          line 15
 74  h   "~/personal/machine-learning/btc/data.csv" line 3141
 75 #h   "~/personal/advent-of-code/2020/day_1.py" line 1
 76 %a   "README.md"                    line 72

BufferTreeExplorer will create a buffer with an ascii-tree that can be used to view the existing buffers. Note that this tree cannot be used to open new files in new vim-buffers.

:Tree
└─ home/el
   ├─ .config/nvim/plugged/buffer-tree-explorer
   │  ├─ ◎ README.md ⇒ 76
   │  └─ autoload
   │     ├─ • buffer.vim ⇒ 29
   │     ├─ • tree.vim ⇒ 27
   │     └─ • explorer.vim ⇒ 26
   ├─ personal
   │  ├─ • machine-learning/btc/data.csv ⇒ 74
   │  └─ • advent-of-code/2020/day_1.py ⇒ 75
   └─ • media/videos/video.html ⇒ 22

Note that the numbers after the arrow next to each file represent the buffer numbers of each file.

Within this buffer you can use the k and j keys to scroll up and down respectively through the available buffers, as well as press <CR> to enter that buffer.

Installation

Add this line to your init.vim / .vimrc file (though you may need to modify it slightly if you use a different plugin manager.

Plug 'el-iot/buffer-tree-explorer'

and run

:PlugInstall

Usage

Use the :Tree command to render your buffers as an ascii-tree in a separate "tree buffer". While navigating within this buffer you can use the j and k keys to scroll up and down through the available buffers, Enter to open this buffer and delete to delete a given buffer a refresh your tree.

Configuration

Compressing the BufferTree

Sometimes your buffers will be very sparse and the buffer-tree will look a little large for so few files. As an example,
└─ home
   └─ el
      ├─ personal
      │  ├─ vim
      │  │  └─ buffer-tree
      │  │     ├─ README.md ⇒ 2
      │  │     └─ plugin
      │  │        └─ buffer-tree.vim ⇒ 3
      │  └─ repos
      │     └─ themerator
      │        └─ themerator.py ⇒ 14
      └─ .config
         └─ nvim
            ├─ plugged
            │  ├─ buffer-tree
            │  │  └─ plugin
            │  │     └─ buffer-tree.vim ⇒ 4
            │  └─ buffer-minimalism
            │     └─ plugin
            │        └─ buffer-minimalism.vim ⇒ 10
            └─ init.vim ⇒ 1

This is a little inconvenient, as a lot of vertical space is taken up by directories with no buffers. You can set g:buffer_tree_explorer_compress to 1 to "compress" your trees where possible. In this case, the tree above would look like

└─ home/el
   ├─ .config/nvim
   │  ├─ plugged
   │  │  ├─ buffer-minimalism/plugin/buffer-minimalism.vim ⇒ 10
   │  │  └─ buffer-tree/plugin/buffer-tree.vim ⇒ 4
   │  └─ init.vim ⇒ 1
   └─ personal
      ├─ repos/themerator/themerator.py ⇒ 14
      └─ vim/buffer-tree
         ├─ README.md ⇒ 2
         └─ plugin/buffer-tree.vim ⇒ 3

Closing the tree after selecting a buffer

By default, You can configure buffertree-explorer to close on selecting a buffer (with <enter>) by setting the g:buffertree_close_on_enter to 1.

buffer-tree-explorer's People

Contributors

el-iot avatar iboard avatar

Stargazers

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

Watchers

 avatar

buffer-tree-explorer's Issues

Set width of explorer to a maximum width and allow to shrink down depending on length of paths

Currently you're using vnew which is fine but it takes up half the available screen space. I think it could be more intelligent and create a new buffer from the width of the open buffers.

For example if my open buffer is:

└─ home
   └─ joe.reynolds
      └─ code
         └─ helloHeaps
            └─ 7-scrolling-camera
               ├─ ◎ Main.hx ⇒ 1
               ├─ • 50 ⇒ 8
               └─ • Player.hx ⇒ 5

Then really, the width should be the longest line on this buffer (I think 34).
It'd make sense to constrain this too so you don't get ridiculously small or big buffers.

Just a thought

More layout options like floating window

  • It would be amazing if there could be floating window support for this plugin.
  • It would be even better if the user can provide his own layout command(similar to fzf_layout), along with a way to give dimensions for the layout like width/height or both in case of floating windows
  • Its more convenient if we can have an additional mapping in buffer tree to close the explorer buffer like escape or q

Feature Request: Close BufferTree window on select

I would like to have the BufferTree window close when I select a buffer. Ideally, this would behavior would be controllable with a flag.

For example NERDTree enables this behavior with the NERDTreeQuitOnOpen flag.

Lacking this, buffer-tree-explorer isn't a viable replacement for bufexplorer for my workflow.

Love the plugin, though! I'm working on a work-around for this, but I would still like to see this functionality supported in the plugin.

Expose API for extensions

I recently came across this plugin, and wonder if you can create/expose two functions for users?

function inputfilelist: Instead of loading buffer list, it will load the list of paths user provides. This way users can write their custom extensions using this your codebase, perhaps even other plugins.

function pathundercursor: When called, this will return the path under the cursor in the buffer tree explorer buffer.

As a sidenote, you could probably source the navigation code from https://github.com/mhinz/vim-tree, it has a navigation feature that keeps the cursor on the first character of directory/file name.

Plug repository leads to a 404

Plug 'el-iot/buffer-tree-explorer.vim'

  • when executing :PlugInstall it errors with a 404 repository not found
  • just remove the .vim extension and it works fine
  • Have a good day ! 😃

Error when switch windows back to :Tree buffer

if I split windows, and then trick to <C+w>h back left to the TreeBuffer view, I get the following error at the bottom of vim

Error detected while processing WinEnter Autocommands for "BufferTree"..function RefreshBuffer:
line    3:
E475: Invalid argument: -1

However it does seem to go back to the buffer fine. vim 8.2 on mac.

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.