Vim Tips Wiki
(Adjust.)
(29 intermediate revisions by 16 users not shown)
Line 1: Line 1:
  +
{{TipImported
{{review}}
 
{{Tip
 
 
|id=88
 
|id=88
  +
|previous=87
|title=How to maximize vim on entry (win32)
 
  +
|next=89
|created=July 14, 2001 19:01
+
|created=2001
 
|complexity=basic
 
|complexity=basic
|author=Leif Wickland (leifw at bigfoot , com)
+
|author=Leif Wickland
|version=5.7
+
|version=6.0
 
|rating=149/61
 
|rating=149/61
  +
|category1=Windows
|text=
 
  +
|category2=
Maybe it's just because I have far too small of a monitor, because I can get distracted while coding if I have other stuff on the screen, or because I starting using vim on a console, but I definitely like my vim window maximized. Anyway, sticking the following in your vimrc will always maximize your vim window on startup.
 
 
}}
  +
===To set the initial size of the Vim window===
  +
Place the following in your [[vimrc]] to control the initial size of the Vim or gvim window (change the numbers to what you need):
  +
<pre>
 
set lines=50 columns=100
  +
</pre>
   
  +
Here is a more sophisticated version:
au GUIEnter * simalt ~x
 
  +
<pre>
  +
if has("gui_running")
  +
" GUI is running or is about to start.
  +
" Maximize gvim window (for an alternative on Windows, see simalt below).
  +
set lines=999 columns=999
  +
else
  +
" This is console Vim.
  +
if exists("+lines")
  +
set lines=50
  +
endif
  +
if exists("+columns")
  +
set columns=100
  +
endif
  +
endif
  +
</pre>
   
  +
On Linux/bsd's terminal, this is done automatically. If you want to set the initial size of gvim, you can put <code>set lines=N columns=N</code> in .gvimrc. Some systems support <code>-geometry</code> as shown in the following example. {{help|-geometry}}
{{help|win16-maximized}}
 
  +
<pre>
  +
gvim -geometry 97x46+1913+145
  +
</pre>
   
  +
===To maximize the initial gvim window using wmctrl (X server)===
}}
 
  +
Instead of running gvim directly, you can run the following simple script:
  +
<pre>
  +
#!/bin/bash
  +
exec=/usr/bin/gvim #here you can modify the location of gvim
  +
$exec -f $* &
  +
pid=$!
  +
winid=""
  +
while [ -z $winid ]; do
  +
sleep 0.05
  +
winid=`wmctrl -pl |grep -P "^0x[0-9a-f]+[ ]+[-0-9]+[ ]+$pid" | cut -f1 -d' '`
  +
done
  +
# echo "debug: $exec started, PID=$pid, Window ID=$winid"
  +
#this maximizes the gvim window
  +
wmctrl -i -b add,maximized_vert,maximized_horz -r $winid
  +
#this switches the gvim window to fullscreen
  +
wmctrl -i -b add,fullscreen -r $winid
  +
</pre>
  +
  +
In words, the script starts gvim, saves its process id and using wmctrl finds the window id of gvim. After that, it sends either a command for maximizing and/or for fullscreen.
  +
  +
If you want to have this as the default whenever you call gvim, you can, e.g., save this script as /usr/local/bin/gvim .
  +
  +
===To maximize the initial Vim window under Windows===
  +
On some Windows systems, pressing Win-Up (Windows key and the Up cursor key) maximizes the window, and Win-Down restores it.
   
  +
Put the following in your vimrc to maximize Vim on startup (from {{help|win16-maximized}}):
== Comments ==
 
  +
<pre>
In Windows, you can control this from your VIM shortcut (and even add a keyboard shortcut that will bring up VIM from anywhere.) Right click on your Icon select properties and fiddle with the Run and Short cut key entries. I use Shift-Control-Alt-V to start VIM from anywhere. If VIM is already running this will switch to the most recently used instance of VIM.
 
  +
