r/vim • • Feb 22 '20

Lens.vim: A Vim Automatic Window Resizing Plugin

662 Upvotes

48 comments sorted by

51

u/metanat Feb 22 '20

You can find the plugin at camspiers/lens.vim. The idea behind this plugin is to resize windows (on enter) to a minimal viewport that allows you to see meaningful content if the current size of the window is too small. This is the first plugin I've written that (optionally) integrates with the animate.vim library for window animation, and so provides an example of how other plugin might do that too.

10

u/Jdj8af Feb 22 '20

Wow I didnt know about animate.vim, this is awesome!! Thank you for contributing!

1

u/Easy-Dima Feb 25 '20

I've written the similar thing for Neovim
Today I realized that there are bunch of such plugins)

19

u/mrpossible1320 Feb 22 '20

cool, is there any similar thing for tmux? normally I would prefer opening 4 tmux panes than 4 vim panes.

2

u/metanat Feb 22 '20

I've thought about the same because I use tmux a lot, but I haven't developed anything yet, and haven't come across anything in my travels.

22

u/akoustikal Feb 22 '20

Really? To each their own, but I can’t imagine tmux panes as a substitute for vim windows. You lose auto-completion and context switching, which are part of the reason I love vim. That said, animated tux window management sounds awesome.

1

u/grep_Name Feb 22 '20

lose auto-completion and context switching

I don't currently use auto completion, but does it really work per window?

Also, you should check out https://github.com/christoomey/vim-tmux-navigator to avoid the context switching problem, it basically lets you switch between vim/tmux panes seamlessly with one set of bindings.

I will say that I use vim windows whenever possible though. My great unsolved problem with replacing vim splits with tmux windows is my vim windows then having different buffer lists. That bugs the crap out of me

3

u/scholeszz Feb 22 '20

And different clipboards, jump lists, marks etc. I personally would be annoyed to hell within the first 30 minutes, but to each their own.

1

u/x_ero 0xAC1D0000 Feb 22 '20

i agree a tmux split with two vim sessions are not the best. but it happens to me sometimes, but more often its another tmux workspace/tab that gets a second instance of vim open in it.

i use these three plugins in tandem to unify tmux and vim movements, splits, resizes and their clipboards with my system wide one.

check out my dotfiles for more

-2

u/MichelleObamasPenis Feb 22 '20 edited Feb 22 '20

What? Your link to your dotfiles is "https://git.io/.vim" which forwards to your github page

   https://github.com/xero/dotfiles/tree/master/vim

What's with that?

I turned all reddit scripting AND CSS off (uuugly), and still its "https://git.io/.vim".

I am just presuming that you don't own the git.io domain.

2

u/hupfdule Feb 23 '20

Go to http://git.io and you will know.

1

u/[deleted] Feb 22 '20

I’ll use tmux panes for separate projects, like if I’m building one thing and referencing something else. It keeps the buffers nice and tidy.

Also, I just can’t get used to the Vim terminal

2

u/tassulin Feb 22 '20

Damn this was something that I always needed but never knew. There should also be a toggle that can disable this function easily if needed.

1

u/metanat Feb 23 '20

You can now run lens#toggle() to disable

1

u/tassulin Feb 25 '20

Hi! Thanks this plugin is awesome. Especially with the animatino. Yet I havent figured out how to run the toggle command.

I tried

:lens#toggle()

as vim command but its just giving me that its not editor command.

1

u/metanat Feb 25 '20

:call lens#toggle()

1

u/metanat Feb 22 '20

Thanks for the suggestion! You can set let g:lens#disabled = 1, but it would be nice to provide a toggle function too.

2

u/razieltakato Feb 22 '20

Just installed, and I love it!

How do you make the selected window darker?

23

u/djrollins Feb 22 '20

I'm surprised to see that winheight and winwidth aren't mentioned here.

I have the following in $MYVIMRC and get very similar behaviour, albeit without the animation.

set winwidth=79
set winheight=50

Does this having anything else over those two settings than animate.vim integration?

2

u/dddbbb FastFold made vim fast again Feb 24 '20

I've skimmed past those options many times and never looked close enough to realize what they do. Thanks!

2

u/worldpotato1 Feb 22 '20

Does it work good with nerdtree?

1

u/aaron__ireland Feb 22 '20

It works well with NerdTree, it makes the NerdTree window a bit larger than I am used to, but all the other windows slide very nicely to accommodate!

1

u/metanat Feb 23 '20

I've added the ability to disable the behavior for certain filetypes:

I don't use nerdtree but something like this should work:

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

1

u/ShortVodka Feb 24 '20

Firstly this plugin is great! I've always wanted something like it but didn't even know how to describe it.

I have the same issue with nerdtree and Gundo that end up all over the place when toggling. I tried the disabled file types but it doesn't seem to work in some cases.

Also, it would be really nice if when a window is closed it resizes them all to fit better. If a window is opened that squishes them down, then you close one, you end up with a very big window and a squished one until you switch over to it.

Again, really awesome work :)

7

u/starwarsholidayspeci Feb 22 '20

Just what I always wanted but never knew!

6

u/XCapitan_1 Feb 22 '20

I'll try it. My display is just a bit too small for three vertical panes.

3

u/[deleted] Feb 22 '20

awesome! love it

3

u/[deleted] Feb 22 '20

this is gold, just checked it out, works flawlessly

3

u/onlyanegg_ Feb 22 '20

This looks cool. I'd like something like <cntl>-z in tmux that expands the current split so that I can focus on it and is a toggle button, so that when I press it again the splits go back to where they used to be. Do you think that's something that could go into lens.vim or animate.vim? Or is there some other plugin that handles this?

3

u/emersonmx Feb 22 '20

So satisfying! *moving between windows like a hell*

A while ago I made a crappy automatic window resizing plugin...I guess it's time to change.

1

u/StingyKarmaWhore Feb 22 '20

What screen recorder are you using?

3

u/metanat Feb 22 '20

For the reddit video I just used the builtin macos one, and for the GIF on github I used Kap.app

2

u/StingyKarmaWhore Feb 22 '20

I did not notice you were on a mac. whoopsies

1

u/pwnedary Feb 22 '20

How does this compare to GoldenView.vim?

1

u/metanat Feb 22 '20

I'd have to play around with goldenview to find out, but thanks for the mention of it because I didn't know it existed!

3

u/lowpass Feb 22 '20

1

u/thrallsius Feb 23 '20

took me a while to get used to it, but once it happened - I never resized windows manually anymore

great concept, if I had to run vim with just one plugin, this one would be a strong contender

4

u/GustapheOfficial Feb 22 '20

What's that white thing moving around on your screen?

0

u/[deleted] Feb 22 '20

[deleted]

2

u/GustapheOfficial Feb 22 '20

I guess, but it seems to be moving a lot.

0

u/[deleted] Feb 22 '20

[deleted]

2

u/GustapheOfficial Feb 22 '20

But how do you move your cursor without leaving the home row?

0

u/[deleted] Feb 22 '20

[deleted]

2

u/GustapheOfficial Feb 22 '20

I'm trying to think of a way to express that we're thinking of different cursors without breaking my facetious air of mock ignorance, but alas.

1

u/Probotect0r Feb 22 '20

Very neat and useful, thanks.

1

u/[deleted] Feb 24 '20

What theme is used in the video? :)

1

u/techannonfolder Feb 22 '20

Difference between this and golden view?

0

u/[deleted] Feb 22 '20

[deleted]

11

u/metanat Feb 22 '20

Done :)