I think you can do this by defining a custom command using one of the languages that was compiled into your copy of vim. I'll assume Python. See if this works::py3 print('hello world')
. If so, then the documentation specifically discusses manipulating windows:
5. Window objects python-window
Window objects represent vim windows. You can obtain them in a number of ways:
- via vim.current.window (python-current)
- from indexing vim.windows (python-windows)
- from indexing "windows" attribute of a tab page (python-tabpage)
- from the "window" attribute of a tab page (python-tabpage)
You can manipulate window objects only through their attributes. They have no
methods, and no sequence or other interface.
If you combine that with the example from here:
For anything nontrivial, you'll want to put your Python code in a separate
file, say (for simplicity) x. To get that code into a Vim session, type
:source x
from within that session. That file will actually be considered to be
Vimscript code, but with Python embedded.
Extending the above obligatory "hello wordl" example, place
:map hw :py3 print("hello world")
in x. From then on, whenever you type 'hw' in noninsert mode, you'll
see the greeting appear in the status line.
For more elaborate code, The format of the file x is typically this:
python << endpy
import vim
lines of Python code
endpy
It doesn't seem like a big stretch to whip something up that does exactly what you're looking for, similar to this:
py3 << __EOF__
import vim
def do_window_stuff(foo):
if vim.current.window == foo:
<do some stuff>
__EOF__
command WindowThing :py3 do_window_stuff(foo)
" OR
noremap .windowthing :py3 do_window_stuff(foo)
This is embedding the python inside the Vimscript. The last few lines will map the custom command to the python function do_window_stuff().
Using command
will let you invoke it at the command mode prompt as :WindowThing
(the command needs to begin with an uppercase letter).
Using noremap
will remap the key sequence .windowthing
when entered from a non-insert mode.