" Use ~x on an English Windows version or ~n for French.
 
au GUIEnter * simalt ~x
  +
</pre>
   
  +
A Windows alternative would be to change the properties of the shortcut to start Vim, for example:
bindu--AT--wavell.net
 
  +
<pre>
, November 11, 2001 13:20
 
 
cmd /c start /max "C:\Program Files\vim\vim71\gvim.exe"
----
 
  +
</pre>
anyone know how to get this functionality to work in X with gvim? please email me if so...
 
   
  +
This will not work, however, if you disable the menu with <code>guioptions-=m</code> and this is not usable if you need to specify gvim as configuration option of some third party tools (file managers etc).
kbgaddis--AT--hotmail.com
 
, January 10, 2002 21:59
 
----
 
i dont know how to do this from vimrc. but it is a function of many windowmanagers, i am using windowmaker and i minimize vim, right click on vim icon, goto attributes, and click start maximized. i would guess many other windowmanagers can do this same thing.
 
   
  +
====Using Maximize.dll plugin====
libberspam--AT--atlaswebmail.com
 
  +
There is also a plugin with a DLL to maximize/restore the Vim window: {{script|id=1302|text=maximize.dll: Maximizing plugin for Win32 gvim}}.
, February 8, 2003 11:36
 
----
 
Use for example:
 
start /MAX "C:\Program Files\vim\vim61\gvim.exe"
 
   
  +
====Using Nircmd====
  +
