GithubHelp home page GithubHelp logo

lens.vim's Introduction

██╗     ███████╗███╗   ██╗███████╗  ██╗   ██╗██╗███╗   ███╗
██║     ██╔════╝████╗  ██║██╔════╝  ██║   ██║██║████╗ ████║
██║     █████╗  ██╔██╗ ██║███████╗  ██║   ██║██║██╔████╔██║
██║     ██╔══╝  ██║╚██╗██║╚════██║  ╚██╗ ██╔╝██║██║╚██╔╝██║
███████╗███████╗██║ ╚████║███████║██╗╚████╔╝ ██║██║ ╚═╝ ██║
╚══════╝╚══════╝╚═╝  ╚═══╝╚══════╝╚═╝ ╚═══╝  ╚═╝╚═╝     ╚═╝

Lens.vim

A Vim Automatic Window Resizing Plugin

Lens.vim automatically resizes windows when their content exceeds their window dimensions, but does so respecting some minimum and maximum resize bounds ensuring automatically resized windows neither become too large (in cases of large content) or too small (in cases of small content).

Demo

Lens

Animation

Lens.vim by default integrates with the camspiers/animate.vim plugin for window animation.

Installation

To install Lens.vim, use your plugin manager of choice, for example

With Animation

Plug 'camspiers/animate.vim'
Plug 'camspiers/lens.vim'

Without Animation

Plug 'camspiers/lens.vim'

Usage

Out of the box Lens.vim it set up to resize windows when they are entered, and as such the minimal usecase is covered. However this can be disabled and resizing can be preformed manually using lens#run().

Options

Lens.vim is set up with some sensible defaults, but if needed the following can be configured:

Disabled

The plugin can be disabled completely with:

let g:lens#disabled = 1

Disabled Filetypes

The plugin can be disabled for specific filetypes:

let g:lens#disabled_filetypes = ['nerdtree', 'fzf']

Animate

Animation is enabled by default, but can be disabled with:

let g:lens#animate = 0

Resize Max Height

When resizing don't go beyond the following height

let g:lens#height_resize_max = 20

Resize Min Height

When resizing don't go below the following height

let g:lens#height_resize_min = 5

Resize Max Width

When resizing don't go beyond the following width

let g:lens#width_resize_max = 80

Resize Min Width

When resizing don't go below the following width

let g:lens#width_resize_min = 20

API

Lens.vim provides the following functions:

Run

Resizes the window to respect minimal lens configuration

function! lens#run() abort

Toggle

Toggles the plugin on and off

function! lens#toggle() abort

Get Size

When current is smaller than target, returns target if target is within bounds otherwise returns a value closest to target within bounds.

function! lens#get_size(current, target, resize_min, resize_max) abort

Get Rows

Gets the rows of the current window

function! lens#get_rows() abort

Get Cols

Gets the cols of the current window

function! lens#get_cols() abort

lens.vim's People

Contributors

camspiers avatar ipod825 avatar kovetskiy avatar pablo1107 avatar sqrtminusone avatar teu5us avatar whoissethdaniel 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

lens.vim's Issues

Resize prefers the right side

Apparently, the resize in vim first increases the size to right, and tries to increase size to the left only if there isn't enough space to the right. So, if number of splits is greater than 2, the behavior is as follows:
ezgif.com-video-to-gifdfd0ca7d13ad1504.gif

The leftmost split is untouched and all the resizing is happening between the last 2. #2 is clearly the result of this as well.

Setting winminwidth helps, but not much. Perhaps, there is a way to resize a window in both sides?

there is no min width for vert splits > 2

Although I can see :echo g:lens_width_resize_min == 20

vim version: latest nightly (gvim and vim cmd)
OS: win 10

lens-vim2

lens-vim

PS, actually for horizontal splits there is the same issue.

lens.vim stretches windows opened via FZF

When you open a new vertically split window through FZF, lens.vim stretches that window to maximal allowed width.

I've created a minimal example at https://github.com/gregorias/lens.vim-fzf-issue that reproduces this issue. I've also recorded an example.

The expected behavior would be for lens.vim to open the new window in an equal vertical split (or just not resize the window).

