43

How to make gVim automatically maximize it's window when I open it? And a cross-plataform solution, I'm trying to use the same configs in a Linux and Windows machine...

I've tried the hack :set lines=999 columns=999, it almost works, but the window is not maximized, just resized and I lose some rows/columns.

wonea
  • 1,877

11 Answers11

32

From the Vim wiki:

au GUIEnter * simalt ~x

That'll work on Windows; I'm not sure what key combinations you'd need on Gnome/KDE.

njd
  • 11,426
15

The best way if you're concerned about cross-platform compatibility is set lines=999 columns=999. I've found it in Vim's Wiki, and despite it's not perfect, it's a best solution if you need to work on different operating systems.

john c. j.
  • 314
  • 6
  • 25
8

On GNU/Linux

On GNU/Linux, the easiest way is to invoke gvim with the -geometry option. For example:

gvim -geometry 1336x744

This is obviously not handy if you would like to reuse the same start command on different machines.

Here is what I am using now on several machines with different screen dimensions without any issues. Just add it somewhere high up in your .vimrc.

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

Source: http://vim.wikia.com/wiki/Maximize_or_set_initial_window_size

6

Trick with:

au GUIEnter * simalt ~x

depends on Windows language.

For my Polish version works:

au GUIEnter * simalt ~s

Where s comes from Mak_s_ymalizuj.

So if ~x doesn't work press ALT+SPACE to open Window menu and check shortcut for Ma_x_imize Window menu option.

4

You can use maximize.dll plugin for fullscreen veiw on Vim (if you are using Windows). Just copy maximize.dll into vimdirectory/plugin folder.

3

For me, :simalt ~x did the trick. (Windows 7, English.)

2

UPDATE: for linux users, I've found much better solution that really does maximize the window: https://stackoverflow.com/questions/12448179/how-to-maximize-vims-windows-on-startup-with-vimrc

The only dependency is wmctrl, but it worths installing.

So, for windows I use maximize.dll plugin (as already mentioned by @fatihturan), and for linux I use wmctrl. Great!

(but I really can't understand why in 2014 gvim doesn't have this feature out-of-the-box)


Old answer:


For me, plain hack :set lines=999 columns=999 works badly on my Linux Mint MATE with two monitors. I have usually gvim opened on the secondary monitor, there're no taskbar, so, Vim should occupy the whole screen. But if I do :set lines=999 columns=999, gvim shrinks these values to the size of primary monitor, therefore, there are a small area below gvim window unused. It's better if I set real lines/columns count: just maximize your window "by hand" and type :set lines? and :set columns? , to get needed values. Since I use two monitors, I also need to specify window position, so, type :winpos to get current window position.

And secondary, it's better not just put these settings to the .vimrc, but execute them when gui is loaded.

So, final recipe:

1) maximize your gvim by hand and type three commands to get actual values: :winpos , :set lines? and :set columns? .

2) add this to .vimrc :

function Maximize()

   " put your actual values below
   winpos 0 0
   set lines=78
   set columns=237

endfunction

autocmd GUIEnter * call Maximize()
Dmitry Frank
  • 1,134
2

If you want vim to achieve full screen in Windows thoroughly (like in the picture), the plugin gvimfullscreen_win32 is highly recommended.

The plugin allows easier access to a full-screen mode and distraction-free environment. You can also add :set go= to gain more space. Here is a screenshot (Gvim7.4 on Windows 8.1):

enter image description here

undo
  • 6,129
1

Ubuntu (16.04)

Better let the window-manager do this task, at least in Ubuntu, it will fullscreen gvim instead of maximizing window, giving you more space. Of course this solution is platform dependent and not cross-platform, but it is a much better option for Ubuntu. You can even set gvim to open on a specific viewport.

Compiz Config Settings Manager -> Place Windows -> Fixed Window Placement -> Windows with fixed placement mode -> new

 Windows class=Gvim
 Mode    Maximize

If you don't have Compiz Config Settings Manager:

sudo apt install compizconfig-settings-manager
Janghou
  • 111
0

Windows

You already have the gvim.lnk at least in Start Menu – just change the property "Window size" ('Start window size', 'Window', etc. Depends on locale settings and Windows version) to "Maximized".

For example, to start gVim from Powershell put this to your $PROFILE file:

Set-Alias gvim -Value "<Path to>\gVim.lnk"

Note: don't forget to correct the path to .lnk!

SynCap
  • 101
-1

I believe you can do this in your $HOME/.vimrc to achieve what you want:

if has("gui_running")
     set fuoptions=maxvert,maxhorz
     au GUIEnter * set fullscreen
 endif

You can confirm where the fullscreen is being applied like so:

:verbose set nofullscreen?
 fullscreen
       Last set from ~/.vim_runtime/my_configs.vim
slm
  • 10,859