How to resize split windows in Vim proportionally? - vim

Ok so first off, this is NOT the answer I'm looking for:
autocmd VimResized * :wincmd =
Let me explain: Let's assume I have 2 vertically split windows, one at 30% size and one at 70% size. When I resize my window, I want that percentage to stay the same. Without this command, the split on the right slowly collapses so that you eventually can't see anything in the window. With the command above, once you start resizing the window, the window sizes immediately change to 50%/50%.
I work with a lot of splits (vertical and horizontal) and I don't want the command above to just make everything equal, but at the same time I do want them to resize, just PROPORTIONALLY to the window... I want the percentage height/width of all splits in the window to stay the same when the window is resized. Ideas?

I've attempted to implement this in my ProportionalResize plugin, following basically the approach outlined in romainl's answer. You can wrap your resize commands in a :ProportionalResize wrapper; the plugin also hooks into various events to allow automatic adaptation when the Vim window is resized e.g. with the mouse.

if you are asking a "vim - official" way to do that, answer is NO. (Vim 7.3)
to prove it:
open vim, type :h todo<Enter>then type /proportionally[Enter] you will see:
- When resizing the whole Vim window, the windows inside should be resized
proportionally (Webb).
so it is in vim's todo list. In this window type gg, you can see the leading minus "-" means Priority classification:
- unclassified
If you want to do it, you could write a function by yourself, on VimResized event, resize all windows based on your logic.

You could create a function that logs window sizes and bind them to a bunch of events like WinEnter/WinLeave and another one bound to VimResized that uses those values to resize the windows.
This doesn't sound like a trivial task.
Or even like a good idea.

Related

vim >> rotate through all buffers opened in target split

Am used to IDE style tab'd panels and am hitting some arggghh inducing scenarios with vim when trying to replicate this functionality using buffers and splits.
I have the following relevant .vimrc settings:
set hidden
set switchbuf=useopen,usetab
Now, let's say I open up 4 buffers, split vertically and then horizontally so that 1 buffer displays on the left and 2 buffers display stacked on the right. The 4th buffer is hidden (opened on the left split).
With the cursor in the left split, using :bnext and :bprevious rotates through all buffers in the left split; that's not desirable as I really have no use for seeing the same file contents in 2 different splits (is there a way to opt-in to the vim cloned buffer affect?). Using :sbnext and :sbprevious works great for visible buffers, but as soon as a hidden buffer is encountered then it opens up in a new split thus wreaking havoc on my layout. The problem gets worse when working with 10+ buffers.
Ideally I'd like to rotate through all buffers visible and hidden within a given split (i.e. where the buffers were opened).
Suggestions appreciated.
p.s. am trying out vim ctrl-space plugin now, quite good but does not address above issue.
Thanks
Why rotate through the buffers when you can go directly to the one you want via :buffer command?
:b foo
:b take either a buffer number or a partial filename (with globs too!). I recommend the partial filename approach. You can also use tab completion to distinguish between ambiguous partial filenames.
You can use :sbuffer (:sb for short) the same way but to open a split instead.
For more help see:
:h :b
:h :sb
The basic navigation unit is the buffer. Windows and tab pages are abstractions built on top of buffers that introduce their own good and bad idiosyncrasies and, most of the time, don't play well with traditional buffers.
You are having troubles because you are trying to apply buffer commands to a window-centered workflow.
As soon as you split your workspace in more than one window you are bound to use window commands for navigation and tab-navigation becomes your standard as soon as you use tab pages. As you noticed, not only is it hard (impossible, AFAIK) to make buffer-navigation window/tab-aware but the alternative techniques actually lack quite a bit in terms of power.
The 4th buffer is hidden (opened on the left split).
That's your first problem: that 4th buffer is hidden and thus transient. It is not opened in any window and could be displayed in any window. You can choose to display a specific buffer in a specific window but you can't really "pin" it to that window.
With the cursor in the left split, using :bnext and :bprevious rotates through all buffers in the left split; that's not desirable as I really have no use for seeing the same file contents in 2 different splits (is there a way to opt-in to the vim cloned buffer affect?).
Again, you are using buffer commands that don't care at all about windows and tab pages.
Using :sbnext and :sbprevious works great for visible buffers, but as soon as a hidden buffer is encountered then it opens up in a new split thus wreaking havoc on my layout.
Again, the wrong tool for the job.
It is possible to keep as many window-local argument lists as you have windows and use those lists with :next and :previous, though, but that would require quite a bit of focus and forethinking. Maybe there's a plugin for that? Anyway:
Create your layout:
:vs|sp
Go back to the large window on the left:
<C-w>w
Put two files in the local argument list:
:arglocal aaa.txt bbb.txt
Move to the next window, edit your local argument list and repeat:
<C-w>w
:arglocal ccc.txt ddd.txt
<C-w>w
:arglocal eee.txt fff.txt
You can now do :next and :previous to switch arguments or <C-^> to switch to the alternate file.
Note that, while you were able to "force" somehow your buffers to specific windows, you are now seriously limited in your ability to navigate around and you now have to deal with a multi-dimensional construction that's rather fragile and requires to too many braincells.
You should consider working with Vim and not against it by using straight buffers as much as possible.
I'm using vim dwm plugin, and it is working very well for my workflow. I'm used to open a lot of buffers in the same window. With this plugin I can manage all of them with easy. I'm using vim-ctrlspace plugin too, and this two plugins are wonderful working together. Well, that's it. I hope this help!