The reason why this happens is that two WinEnter events happen when FZF does a split. During the first enter (i.e., FZF just returns to the original window), the target window is at full width and lens.vim starts animating. Then FZF opens a new window, and, when the second WinEnter happens, the target window has the proper width (equally split across both windows) but the started animation prevents lens.vim from adjusting (there's an explicit if: https://github.com/camspiers/lens.vim/blob/master/plugin/lens.vim#L132).

netrw issue

The disable lens via filetype is not working on netrw

I already set it up on my vimrc
Screenshot 2020-03-08 at 5 58 50 PM

If I disable lens and run netrw, it behave according to the size I specified
Btw, I'm not using animate.vim

Window width behaves unexpectedly with line numbers turned on

Without line numbers, lens.vim scales the window to 80 characters (as shown by my grey vertical bar)

image

With line numbers turned on, I can't see all 80 characters anymore (i.e. can't seen grey vertical bar)
image

If I do a :echo lens#get_cols() it returns 80, so I am guessing that the resizing doesn't account for the line number columns. Is this the intended behaviour? If so, is there a way to configure lens.vim so that it behaves the way I described?

Unable to exclude defx from lens

Lens tries to resize defx even when listed in disabled_filetypes

I'm using vim 8.2 patch 1-148
Here is a minimal vimrc to reproduce

autocmd!

call plug#begin('~/.vim/plugged')
filetype plugin indent on

if has('nvim')
  Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }
else
  Plug 'Shougo/defx.nvim'
  Plug 'roxma/nvim-yarp'
  Plug 'roxma/vim-hug-neovim-rpc'   
endif
Plug 'camspiers/animate.vim'
Plug 'camspiers/lens.vim'
call plug#end()

noremap <silent> <F3> :Defx -toggle<CR>

" =====================
" defx
" =====================
" Set appearance
call defx#custom#option('_', {
  \ 'winwidth': 35,
  \ 'split': 'vertical',
  \ 'direction': 'topleft',
  \ 'show_ignored_files': 0,
  \ 'buffer_name': 'defxplorer',
  \ 'columns': 'icon:indent:icons:filename',
  \ 'resume': 1,
  \ })

" =====================
" lens
" =====================
let g:lens#disabled = 0
let g:lens#animate = 1
let g:lens#disabled_filetypes = ['defx', 'nerdtree', 'fzf', 'defxplorer']

Start vim and hit F3, straight away defx is resized beyond the defined 35
set let g:lens#disabled = 1 and defx behaves as expected

When defx is loaded, running :set ft reports filetype=defx

Is this a lens issue or defx? any chance of a work around?

Is it really working with nerd tree?

It doesn't work with my setup, not sure what I'm doing wrong, but adding the plugging makes the nerdtree explorer to resize to a huge width the first time its opened. I've tried doing:

let g:lens#disabled_filetypes = ['nerdtree', 'fzf']

But doesn't change anything

Issue when using lens.vim, animate.vim, vim-peekaboo

To reproduce:

call plug#begin()
Plug 'https://github.com/junegunn/vim-peekaboo'
Plug 'https://github.com/camspiers/lens.vim'
Plug 'https://github.com/camspiers/animate.vim'
call plug#end()
  1. Start vim/nvim
  2. Open a file
  3. :split
  4. <c-w>j
  5. "
  6. <Esc>

What happens

The focus is on the top split while initially it was on the bottom one.

If animate.vim is disabled, then the above does not happen.

Problem resizing in terminal mode

The plugin works perfectly until I try opening a terminal in neovim. It doesn't seem to resize automatically but does what is expected for files. Just wondering whether the plugin works for terminal mode or not.

I like it, but...

Would it be possible to add an option to respect textwidth instead of file content?

Resize prefers the right side without animate.vim

#6 reported that the leftmost split is often left untouched when resizing vertical splits with animate.vim. That issue was fixed upstream. The behavior persists, however, when using lens.vim to handle resizing.

