Wikia

Vim Tips Wiki

Changes: Maximize or set initial window size

Edit

Back to page

(I find that the previous version does not work well in Windows 8.1 I found and updated an alternative that would do the work perfectly in Windows 8.1. I believe this should also be compatible for the previous distributions of Windows.)
(Adjust.)
 
Line 21: Line 21:
 
if has("gui_running")
 
if has("gui_running")
 
" GUI is running or is about to start.
 
" GUI is running or is about to start.
" Maximize gvim window.
+
" Maximize gvim window (for an alternative on Windows, see simalt below).
" set lines=999 columns=999 " [This is the original suggestion] au GUIEnter * simalt ~x " [Works well in Windows 8.1]
+
set lines=999 columns=999
  +
else
 
" This is console Vim.
 
" This is console Vim.
 
if exists("+lines")
 
if exists("+lines")
Line 33: Line 33:
 
</pre>
 
</pre>
   
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
+
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}}
+
<pre>
How to put:
+
gvim -geometry 97x46+1913+145
-geometry 97x46+1913+145 ????
+
</pre>
   
 
===To maximize the initial gvim window using wmctrl (X server)===
 
===To maximize the initial gvim window using wmctrl (X server)===
 
Instead of running gvim directly, you can run the following simple script:
 
Instead of running gvim directly, you can run the following simple script:
 
 
<pre>
 
<pre>
 
#!/bin/bash
 
#!/bin/bash
Line 52: Line 51:
 
done
 
done
 
# echo "debug: $exec started, PID=$pid, Window ID=$winid"
 
# echo "debug: $exec started, PID=$pid, Window ID=$winid"
#this maximizes the GVim window
+
#this maximizes the gvim window
 
wmctrl -i -b add,maximized_vert,maximized_horz -r $winid
 
wmctrl -i -b add,maximized_vert,maximized_horz -r $winid
#this switches the GVim window to fullscreen
+
#this switches the gvim window to fullscreen
 
wmctrl -i -b add,fullscreen -r $winid
 
wmctrl -i -b add,fullscreen -r $winid
 
</pre>
 
</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.
+
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 .
 
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===
 
===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.
   
In Windows, you can change the Properties of the shortcut to start Vim, for example:
+
Put the following in your vimrc to maximize Vim on startup (from {{help|win16-maximized}}):
 
<pre>
 
<pre>
cmd /c start /max "C:\Program Files\vim\vim71\gvim.exe"
+
" Use ~x on an English Windows version or ~n for French.
  +
au GUIEnter * simalt ~x
 
</pre>
 
</pre>
   
This wont work, however, if you disable 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...).
+
A Windows alternative would be to change the properties of the shortcut to start Vim, for example:
 
There is also a <code>:winsize</code> 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}}):
 
 
<pre>
 
<pre>
au GUIEnter * simalt ~x "x on an English Windows version. n on a French one
+
cmd /c start /max "C:\Program Files\vim\vim71\gvim.exe"
 
</pre>
 
</pre>
  +
  +
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).
   
 
====Using Maximize.dll plugin====
 
====Using Maximize.dll plugin====
+
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}}.
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}}.
 
   
 
====Using Nircmd====
 
====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:
 
[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>
<pre>nircmd.exe exec max "C:\Program Files (x86)\vim\vim74\gvim.exe"</pre>
+
nircmd.exe exec max "C:\Program Files (x86)\vim\vim74\gvim.exe"
  +
</pre>
   
 
or as PowerShell function that accepts file argument
 
or as PowerShell function that accepts file argument
 
 
<pre>
 
<pre>
function gvim($file){
+
function gvim($file) {
start nircmd.exe "exec max ""C:\Program Files (x86)\vim\vim74\gvim.exe"" $file"
+
start nircmd.exe "exec max ""C:\Program Files (x86)\vim\vim74\gvim.exe"" $file"
}</pre>
+
}
  +
</pre>
   
 
===To maximize the initial Vim window under Sawfish===
 
===To maximize the initial Vim window under Sawfish===
Line 95: Line 95:
 
*Select "matched windows", "Add...".
 
*Select "matched windows", "Add...".
 
*In "macthers" select "Class".
 
*In "macthers" select "Class".
*"Grab..." and click the Gvim window.
+
*"Grab..." and click the gvim window.
 
*Select the "Maximized" checkbox and click "OK".
 
*Select the "Maximized" checkbox and click "OK".
   
Line 107: Line 107:
 
*[[VimTip883|883 Automatically maximizing gvim in KDE]]
 
*[[VimTip883|883 Automatically maximizing gvim in KDE]]
 
*[[VimTip1110|1110 Toggle gvim window size]]
 
*[[VimTip1110|1110 Toggle gvim window size]]
  +
  +
===Edit June 9, 2014===
  +
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)

Latest revision as of 05:57, June 10, 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 windowEdit

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)Edit

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 WindowsEdit

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 pluginEdit

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

Using NircmdEdit

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 SawfishEdit

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

CommentsEdit

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

Edit June 9, 2014Edit

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)

Around Wikia's network

Random Wiki