Vim window resizing - vim

I split my windows in Vim horizontally. But after I split, the new window occupies half of the original window size, I want to change this and make sure the new window occupies almost the entire old window.
Basically if I open three files using horizontal split in Vim, I should see three status bars at the bottom of the screen the third file occupying the rest of the screen. The files as I already know can be navigated through Ctrl+W+arrow keys. So if I navigate to second file now, I should see one status bar at the bottom and one status bar at the top.
Kindly let me know how to configure the same. I looked up online all I could find is options to dynamically change the size or resize, but I want static one-time config (for example, in vimrc or bashrc).

If you set the winheight option to 999, the current window occupies as much of the screen as possible, and all other windows occupy only one line (I have seen this called "Rolodex mode"):
set winheight=999

You can type in command mode :res[ize] +N or :res[ize] -N where N is the amount in which your window will grow or shrink respectively.
Go to point 6 (Window resizing) http://vimdoc.sourceforge.net/htmldoc/windows.html but the article has everything on windows management in VIM
Hope this helps!

You might prefer just using vim tabs, which work rather like how you described.
Try this:
vim -p file1 file2 file3
Then use :tabn and :tabp to cycle fwd and back through the tabs.
I also like this mapping in .vimrc to use ctrl-l and ctrl-h to cycle fwd and back respectively:
noremap <C-h> :tabp<CR>
noremap <C-l> :tabn<CR>

Command for split window:
:[N]sp[lit] [++opt] [+cmd]
Where N is height of new window. Default is to use for half the height current window. Same thing for vertcal splitting:
:[N]vsp[lit] [++opt] [+cmd]
N is width for split window.
And so on:
[N]new, [N]vnew
For details read the
:help split
But I can't understand why you do not use buffers?

Related

Set Vim window size and selection from command line

I want to launch two files from the command line and I want the window to be split horizontally. This can be achieved with the following command:
vim -o index.html index.1
Which gives me the following output split evenly
What I want, instead, is for the top window to be substantially larger, like so
How do I achieve this? Also, currently, the top window is selected, which is what I want. However, if it wasn't selected, or I wanted the bottom window selected, how would I go about achieving this?
You can open the two files with
vim index.html +10sp index.1
After vim has read index.html it executes the ex command 10sp. That means that the current window is split into two with the new window being 10 rows high. After that index.1 is read by vim and loaded into the currently active window.
If you already set splitbelow in your .vimrc index.1 is loaded into the bottom window that is active at the same time.
For example if you want the top window to be active and splitbelow is set you can append the corresponding ex command to the line
vim index.html +10sp index.1 +"wincmd k"
One possible solution would be to make the top window 80% of the available size:
vim +'execute "resize" (&lines / 10) * 8' -o file1 file2
See :help :resize and :help 'lines' for more information.
Small clarification: & is used in front of options to retrieve its value. Thus &lines holds the value of what you could set yourself, e.g.:set lines=100. In this case, &lines gets set by Vim on-the-fly even when you resize the window that holds Vim.

Vim, split window have only 1-line-size

I have the problem with splitting windows. If I open a file with :split the size of the new window includes only one line. I don't know why.
Is there a way to resize the window in vim as I need it?
jump into the window you want to resize (ctrl-w ctrl-w OR ctrl-w direction-arrow), then hit ctrl-w followed by [number followed by] + (or - if you want to decrease the size)
the number is optional and indicates how many "units" you want to enlarge the window by, defaults to 1 if not specified
Or just hit ^W= to make all windows roughly same-size.
Also, :se mouse+=a should enable you to just drag the dividers with the mouse, even on terminal emulators across a GNU screen session.

in VIM, How to set the initial window size via file browser?

I'm using vim to browse through different folders. (i.e., issue :tabe . command in vim)
However, when I open the file either in split window (pressing 'o') or in vertical split window(pressing 'v'), the newly opened window size is really small. (while meanwhile, vim's file browser's windows stays pretty big which I don't really need).
I know that I can manually change the window size by Ctrl+W with either -/+ or split, or for vertical split, or '=' to make the window sizes equal; but that's too troublesome.
I want to check if there're existing ways to set the default size of the window opened using "o" or "v" to be bigger?
Thanks a lot ;)
The new window should take half of the height or half of the width of the current window which can give you small windows pretty quickly.
The option that defines that proportion can be found in :help netrw:
let g:netrw_winsize = 75
Note that using this method will make any further split even smaller than before:
let g:netrw_winsize = 50 (default)
|-netrw--------------------------------------------|
|-netrw------------------|-file--------------------|
|-netrw------|-file------|-file--------------------|
let g:netrw_winsize = 75
|-netrw--------------------------------------------|
|-netrw------|-file--------------------------------|
|-netrw|-file|-file--------------------------------|
The "problem", here is that netrw splits its own window, not the previous window.
Netrw can be used to open the file under the cursor in the current window, in a split window or in another tab but the way it splits its own window makes it hard to use it the way you want. AFAIK, the most common usage is:
open netrw with :Ex,
navigate,
hit <CR> to open the file under the cursor in the current window,
edit,
re-open netrw in its latest state with :Rex (for Peter Rincker),
GOTO 2
An alternative is to use :Vex to open netrw in a vertical split and use P to open the file in the previous window.
I'm afraid Netrw is not really designed to work like what you seem to want it to work. IMO, netrw is more like an "open…" dialog than the kind of file explorer pane you can see in most editors/IDEs. I'd suggest you either get used to it or try NERDTree which has only a subset of netrw's features but is designed to be more like those file explorer panes.
Actually the split size is not relative to netrw, it's the default size vim sets for newly created splits, so if you want to resize the actual split which is in you case the navigator (netrw) you can use this commend:
:vertical resize 30
There is :Lex now to open a left explorer. You can place let g:netrw_winsize=30 in your vimrc file to keep the explorer small.

