Dunno about constraining to a window, but vimscript itself could be a good way of sending editing commands.