I am using Cygwin's X-windows and Gvim. I have a command that docks a Gvim window to the right side of my Windows 10 desktop so that I can take notes during video meetings, which seem to be the norm during COVID-19 lockdown:

command! GR set lines=45 columns=60 guifont=Consolas\ 15 | winpos 1239 53

I hard-coded the lines & columns options and winpos arguments based on the resolution of my screen and the font I happen to be using.

Is there a simple way to generalize this so that the winpos arguments are automatically determined for other screen sizes and font sizes? Actually, the lines option will also depend on the height of the screen. I'll stick with columns=60.

I realize that I am in effect asking someone to develop vimscript code to do this. I don't have the expertise to do this, and it would take more years than remaining in my life to obtain it. So unless you enjoy this kind of challenge, please ignore this.


Investigative steps taken

As intermediate steps, I can maximize the window by :set lines=999 columns=999, query what they got coerced to, then use &lines to set the window height. The command :winpos xOffset yOffset sets the number of pixels offset of the top-left corner of gvim from the top-left of the desktop, although the title bar of the window falls off the top of the Windows desktop for yOffset=0 (which is fine).

I need to choose xOffset to be less than the pixel count of the desktop width, leaving enough width for 60 columns. This requires the ratio of pixels to columns, obtainable by X-windows commands for the display width and the maximum value that columns was coerced to, or by :set lines=60 | windpos 0 0, shelling out, and querying X-windows for the width of the Gvim window (:help winsize). Both require installing X-windows utilities (wmctrl,xprop,xrandr,xwininfo), which means shutting Cygwin down and logging in as Windows administrator. I will follow up after finishing off some things.

  • « Gvim language code » vimscript? There are some good, not too long resources (not to mention :help), eg, Learn Vimscript the Hard Way. OTOH I suspect you’ll need information from the hardware
    – D. Ben Knoble
    Mar 20 at 1:04
  • Yes, I reworded the question to use "vimscript". Learning vimscript is what I would need to do. I've dabbled in various aspects that I see in browsing Learn Vimscript the Hard Way, but it will definitely be a long term endeavour for me (with other endeavours already in the wings). The script or function will probably get geometry parameters from Cygwin's X-windows rather than the hardware itself. I suspect that the formalism used would be determined by X-windows rather than the fact that it is Cygwin. Or whatever layer of abstraction gvim uses to interact with the host windowing system. Mar 20 at 19:02
  • 1
    Ok, fair, you need to interrogate X-windows. If you (or someone else) can gather that information, the vimscript part is actually not too hard.
    – D. Ben Knoble
    Mar 20 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.