如何从gnome中的bash-script启动带有最大化窗口的vim

时间:2011-05-05 16:06:06

标签: vim gnome

我想编写一个bash脚本,直接在最大化窗口中启动gvim-session。

那是我的bash脚本:

#!/bin/bash - 
set -o nounset

cd /home/alexthebird/vim-stuff; # directory of the gvim-session file
gvim -S bootmap;                # start gvim from the sessionfile 'bootmap'

您是否有任何想法如何使用bashscript完成此操作?只有在通过此脚本启动时才应最大化Gvim。当然,欢迎任何其他想法如何实现这一目标。

我使用Ubuntu 11.04和gnome。

感谢您抽出宝贵时间阅读我的留言。

AlexTheBird

此脚本有效:

#!/bin/bash - 
set -o nounset
# directory of the gvim-session file
cd /home/alexthebird/vim-stuff;
# -f because of a ubuntu global-menu bug
# -S starts from session-file named 'bootmap'
# -geom solved the problem. see post of Lstor
gvim -geom '200x50+0+0' -f -S bootmap; # start gvim from the sessionfile 'bootmap';

谢谢大家的时间。

编辑:我刚发现上述解决方案仅适用于unity-2d(非3D加速)桌面。哪个对我好。它不适用于使用Unity的3D加速版本的默认Ubuntu-desktop。

3 个答案:

答案 0 :(得分:5)

以下适用于Ubuntu 8.04,Gnome(基于对this forum的评论):

#!/bin/bash
gvim

sleep 1  # give gvim time to launch

wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz

您可能需要安装wmctrl

sudo apt-get install wmctrl

答案 1 :(得分:2)

您可以使用-geom(etry)选项将大小与显示器的大小相匹配。

gvim -geom 200x50+0+0

200是水平放置的字符数,50垂直相同,+0+0表示屏幕左上角的水平和垂直偏移为零

请注意,窗口本身不会最大化,它只会(大约)与显示器大小相同。

答案 2 :(得分:0)

像@Curt Nelson一样,我使用wmctrlautocmdguienter。它适用于我的Windows 7和Ubuntu 13.10。

  1. 安装wmctrl:sudo apt-get install wmctrl
  2. 将以下脚本添加到您的配置中。
  3. 脚本:

    if has("gui_running")
        if MySys() == 'linux'
            autocmd GUIEnter * silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
        else
            winpos 0 0
            set lines=99999 columns=99999
            autocmd guienter * let &columns = 999 | let &columns = &columns/2 
            autocmd guienter * set lines=9999 columns=9999
        endif
    endif