Vim Tips Wiki

Maximize or set initial window size

Revision as of 15:02, February 24, 2014 by Fritzophrenic (Talk | contribs)

1,613pages on
this wiki
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.
  set lines=999 columns=999
  " This is console Vim.
  if exists("+lines")
    set lines=50
  if exists("+columns")
    set columns=100

On Linux/bsd's terminal, this is done automatically. If you want to set initial size of gvim, you can put "set lines=N columns=N" in .gvimrc

How to put: -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:

exec=/usr/bin/gvim #here you can modify the location of gvim
$exec -f $* &

while [ -z $winid ]; do
  sleep 0.05
  winid=`wmctrl -pl |grep -P "^0x[0-9a-f]+[ ]+[-0-9]+[ ]+$pid" | cut -f1 -d' '`
# 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

In Windows, you can change the Properties of the shortcut to start Vim, for example:

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

This wont work, however, if you disable 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...).

There is also a :winsize command, but it is deprecated (see :help winsize).

Using simalt command

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

au GUIEnter * simalt ~x "x on an English Windows version. n on a French one

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".


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

Around Wikia's network

Random Wiki