Vim Tips Wiki
(Change to TipImported template + severe manual clean)
('vimx" not used anywhere else)
(11 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=1215
 
|id=1215
|previous=1214
+
|previous=1213
 
|next=1217
 
|next=1217
 
|created=April 26, 2006
 
|created=April 26, 2006
 
|complexity=basic
 
|complexity=basic
|author=Robert
+
|author=Robert & Bill
|version=6.0
+
|version=7.0
 
|rating=4/4
 
|rating=4/4
  +
|category1=Split windows
  +
|category2=
 
}}
 
}}
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).
 
   
  +
This tip is about how to resize {{help|prefix=no|usr_08.txt|Windows}} efficiently.
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.
 
 
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.
 
   
  +
You can use the <code>:resize</code> command or its shortcut <code>:res</code> to change the height of the window. To change the height to 60 rows, use:
 
<pre>
 
<pre>
  +
:resize 60
nnoremap &lt;silent&gt;&lt;Leader&gt;= :&lt;C-u&gt;exe "norm! z".(line("$")&lt;=winheight(0)?line("$")+&amp;so:(winheight(0)+&amp;so+1)*3/2)."\&lt;lt&gt;CR&gt;"&lt;CR&gt;
 
  +
</pre>
nnoremap &lt;silent&gt;&lt;Leader&gt;- :&lt;C-u&gt;exe "norm! z".(winheight(0)*2/3)."\&lt;lt&gt;CR&gt;"&lt;CR&gt;
 
  +
You can also change the height in increments. To change the height by increments of 5, use:
nnoremap &lt;Leader&gt;_ &lt;C-w&gt;_
 
  +
<pre>
nnoremap &lt;Leader&gt;&lt;Bar&gt; &lt;C-w&gt;&lt;Bar&gt;
 
 
:res +5
 
:res -5
 
</pre>
 
</pre>
   
----
 
You can also use the :resize command for this, e.g:
 
   
  +
You can use <code>:vertical resize</code> to change the width of the current window. To change the width to 80 columns, use:
 
<pre>
 
<pre>
  +
:vertical resize 80
:res +10
 
  +
</pre>
:res -10
 
  +
You can also change the width in increments. To change the width by increments of 5, use:
:res 20
 
  +
<pre>
  +
:vertical resize +5
  +
:vertical resize -5
 
</pre>
 
</pre>
   
----
 
WinWalker has resizing as well as a lot of other stuff. I just uploaded another version. It's only for Vim 7, though.
 
   
  +
For a '''split''' window: You can use <code>Ctrl-w +</code> and <code>Ctrl-w -</code> to resize the height of the current window by a single row. For a '''vsplit''' window: You can use <code>Ctrl-w &gt;</code> and <code>Ctrl-w &lt;</code> to resize the width of the current window by a single column. Additionally, these key combinations accept a count prefix 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]
----
 
I have reduced these mappings to (in my opinion the most compact form):
 
   
  +
To resize all windows to equal dimensions based on their splits, you can use <code>Ctrl-w =</code>.
  +
  +
To increase a window to its maximum size, use <code>Ctrl-w _</code>.
  +
  +
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 &lt;silent&gt; + :exe "resize " . (winheight(0) * 3/2)&lt;CR&gt;
+
nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap &lt;silent&gt; - :exe "resize " . (winheight(0) * 2/3)&lt;CR&gt;
+
nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
 
</pre>
 
</pre>
   
----
 
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.
 
   
  +
In Gvim and vim in terminals with mouse support, 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.
It also works under Unix. I also like to use the "&lt;c-w&gt; =" to make all windows same size (once I've resized 10 subwindows and got lost on the original one I'm working on). "&lt;c-w&gt; _" (underscore) is very powerfull too, to maximize one subwindow
 
   
  +
==See also==
----
 
  +
*[[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}}
  +
* Kana Natsunos {{script|id=2467|text=submode plugin}}
  +
* Tom Links {{script|id=4199|text=tiny keymaps}}
 
==Comments==

Revision as of 14:28, 14 January 2014

Tip 1215 Printable Monobook Previous Next

created April 26, 2006 · complexity basic · author Robert & Bill · version 7.0


This tip is about how to resize Windows efficiently.

You can use the :resize command or its shortcut :res to change the height of the window. To change the height to 60 rows, use:

:resize 60

You can also change the height in increments. To change the height by increments of 5, use:

:res +5
:res -5


You can use :vertical resize to change the width of the current window. To change the width to 80 columns, use:

:vertical resize 80

You can also change the width in increments. To change the width by increments of 5, use:

:vertical resize +5
:vertical resize -5


For a split window: You can use Ctrl-w + and Ctrl-w - to resize the height of the current window by a single row. For a vsplit window: You can use Ctrl-w > and Ctrl-w < to resize the width of the current window by a single column. Additionally, these key combinations accept a count prefix 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 equal dimensions based on their splits, you can use Ctrl-w =.

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>


In Gvim and vim in terminals with mouse support, 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