Specifying width for :vsplit in vim - vim

Is there any way to specify a width when doing :vsplit?
Also, is there a way to increase or decrease the width on a vertically splitted window? Ctrl-w + and Ctrl-w - seems to be working on only horizontally split windows.

According to :help :vsplit, it takes an optional numeric argument as a prefix, e.g., :80vs. Try it out!
Edit: I guess I forgot to mention. You can control the width with Ctrl-W < and Ctrl-W >
For more info, read the manual at :help windows

Ctrl-W n < works, replace n with the number of steps you want to move.

You can also use for example 80| to set your current split width to 80 columns

If you want to fix the adjusted windows width, be sure the cursor is placed inside it and set the boolean
:set winfixwidth
This prevents from unwanted automatic resize of the such locked window width if some other window command like CTRL-= ("make all windows equal") is applied.
:set nowinfixwidth with the cursor placed inside the appropriate window disables the lock.
:mksession stores the window arrangement as calling vim again from the command line likevim -S Session.vim & restores it.
Hope this helps...

Also:
:vs
:vertical resize 30
and:
:sp
:resize 30
I have an Alt+E binding for a vertical file-explorer pane 60 chars wide:
:vs +Explore<CR>:vertical resize 60<CR>
Admittedly, I didn't know about the simple :60vs or :60sp thing in Luis' answer when I wrote that macro.

Related

What vimrc setting controls number of scroll lines

When using Ctrl-E and Ctrl-Y in vim, I would like it to scroll multiple lines instead of one at a time. How would I set up my vimrc to specify the number of lines for just these 2 commands?
You can override the default bindings with counted versions.
noremap <C-e> 2<C-e>
noremap <C-y> 2<C-y>
Use noremap to avoid recursion.
You don't need to do any particular setup. Instead, you can just scroll one page at a time using CTRL+F (forward) or CTRL+B (backwards) as an alternative solution.
This is not exactly what you want, but I hope it helps.
Regarding Ctrl+E and Ctrl+Y, I'm afraid that the only way may be to precede the command with a line count. So, if you want to scroll down five lines, you press 5, then Ctrl+E.
But you can, by default, use Ctrl+D to scroll half a page downwards, and Ctrl+U to scroll half a page upwards, and you can also set how many lines you want to go up or down with the scroll variable.
So, in your .vimrc, add the line set scroll=N, where N is the number of lines you want to scroll with the Ctrl+D and Ctrl+U commands.

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.

Vim window resizing

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?

Changing the size of the split screen in vimdiff

I only know two commands for dealing with vimdiff:
Ctrl-w Ctrl-w switches windows and Ctrl-w = makes the two windows equal width if they became uneven due to, for example, resizing the terminal.
How can I make the left screen much larger than the right, for instance?
You can use any windowing command in vimdiff, for example CTRL-w < to make the left window one column smaller. This can also be combined with a count, for example CTRL-W 5> to make the right window 5 columns smaller. Consult the help page with :help CTRL-w to get a list of window commands.
Additionally, you can use the mouse to change the size of the windows by clicking the boundary between both windows and dragging it into a direction. You might have to enable mouse support by issuing :set mouse=a first.

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

Resources