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.

3
  • 3
    That's the most portable way I know. Could you elaborate on the "but the window is not maximized, just resized and I lose some rows/columns". Maximization is afaik, resizing till the edges. And I don't think I ever lost a row/col in that way.
    – Rook
    May 12, 2010 at 19:04
  • @Idigas: correct, maximization is just "resize till it fills up available space (not covering toolbars etc)", in terms of wm-speak :)
    – akira
    May 13, 2010 at 7:39
  • Setting the hack above doesn't resize till the edges. I'm starting to think the better approach is going to add an if in my vimrc: if it'd windows, call a config, else, call other config. May 13, 2010 at 12:15

11 Answers 11

31

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.

5
  • This didn't work for me on Windows 7 Ultimate. Feb 18, 2011 at 20:01
  • 2
    It also depends on the OS language sadly. For French Windows versions, it becomes au GUIEnter * simalt ~n.
    – ereOn
    Sep 7, 2011 at 11:52
  • Is there a way to do the opposite, to un-maximize? Seems like :simalt ~x only works one way on Windows7x64 ENG. Oct 17, 2012 at 20:46
  • 1
    ~x comes from keyboard shortcut for menu option. Check the shortcut for desire option and try it. Maybe it's Restore? Nov 3, 2012 at 0:18
  • @GrzegorzGierlik Thanks, you're right. I didn't realize that simalt meant 'simulate the alt keypress'. Thanks. Dec 8, 2012 at 19:24
14

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.

5
  • Can you combine this with au GUIEnter * simalt ~x ??
    – snitzr
    Jun 9, 2010 at 1:34
  • Yes, creating a condition in your vimrc to know if it's windows or Linux. Since I'm mainly using Linux, I'm going to add this config later. Jun 9, 2010 at 12:22
  • This approach does not work for me under GNOME 3. When the window was already non-maximized, this will slow down Vim for a little while (does not happen when I maximize using the window manager), and it will leave a little edge above the window uncovered, because my screen height is not a perfect multiple of line height. When the window was vertically (but not horizontally) maximized by dragging the window to the left or right of the screen, this will have no effect. May 2, 2012 at 20:40
  • @AndresRiofrio For these situations (multiple desktop environments in Linux), I am seriously thinking about using devilspie. It's a third-party solution, I know, but it may work. I've used it in some other applications I wanted to be open maximized. Jun 24, 2012 at 1:56
  • This also causes the window to become huge if you un-maximize it.
    – Kevin Cox
    Sep 18, 2013 at 19:00
7

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

1
  • 1
    For linux this is probably the best option. in .zshrc do alias v="gvim -geometry 1366x768" and you're set for good. Jan 30, 2016 at 17:16
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.

2
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.)

0
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()
1
  • Interesting. Maybe you can dinamically get the lines and columns values in vimscript, so this config will work in all devices. Mar 20, 2014 at 2:00
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

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
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! 😉

-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
1
  • Looks like this only work for MacVim. Jul 28, 2016 at 10:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .