How to start gVim maximized?

38

11

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.

Somebody still uses you MS-DOS

Posted 2010-05-12T17:13:56.140

Reputation: 4 143

3That'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 – 2010-05-12T19:04:36.680

@Idigas: correct, maximization is just "resize till it fills up available space (not covering toolbars etc)", in terms of wm-speak :) – akira – 2010-05-13T07:39:21.323

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. – Somebody still uses you MS-DOS – 2010-05-13T12:15:21.490

Answers

10

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.

Somebody still uses you MS-DOS

Posted 2010-05-12T17:13:56.140

Reputation: 4 143

Can you combine this with au GUIEnter * simalt ~x ?? – snitzr – 2010-06-09T01:34:58.387

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. – Somebody still uses you MS-DOS – 2010-06-09T12:22:34.680

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. – Andres Riofrio – 2012-05-02T20:40:48.327

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

– Somebody still uses you MS-DOS – 2012-06-24T01:56:24.987

This also causes the window to become huge if you un-maximize it. – Kevin Cox – 2013-09-18T19:00:33.950

30

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

Posted 2010-05-12T17:13:56.140

Reputation: 9 743

This didn't work for me on Windows 7 Ultimate. – Matt Alexander – 2011-02-18T20:01:41.637

2It also depends on the OS language sadly. For French Windows versions, it becomes au GUIEnter * simalt ~n. – ereOn – 2011-09-07T11:52:20.757

Is there a way to do the opposite, to un-maximize? Seems like :simalt ~x only works one way on Windows7x64 ENG. – TankorSmash – 2012-10-17T20:46:11.497

1~x comes from keyboard shortcut for menu option. Check the shortcut for desire option and try it. Maybe it's Restore? – Grzegorz Gierlik – 2012-11-03T00:18:12.353

@GrzegorzGierlik Thanks, you're right. I didn't realize that simalt meant 'simulate the alt keypress'. Thanks. – TankorSmash – 2012-12-08T19:24:28.667

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.

Grzegorz Gierlik

Posted 2010-05-12T17:13:56.140

Reputation: 161

1And ~m for Norwegian – Bjarte Brandt – 2014-11-21T10:06:25.363

1And ~n for french ("Agra&ndir") – Sébastien RoccaSerra – 2013-07-17T14:16:34.003

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.

fatihturan

Posted 2010-05-12T17:13:56.140

Reputation: 41

3

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

Per Christian Corneliussen

Posted 2010-05-12T17:13:56.140

Reputation: 31

3

On GNU/Linux

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

gvim -geometry 1336x744

This is 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 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

Serge Stroobandt

Posted 2010-05-12T17:13:56.140

Reputation: 1 152

For linux this is probably the best option. in .zshrc do alias v="gvim -geometry 1366x768" and you're set for good. – Tanel Tammik – 2016-01-30T17:16:59.893

@TanelTammik Have a look again at my answer. I have edited it substantially to show the better solution that I am using now. Thanks for up-voting. – Serge Stroobandt – 2016-01-31T13:12:52.497

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

Posted 2010-05-12T17:13:56.140

Reputation: 699

Interesting. Maybe you can dinamically get the lines and columns values in vimscript, so this config will work in all devices. – Somebody still uses you MS-DOS – 2014-03-20T02:00:35.830

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

Posted 2010-05-12T17:13:56.140

Reputation: 111

1

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

user314897

Posted 2010-05-12T17:13:56.140

Reputation:

0

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

Posted 2010-05-12T17:13:56.140

Reputation: 7 449

Looks like this only work for MacVim. – Michael Yoo – 2016-07-28T10:37:47.770