How can I maximize a split window?

Invoking :help in Vim, I got the help manual page with split window. I want to maximize the help manual window and close the other window.
How can I do this? What is the Vim command to do this?
You can employ Ctrl+WT (that's a capital T) to move any open window to its own tab.
As mentioned by others Ctrl+W_ / Ctrl+W| to maximize within the current tab/window layout (while respecting min height/width settings for various other windows).
(Ctrl+W= resizes all windows to equal size, respecting the minimum height/width settings)
Edit To the comment
start vim (e.g. gvim /tmp/test.cpp)
invoke help :help various-motions - opens a split window
move help into separate tab maximized: C-wT
enjoy reading the fine manual :)
move the help back into the original tab:
mAZZ<C-w>S`A
mA: set global mark A
ZZ: close help buffer/tab
C-wS: split original window
`A: jump to saved mark A
You can avoid using a mark for normal (non-help) buffers. Let me know if you're interested.
With :help [topic] you open up a topic that interests you.
Ctrl-Wo will minimize the other windows (leaving only the help window open/maximized).
(Ctrl-Wo means holding Ctrl press W, and then o)
You can expand a window to its maximum size using Ctrl+W_ (underscore). The final size of the expanded window will be constrained by the value of the winminheight option. When you close the help window, your previous window(s) will be restored to their former sizes.
I prefer to use tabs for that. Use
:tabedit %
to open a file maximized in a new tab, once you are done return to the old setup with all windows using
:tabclose
I find this the ideal solution as this works together with :cw and the Tagbar plugin. Taken from: vim.wikia
I like to use 'M' to maximize and 'm' to minimize.
It won't look great as it'll shrink all the other open windows that are in the same buffer, but I found it to be more useful when dealing with tabs. So for instance, instead of opening a new tab for that file then having to close it after you're done with it or want to minimize it.
nnoremap <C-W>M <C-W>\| <C-W>_
nnoremap <C-W>m <C-W>=
The reason for nnoremap is that I don't care about recursive mapping, but just map should also work.
Install the plugin vim-maximizer, then you can maximize the current window and restore with F3
You can get help window in full size without closing/resizing any other windows by using
tab help {topic}
This will open help window in a new tab, other windows will be left as-is (really resized so that tabline can be shown, but this is only one additional line above). You can close help as usual: at least :bw<CR> and <C-w>c work for me closing new tab as well.
Plugin ZoomWin
by Charles Campbell
This plugin remaps
Ctrl-w o
to do both: maximize and restore previous layout.
This plugin can be downloaded from two locations
https://www.vim.org/scripts/script.php?script_id=508 (v24)
http://www.drchip.org/astronaut/vim/index.html#ZOOMWIN (v25)
To get just the help up, then close the other window, do this: :helpCTRL-WCTRL-W:close. Then you'll have just the help up.
Somehow the ZoomWin plugin did not work at all for me, I now see there are other plugins but I already wrote this and gives me the exact effect I wanted (with a minor quirk detailed below):
function! ToggleZoom(zoom)
if exists("t:restore_zoom") && (a:zoom == v:true || t:restore_zoom.win != winnr())
exec t:restore_zoom.cmd
unlet t:restore_zoom
elseif a:zoom
let t:restore_zoom = { 'win': winnr(), 'cmd': winrestcmd() }
exec "normal \<C-W>\|\<C-W>_"
endif
endfunction
augroup restorezoom
au WinEnter * silent! :call ToggleZoom(v:false)
augroup END
nnoremap <silent> <Leader>+ :call ToggleZoom(v:true)<CR>
Use the mapped key (Leader and + in my case) to toggle between maximized / previous layout. If you change to another split in the same tab, maximization turns off.
If you change tabs, the split stays maximized, although somehow it won't cover the complete full width anymore, with the width minimized windows gaining back some 4 columns or something. Anyway it works acceptably for me even with that minor quirk.
edit: somehow it works fine now, must've messed up in some way before.
in your .vimrc, just place
nmap - :res<CR>:vertical res<CR>$
When you want maximize current window, just press - in command mode. Press = when you want to restore the last status of multiple window

auto-scrollable pagination with vim using vertical split

I want to achieve the following: I want to split a vim session into two (or more) vertical windows (with the :vsplit command). Then, I want to have each window contents vertically offsetted so that the line after the last visible one of the first window becomes the first line of the second window. Then, when I use the arrows to scroll around, the vertical windows are scrollbound so that text flows from the second window into the first. How can I achieve this?
There are plugins for that: MultiPage
You can also use a oneliner described in this post by Chip Campbell:
:nmap <silent> <Leader>ef :vsplit<bar>wincmd l<bar>exe "norm! Ljz<c-v><cr>"<cr>:set scb<cr>:wincmd h<cr> :set scb<cr>
This will bind <Leader>ef to open a vsplit and make the splits continuous.
First, split your window normally and position it according to your needs (last line in one, first line in the other).
Now, run :set scrollbind in the first window. Jump to the second one and do the same, you can also use :set scb for short.
That's it!
And be sure to read :h scroll-binding.

Resources