Vim Tips Wiki
Register
No edit summary
(reworked the tip)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=1215
 
|id=1215
Line 13: Line 12:
 
}}
 
}}
   
  +
This tip is about how to resize {{help|prefix=no|usr_08.txt|Windows}} efficiently.
You know that you can use "<c-w> +" and "<c-w> -" to resize a split window, but did you know you can repeat the resize commands (e.g. "10<c-w>+" will increase the window size by 10).
 
   
  +
You can use <code>Ctrl-W +</code> and <code>Ctrl-W -</code> to resize a split window. For changing the width of a window, use <code>Ctrl-W &gt;</code> to increase the window size by one, while <code>Ctrl-W &lt;</code> decreases the window width by one. Those keys also accept a count, so that you can change the window size in larger steps, e.g. <code>10 Ctrl-W+</code> increases the window size by 10 lines.
While this is a basic tip, I sometimes need to split windows in terminals and ended up killing my fingers while resizing them until I realized that the command could be repeated.
 
  +
To resize all Windows to the same size, you can use <code>CTRL-W =</code> and to increase a window to its maximum size, use <code>Ctrl-W _</code>.
 
Other resizing tips are at [[VimTip427]].
 
 
==Comments==
 
Here are some other suggestions. Increasing a window size by a factor of 1.5 and decreasing by a factor of 0.67 seems to work well for me.
 
   
  +
To resize in different steps, you can create maps that will adjust the window size differently. For example to increase the window size by a factor of 1.5 and decrease the window size by 0.67, you can map this:
 
<pre>
 
<pre>
nnoremap <silent><Leader>= :<C-u>exe "norm! z".(line("$")<=winheight(0)?line("$")+&so:(winheight(0)+&so+1)*3/2)."\<lt>CR>"<CR>
+
nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent><Leader>- :<C-u>exe "norm! z".(winheight(0)*2/3)."\<lt>CR>"<CR>
+
nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
nnoremap <Leader>_ <C-w>_
 
nnoremap <Leader><Bar> <C-w><Bar>
 
 
</pre>
 
</pre>
   
  +
Alternatively you can use the <code>:resize</code> command to change the height of the window, to change the window width, use the <code>:vertical </code> modifier. So to resize by 10 lines, use:
----
 
You can also use the :resize command for this, e.g:
 
 
 
<pre>
 
<pre>
 
:res +10
 
:res +10
 
:res -10
 
:res -10
:res 20
 
 
</pre>
 
</pre>
  +
And to resize to a size of 20 use this:
 
----
 
WinWalker has resizing as well as a lot of other stuff. I just uploaded another version. It's only for Vim 7, though.
 
 
----
 
I have reduced these mappings to (in my opinion the most compact form):
 
 
 
<pre>
 
<pre>
 
:res 20
nnoremap <silent> + :exe "resize " . (winheight(0) * 3/2)<CR>
 
  +
:vertical resize 20
nnoremap <silent> - :exe "resize " . (winheight(0) * 2/3)<CR>
 
 
</pre>
 
</pre>
   
  +
It is also possible to use the mouse to resize a window. Simply grab the statusline at the window border and drag it into the desired direction.
----
 
You can also drag the split with the mouse to where you want it. Just grab ahold of the statusline that makes the split, and drag. I know this works at under Windows, both in GUI and in non-GUI.
 
   
  +
==See also==
It also works under Unix. I also like to use the "<c-w> =" to make all windows same size (once I've resized 10 subwindows and got lost on the original one I'm working on). "<c-w> _" (underscore) is very powerfull too, to maximize one subwindow
 
  +
*[[VimTip427]]
 
  +
==Plugins==
----
 
  +
The following plugins allow to define submodes, that make it possible to use e.g. <code>Ctrl-W +</code> to increase the window size and keep on increasing as long as you keep '+' pressed:
 
  +
* Andy Wokulas {{script|id=2223|text=tinymode plugin}}
I have happily created submodes for various window commands with this plugin http://www.vim.org/scripts/script.php?script_id=2467 It has some drawbacks that the submode name length is limited, you can't use spaces, but it makes resizing easier.
 
  +
* Kana Natsunos {{script|id=2467|text=submode plugin}}
  +
* Tom Links {{script|id=4199|text=tiny keymaps}}
 
==Comments==

Revision as of 15:17, 20 November 2012

Tip 1215 Printable Monobook Previous Next

created April 26, 2006 · complexity basic · author Robert · version 6.0


This tip is about how to resize Windows efficiently.

You can use Ctrl-W + and Ctrl-W - to resize a split window. For changing the width of a window, use Ctrl-W > to increase the window size by one, while Ctrl-W < decreases the window width by one. Those keys also accept a count, so that you can change the window size in larger steps, e.g. 10 Ctrl-W+ increases the window size by 10 lines. To resize all Windows to the same size, you can use CTRL-W = and to increase a window to its maximum size, use Ctrl-W _.

To resize in different steps, you can create maps that will adjust the window size differently. For example to increase the window size by a factor of 1.5 and decrease the window size by 0.67, you can map this:

nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>

Alternatively you can use the :resize command to change the height of the window, to change the window width, use the :vertical modifier. So to resize by 10 lines, use:

:res +10
:res -10

And to resize to a size of 20 use this:

:res 20
:vertical resize 20

It is also possible to use the mouse to resize a window. Simply grab the statusline at the window border and drag it into the desired direction.

See also

Plugins

The following plugins allow to define submodes, that make it possible to use e.g. Ctrl-W + to increase the window size and keep on increasing as long as you keep '+' pressed:

Comments