Ideally (at least for me) the active window would be resized as configured with other splits being distributed evenly (see: #6 (comment)).

duplicated help tag g:lens#animate

when generating the helptags, I get

       > E154: Duplicate tag "g:lens#animate" in file /nix/store/9waanx9l6g6a0rskm9anyxnbmm86mw7w-vimplugin-lens.vim-2021-05-30/./doc/lens.txtFailed to build help tags!

Animation doesn't work with fugitive

When I try to create a commit in fugitive, the animation changes the default behaviour. Previously, when I use :G to bring up the status page (which is opened in a horizontal split), stage some files, and use cc to create a commit (which creates an editor in a horizontal split) and the focus is brought to the editor. When I have animation turned on, (i.e. let g:lens#animate = 1), the focus doens't jump to the editor split, and instead stays inside the status split, and the status split is zoomed in. However, when animation is turned off, the behaviour goes back to normal. I know that you can turn the animation off for certain filetypes, but in this case I don't want to do that. Is there anything else I can do to resolve the problem? Thanks!

[Suggestion] Toggle

Suggestion for future. A toggle to enable/disable would be nice as sometimes we need the windows to be static.
Love this plugins
Thank you!

Option to keep nearby buffers big as well

Hey, thanks for this awesome plugin.
I use side by side files a lot so this I thought comes in handy.

I mainly have multiple files side-by-side so I can check the other files when writing into one file.

The way lens currently works seems to minify the nearby neeighbours once I switch from them which is the exact opposite of what I need.

Here is a screen of what I was hoping lens could do for me.
Screenshot from 2020-03-02 10-39-26

You're likely busy so I'm posting this hoping it would find a few more people like me who want this.

Also I'm happy to buy you a coffee as this will likely increase my productivity.

Btw I am using it without animate (not sure if that affects things).

Animations not working all the time

Hi. i test your plugin with neovim(v0.4.3 ).
i realized that sometimes, the animations not working properly and i should explicitly call:
:call lens#run()

Sugestions for coc-ecxplorer

I have installed coc-explorer like other option by NerdTree, but inthe configuration of lens the option "let g:lens#disabled_filetypes = ['explorer', 'fzf']" don't work.

I tried with coc, Coc, coc-explorer and CoC-Explorer.

it also does not work for voomtree side panel.

it also does not work for voomtree side panel.
https://github.com/vim-voom/VOoM

when you generate voomtree panel, it is extended he width unexpectedly.
then you manually squeeze the width back. from now it won't be extended anymore, which is good.
but then everytime you toggle the voomtree panel, it will be extended again. very annoying.

my vimrc:

let g:lens#width_resize_max = 80
"let g:lens#disabled = 1
let g:lens#animate = 0
let g:lens#disabled_filetypes = ['nerdtree', 'fzf', 'voomtree', 'vim-plug']

this plugin is super and useful since I'm a buffer split lover. but I'm also a Voom user and can't live without it. so this issue is a stopper for me. have to uninstall it for now...

btw nerdtree work fine after I disabled animate.

does it work with iterm2?

ive installed the plugins for lens and animate. and i have opened serveral window panes with iterm2 commands to split windows etc. not auto resizing though.

width_resize_max not respection width_resize_min?

Hi,
I set let g:lens#width_resize_max = 999 - which should basically mean take as much space as you need. But I also set let g:lens#width_resize_min = 80 which shouldn't let any window go below that value. But if I have wide buffer it just takes whole vim space. Am I missunderstanding behavior of the plugin?

Thanks,
Vjekoslav

lens.vim doesn't always seem to respect the width of help page

Hi! lens.vim doesn't seem to always respect the width of a vertical help page.

My .vimrc:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'camspiers/lens.vim'
call vundle#end()

To reproduce open a couple of vertical splits and then do vertical help help so that the help window gets less than 78 characters wide. Even if I do <C-w><C-w> <C-w><C-w> (jump out of and into the help window) the width of the help page is sometimes still less than 78 characters (sometimes I have to move around in one of the windows for the bug to appear).

Problme with resizing with terminals

The plugging works perfectly until I try opening a terminal in neovim. It doesn't seem to resize automatically but does what is expected for files.

Can we make the XXX_resize_max proportional to the terminal size

Hi,

lens is realy a great plugin that saves me a lot of time.
It works as what I expected most of the time.

Can lens make the XXX_resize_max proportional to the terminal size?

For example, adjust the XXX_resize_max everytime when the terminal size changes.

let g:lens#height_resize_max = winheight('%') / 4 * 3
let g:lens#width_resize_max = winwidth('%') / 4 * 3

Thanks!

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.