1

I want to create a command that will place my gvim window to a different "x" location on my screen while maintaining the "y" position.

I do this in my _gvimrc by calling

winpos 319 16

I want to create a function WinRight that will put my window on the right side of the screen, but this doesn't work:

function! WinRight()
    let ypos=getwinposy()
    winpos 1241 ypos
endfunction

When I :call WinRight(), I get "E466 :winpos requires two number arguments".

The function works if I substitute a number for ypos. Why doesn't my use of the variable ypos work here though?

2

Use :execute to assemble a command from a string, which allows you to include the contents of a variable or return value from a function.

This should work:

function! WinRight()
    let ypos=getwinposy()
    execute "winpos 1241 ".ypos
endfunction

Or even:

function! WinRight()
    execute "winpos 1241 ".getwinposy()
endfunction
0

I want to create a command that will place my gvim window to a different "x" location on my screen while maintaining the "y" position.

As a more general solution to the problem of rearranging windows, you might look at Divvy – it's a window manager available on Mac and Windows (there are probably other options for both of those operating systems, or Linux).

Using Divvy, you get to define global keyboard commands that allow you to move any window from any application to one of several specific screen regions. I have defined cmd-ctrl-8 (as a chord) to relocate the current window to the left half of the screen, cmd-ctrl-9 to the right half, and cmd-ctrl-0 to maximize to full screen. I use it to rearrange vim windows as well as everything else – terminals, browser, email, etc.

I don't know how many it supports in total, I have 9 unique shortcut/locations defined and it still shows the "New" button to create another one.

Your Answer

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

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