35

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
    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 '10 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 '10 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. – Somebody still uses you MS-DOS May 13 '10 at 12:15

10 Answers 10

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.

  • This didn't work for me on Windows 7 Ultimate. – Matt Alexander Feb 18 '11 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 '11 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. – TankorSmash Oct 17 '12 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? – Grzegorz Gierlik Nov 3 '12 at 0:18
  • @GrzegorzGierlik Thanks, you're right. I didn't realize that simalt meant 'simulate the alt keypress'. Thanks. – TankorSmash Dec 8 '12 at 19:24
7

The best way if you're concerned about cross-plataform is using :set lines=999 columns=999. I've found it in Vim's Wiki, wasn't so satisfied about it, buy if cross-plataform is a must, them this the solution.

  • Can you combine this with au GUIEnter * simalt ~x ?? – snitzr Jun 9 '10 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. – Somebody still uses you MS-DOS Jun 9 '10 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. – Andres Riofrio May 2 '12 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. – Somebody still uses you MS-DOS Jun 24 '12 at 1:56
  • This also causes the window to become huge if you un-maximize it. – Kevin Cox Sep 18 '13 at 19:00
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()
  • 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 Mar 20 '14 at 2:00
2

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

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

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
  • Looks like this only work for MacVim. – Michael Yoo Jul 28 '16 at 10:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.