[http://www.nirsoft.net/utils/nircmd.html Nircmd] is a small tool from Nirsoft that can be used to automate various aspects of Windows environment. You can use it to start application maximized or maximize running application window:
  +
<pre>
  +
nircmd.exe exec max "C:\Program Files (x86)\vim\vim74\gvim.exe"
  +
</pre>
   
  +
or as PowerShell function that accepts file argument
mkruszec--AT--mops.uci.agh.edu.pl
 
  +
<pre>
, March 17, 2003 5:42
 
  +
function gvim($file) {
----
 
  +
start nircmd.exe "exec max ""C:\Program Files (x86)\vim\vim74\gvim.exe"" $file"
In the same vein, you can specific a starting window size with:
 
  +
}
  +
</pre>
   
  +
===To maximize the initial Vim window under Sawfish===
set lines=50 columns=100
 
  +
You can configure [[w:c:sawfish:Main_Page|Sawfish]] to automatically maximize gvim on startup:
  +
*Run "sawfish-ui".
  +
*Select "matched windows", "Add...".
  +
*In "macthers" select "Class".
  +
*"Grab..." and click the gvim window.
  +
*Select the "Maximized" checkbox and click "OK".
   
 
==Comments==
I have a 21" monitor at 1600x1200, and with a medium-to-small font I can fit 4 gvim windows side by side at 100x50 each and still have room for IM client, music player, etc., yet still have enough room in each window to actually do stuff. (I'm one of those "prefers a busy screen" freaks).
 
  +
'''''TODO''''' Following are related tips. Should merge some of these.
  +
*[[VimTip427|427 Fast window resizing with plus/minus keys]]
  +
*[[VimTip488|488 Start with a wide window for diff]]
  +
*[[VimTip494|494 Maximize or restore window]]
  +
*[[VimTip507|507 Quick window resizing]]
  +
*[[VimTip669|669 Nice window resizing]]
  +
*[[VimTip883|883 Automatically maximizing gvim in KDE]]
  +
*[[VimTip1110|1110 Toggle gvim window size]]
   
  +
===Edit June 9, 2014===
see {{help|winsize}} (which is depreciated, but the help's still there)
 
  +
An edit put <code>simalt ~x</code> in the "more sophisticated" script, but that is already in the tip so I removed it. [[User:JohnBeckett|JohnBeckett]] ([[User talk:JohnBeckett|talk]]) 05:57, June 10, 2014 (UTC)
----
 
I wrote an utility which maximizes the Vim window, you call it from your _vimrc: http://vim.sourceforge.net/scripts/script.php?script_id=1302
 
----
 
<!-- parsed by vimtips.py in 0.430544 seconds-->
 
[[Category:Windows]]
 

Revision as of 05:57, 10 June 2014

Tip 88 Printable Monobook Previous Next

created 2001 · complexity basic · author Leif Wickland · version 6.0


To set the initial size of the Vim window

Place the following in your vimrc to control the initial size of the Vim or gvim window (change the numbers to what you need):

set lines=50 columns=100

Here is a more sophisticated version:

if has("gui_running")
  " GUI is running or is about to start.
  " Maximize gvim window (for an alternative on Windows, see simalt below).
  set lines=999 columns=999
else
  " This is console Vim.
  if exists("+lines")
    set lines=50
  endif
  if exists("+columns")
    set columns=100
  endif
endif

On Linux/bsd's terminal, this is done automatically. If you want to set the initial size of gvim, you can put set lines=N columns=N in .gvimrc. Some systems support -geometry as shown in the following example. :help -geometry

gvim -geometry 97x46+1913+145

To maximize the initial gvim window using wmctrl (X server)

Instead of running gvim directly, you can run the following simple script:

#!/bin/bash
exec=/usr/bin/gvim #here you can modify the location of gvim
$exec -f $* &
pid=$!
winid=""
while [ -z $winid ]; do
  sleep 0.05
  winid=`wmctrl -pl |grep -P "^0x[0-9a-f]+[ ]+[-0-9]+[ ]+$pid" | cut -f1 -d' '`
done
# echo "debug: $exec started, PID=$pid, Window ID=$winid"
#this maximizes the gvim window
wmctrl -i -b add,maximized_vert,maximized_horz -r $winid
#this switches the gvim window to fullscreen
wmctrl -i -b add,fullscreen -r $winid

In words, the script starts gvim, saves its process id and using wmctrl finds the window id of gvim. After that, it sends either a command for maximizing and/or for fullscreen.

If you want to have this as the default whenever you call gvim, you can, e.g., save this script as /usr/local/bin/gvim .

To maximize the initial Vim window under Windows

On some Windows systems, pressing Win-Up (Windows key and the Up cursor key) maximizes the window, and Win-Down restores it.

Put the following in your vimrc to maximize Vim on startup (from :help win16-maximized):

" Use ~x on an English Windows version or ~n for French.
au GUIEnter * simalt ~x

A Windows alternative would be to change the properties of the shortcut to start Vim, for example:

cmd /c start /max "C:\Program Files\vim\vim71\gvim.exe"

This will not work, however, if you disable the menu with guioptions-=m and this is not usable if you need to specify gvim as configuration option of some third party tools (file managers etc).

Using Maximize.dll plugin

There is also a plugin with a DLL to maximize/restore the Vim window: maximize.dll: Maximizing plugin for Win32 gvim.

Using Nircmd

Nircmd is a small tool from Nirsoft that can be used to automate various aspects of Windows environment. You can use it to start application maximized or maximize running application window:

nircmd.exe exec max "C:\Program Files (x86)\vim\vim74\gvim.exe"

or as PowerShell function that accepts file argument

function gvim($file) {
  start nircmd.exe "exec max ""C:\Program Files (x86)\vim\vim74\gvim.exe"" $file"
}

To maximize the initial Vim window under Sawfish

You can configure Sawfish to automatically maximize gvim on startup:

  • Run "sawfish-ui".
  • Select "matched windows", "Add...".
  • In "macthers" select "Class".
  • "Grab..." and click the gvim window.
  • Select the "Maximized" checkbox and click "OK".

Comments

TODO Following are related tips. Should merge some of these.

Edit June 9, 2014

An edit put simalt ~x in the "more sophisticated" script, but that is already in the tip so I removed it. JohnBeckett (talk) 05:57, June 10, 2014 (UTC)