VIM: disallow focusing a window

In VIM, I want to split a window in two parts where first one is the regular editor, and the second one is just read-only window for some auxiliary information.
The user should not be allowed to access (focus) the read-only window. Can I set that somehow?
set nomodifiable is helpful but it is not what I meant - I still can access the window.
Edit
I mean two independent buffers
Usually the preview window is used for auxiliary information, e.g. insert-mode completion can show additional information there. You can :pedit a scratch buffer, and show your information there.
I don't follow your requirement of not allowing to move into that window. That's not very Vim-like. You can disallow (accidental) editing with :setlocal nomodifiable, but why not allow the user to interact with the window?! (Some operations like resizing are way easier or only possible when you're inside the window.)
Alternative
If the amount of information is small and only needs to be displayed for a short time, and you're in GVIM, you can also use tooltip popups via 'balloonexpr'.
Do you mean two (or more) windows using same buffer? In that case I think that modifiable wouldn't be an option because it wouldn't let you change the data from any window.
You could try to use the WimEnter autocommand to come back to the previous window.
autocmd WinEnter * exe "normal \<c-w>\<c-p>"

Opening :help into an existing window/split

I currently have my terminal running in full screen, with three nice large vertical splits in it. The leftmost is running NERDTree, so I don't really need the full height. I'd like to split that column horizontally and put help in the new frame, but when I :help, it creates a large horizontal split across the entire screen. I know I can technically set this up the way I want before I make my vertical splits, but I tend to not think about opening help until I'm well into my workflow.
So is it possible to have help only split the existing window, or open into the current buffer?
The answer (works for me) is:
:above help
Note that it already has the same behaviour if you were in the rightmost column.
See also :help vert, :help above etc. for all kinds of variations (rightbelow etc.)

Changing the VIM/GVIM message window behavior

When I type :!ls, for example, and see the result, it shifts up the current window to make space for it.
I've been annoyed by how the whole content moves up and down. I'm wondering if there's a way to fix that in either vim or gvim 7.3 - like in Emacs.
So for example, if I have lines 1~30, and the message area takes up 5 lines, I want my code window to show lines 1~25 instead of 6~30. That's what Emacs does, I think.
Thanks.
As far as I am aware, this is not possible in vim. However, there are ways to get around it. You can use screen or tmux and use that to create a lower window to execute commands in. You can also take a look into conque, which simulates a terminal within vim.

An alternative to minibufexplorer (vim)?

minibufexplorer is a persistent buffer manager for vim that lives in its own window. It shows all the buffers you have open, with color indicators as to which are currently visible in windows and which have unsaved changes.
It's a great plugin which I've been hooked on forever. And without the persistent buffer display I find that I now feel lost.
The problem is, minibufexpl tends to get in the way of other window controls. As it is a normal vim window, it behaves like one, causing issues if you wanted to say, rotate your other working windows. Minibufexplorer's window would rotate as well, which is obviously less than desirable.
What I really need is a plugin that persistently displays the open buffers, but doesn't behave like a window. I don't need file navigation or anything as I use other means for that. Perhaps even something like an extended status bar that was capable of displaying information on buffers like minibufexpl does?
There's a new fork of minibufexpl.vim on GitHub which aims to solve some of these problems. One of its new features is "Prevents resizing of MBE buffer by window resizing commands" and it is immune to commands such as C-WC-R (rotate windows).
https://github.com/fholgado/minibufexpl.vim
While this is not an exact answer to your question, I think you could find it useful.
FuzzyFinder plugin provides good visual representation of your open buffers,
and also offers great way to jump between them - fuzzy match.
Its list of buffers is not "persistent" meaning it's only shown on
demand, but I consider this an advantage: firstly the buffers list doesn't eat
up precious screen estate, and secondly with fuzzy match I don't feel a
need to see it at all.
Consider the below screenshot: in order to switch to ext_gcd.py I just need to press
,bg : ,b invokes buffers list and g fuzzy-matches the only buffer
whose name contains letter g.
P.S: it works with files too. My mappings are as follows:
map <leader>f :FufFileWithCurrentBufferDir **/<C-M>
map <leader>b :FufBuffer<C-M>
,f in this case recursively fuzzy-matches files starting from a directory where current buffer is placed.
Old thread, but for anyone else searching checkout the vim-airline plugin. It's very popular and has great compatibility with other plugins.
Use the g:airline#extensions#bufferline#enabled option to get what your looking for.
I really enjoy buftabs.vim because it keeps the information about which buffers I have open in the status line, which disappear when I need to type there in a nice clear manner. I find this quite preferable to minibufexplorer because my cursor never accidentally ends up in a read-only scratch buffer which takes up more space than necessary. It also does some magic-mapping of :bnext and :blast to allow hopping between buffers for a rather more "familiar" feeling.
You can use ctrlp, a plugin written in pure Vimscript and highly configurable.
:CtrlPBuffer open a window with the list of open buffers
you can begin to type, it is a fuzzy finder.
There is also Tagma Buffer Manager. I am not using it yet, but someday I will give it a try, for sure.
You can try Powerline's tabline!
I tried many plugins but they tend to take up the command line or the status line, or won't show up the whole tabs when there're too many of them.
Here is a screen shot (the top bar is the tabline!):
You need to add set showtabline=2 in .vimrc after install Powerline.
And if you want to go to the 8th buffer, :b 8 will jump to it!
Hope this helps.

Resources