Wikia

Vim Tips Wiki

Automatically maximizing gvim in KDE

Talk0
1,613pages on
this wiki

Redirected from VimTip883

Tip 883 Printable Monobook Previous Next

created February 22, 2005 · complexity basic · author Anthony Gorecki · version 6.0


After a week of trying to find a proper way to maximize a gvim window under KDE, using the vimrc file, the best solution that I was able to find was "pseudo-maximize", which still left extra space around the gvim window. As a result of this, I abandoned the Vim configuration file and began experimenting with KDE's window-specific settings. Ironically, the solution was fairly simple:

First, open a gvim window and press the maximize button. Vim will generally rescale the window after you do this, so you'll need to make sure that the window is in fact maximized, typically by pressing the maximize button a second time to achieve the desired effect. Another way is to manually resize until you get as close as you can to a maximum size.

Next, right click on the title bar: Advanced -> Window Specific Settings. Select the Window tab if it isn't the default.

Click on the Detect button, and click anywhere inside the gvim window. In the window that pops up, select "Use window class (whole application)" and click Ok.

From here, move over to the Geometry tab and check the Size box. Change "Do Not Affect" to Force. You'll note that the size to the right is the same as that of the maximized window, which is the correct value. If you choose "Apply Initially" instead of Force, you'll encounter the same rescaling problem that required you to press the maximize button twice in the first step.

Please make certain that you've followed all of the above steps, as you'll need to edit these settings manually to change them. They're located in ~/.kdeX.Y/share/config/kwinrulesrc and must be edited when KDE is not running in order to avoid being overwritten. If you are on 4.4 you can edit it via right clicking on the titlebar, then "configure window behavior", go to the "window specific" section, choose your settings and select modify. The above is tested with KDE 3.4 and 4.4 (named slightly differently in 4.4 but close enough). If you're still a few pixels away just continue to edit it until you get it perfect.

Click Ok at the bottom of the window, restart gvim and enjoy.

CommentsEdit

Another way, much simpler, is the following: you run gvim, maximize it in usual way (by clicking appropriate button), then open (or create) ~/.gvimrc and type somewhere inside it:

set lines=<n1> columns=<n2>

where <n1> and <n2> may be found by executing command

:set lines? columns?

Using KDE 3.3 I found it very simple to define a Keyboard shortcut <CTRL><ALT><SPACE> on Maximise Window in the KDE ControlCenter. This can be used to toggle between the startup size and fullscreen.


Most KDE desktops will also accept F11 as a fullscreen command.

Regarding set (lines|columns), the method is correct, however it's not a true "maximization". gvim automatically rescales the lines and columns to the nearest whole number that will fit on the screen, thus if you 'set lines=999', you may end up with lines=140, leaving extraneous free space below the window because there isn't enough space to evenly fit another line. While the method listed in the tip works, I agree that it could be far less complex; unfortunately, I haven't found a way to forcibly disable the window rescaling at runtime.


I don't have access to KDE at the moment but this can be controlled from your .Xdefaults file like by adding something along the lines of

gvim*Geometry: 150x50+45+25

If you are like me and have different resolutions at home and at work then you can bypass the >Xdefaults file with aliases (These are Solaris tcsh)

alias vh "gvim -U ~/.gvimrc -o -geometry 160x50+150+55 -fn 10x16"

alias vhd "gvimdiff -U ~/.gvimrc -O -geometry 160x50+150+55 -fn 10x16"

etc.


I've actually found a simpler and more "accurate" way, based on the original tip. Using KDE 4.4.5:

First open a "common" KDE application (let's say Konsole/Terminal). Maximize it, click on the application icon on the left and choose Advanced->Special Window Settings. Click the Geometry tab and look at the "Size" entry. Even if it's grayed out you'll still see the values (1288,996 on a 1280x1024 resolution).

Now open gVim and do the same procedure: icon->Advanced->Special Window Settings. IMPORTANT: Click on the Window tab and set the Window role as "Unimportant". You'll notice that there's no need to detect anything: KDE already brings the right settings. Now go to the Geometry tab, mark the "Size" checkbox and put the exact same values found on the other application. Voila! =)


Can be even easier (tested in 4.9): Open gvim, use said way to change the window specific settings, but instead of setting Position and Size in the Size & Position tab, toggle the last checkbox, Obey geometry restrictions, set this to force and No, and it will maximize properly.

Around Wikia's network

Random Wiki