Loading ...
Sorry, an error occurred while loading the content.

Re: GVIM: start gvim with the same size and position as when closed in the session before

Expand Messages
  • Jingzhao Ou
    Hi, Antoine, I have problems using your script on Windows XP. I need to change the following au VimLeave call SaveXY() au VimEnter if
    Message 1 of 8 , Feb 2, 2005
    • 0 Attachment
      Hi, Antoine,

      I have problems using your script on Windows XP. I need to change the
      following

      au VimLeave call SaveXY()
      au VimEnter if filereadable("~/setwin.vim")

      to

      au VimLeave * call SaveXY()
      au GUIEnter * if filereadable("~/setwin.vim")

      in order to make it work properly. Also, I changed VimEnter to GUIEnter
      as I found out that GUIEnter works more smoothly than VimEnter when I
      open gvim.

      Nice script! Helpful in my case. Thanks a lot!

      Jingzhao Ou ( a Tcl guy )

      Antoine J. Mechelynck wrote:
      > bernhard esslinger wrote:
      >
      >> Hello,
      >>
      >> I am using gvim 6.3.
      >>
      >> I'd appreciate very much if someone can tell me how to achieve the
      >> following behavior of the gvim window:
      >>
      >> When I open gvim I first move it to a special place on my screen and
      >> then I change it to a bigger size than it opens by default.
      >> When I close gvim and open it later, it has again its default position
      >> and size.
      >> How can I manage that gvim starts using the same position and size it
      >> had when closing it before.
      >>
      >> Because I am new on this mailing list: Is this a question for this
      >> mailing list or for vim-dev ?
      >>
      >> Best regards, Bernhard
      >> ______________________________________________________________
      >> Verschicken Sie romantische, coole und witzige Bilder per SMS!
      >> Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
      >>
      >>
      >>
      >>
      >
      > Add the following (untested) to your vimrc:
      >
      > func SaveXY()
      > let x0=getwinposx()
      > let y0=getwinposy()
      > redir! > ~/setwin.vim
      > silent echo "winpos" x0 y0
      > silent echo "set lines=" . &lines
      > silent echo "set columns=" . &columns
      > redir END
      > endfunc
      > au VimLeave call SaveXY()
      > au VimEnter if filereadable("~/setwin.vim")
      > \ | source ~/setwin.vim
      > \ | endif
      >
      >
      > There must be no whitespace to the left of the endfunction command.
      >
      > See
      > :help :function
      > :help :endfunction
      > :help :winpos
      > :help getwinposx()
      > :help getwinposy()
      > :help 'lines'
      > :help 'columns'
      > :help :redir
      > :help :silent
      > :help :echo
      > :help :autocmd
      > :help VimLeave
      > :help VimEnter
      > :help filereadable()
      >
      > HTH,
      > Tony.
      >
      >
    • Antoine J. Mechelynck
      ... Oops, yes, I forgot the autocommand pattern. ... GUIEnter is called before VimEnter at startup, but only for a GUI session, so yours is an elegant
      Message 2 of 8 , Feb 2, 2005
      • 0 Attachment
        Jingzhao Ou wrote:
        > Hi, Antoine,
        >
        > I have problems using your script on Windows XP. I need to change the
        > following
        >
        > au VimLeave call SaveXY()
        > au VimEnter if filereadable("~/setwin.vim")
        >
        > to
        >
        > au VimLeave * call SaveXY()
        > au GUIEnter * if filereadable("~/setwin.vim")

        Oops, yes, I forgot the autocommand pattern.
        >
        > in order to make it work properly. Also, I changed VimEnter to GUIEnter
        > as I found out that GUIEnter works more smoothly than VimEnter when I
        > open gvim.

        GUIEnter is called before VimEnter at startup, but only for a GUI
        session, so yours is an elegant solution, which makes the test on
        has("gui_running") unnecessary.
        >
        > Nice script! Helpful in my case. Thanks a lot!

        My pleasure. Did you notice that other post, showing how to save the
        window settings in the vimifo file?
        >
        > Jingzhao Ou ( a Tcl guy )
        [...]

        Best regards,
        Tony.
      • David Fishburn
        ... This is the version I use since I want each *instance* of gvim to remember is previous position and size. I often have multiple gvims running for different
        Message 3 of 8 , Feb 9, 2005
        • 0 Attachment
          > -----Original Message-----
          > From: drchip@... [mailto:drchip@...]
          > Sent: Wednesday, February 02, 2005 12:08 PM
          > To: bernhard esslinger
          > Cc: vim@...
          > Subject: Re: GVIM: start gvim with the same size and position
          > as when closed in the session before
          >
          > Quoting bernhard esslinger <besslinger@...>:
          >
          >
          > > When I open gvim I first move it to a special place on my
          > screen and
          > > then I change it to a bigger size than it opens by default.
          > > When I close gvim and open it later, it has again its
          > default position
          > > and size.
          > > How can I manage that gvim starts using the same position
          > and size it
          > > had when closing it before.
          >
          > Other posters have suggested saving information to a file and
          > using it to restore position and sizing already. The
          > following does that, but uses vim's builtin viminfo capability. With
          > set viminfo=!,'25,\"100,:20,%,n~/.viminfo
          > in your <.vimrc>, the following code will save/restore gui
          > size and position:
          > (tested)
          >
          > " restore last position and sizing
          > au VimLeavePre * call RetainPosnSz()
          > au VimEnter * call RestorePosnSz()
          >
          > fun! RetainPosnSz()
          > let g:GVIM_POSX = getwinposx()
          > let g:GVIM_POSY = getwinposy()
          > let g:GVIM_SIZX = &columns
          > let g:GVIM_SIZY = &lines
          > endfun
          >
          > fun! RestorePosnSz()
          > if has("gui_running") && exists("g:GVIM_SIZX")
          > exe "set lines=".g:GVIM_SIZY
          > exe "set columns=".g:GVIM_SIZX
          > exe "winpos ".g:GVIM_POSX." ".g:GVIM_POSY
          > endif
          > endfun
          >

          This is the version I use since I want each *instance* of gvim to remember
          is previous position and size.

          I often have multiple gvims running for different projects, and only load
          files into a particular gvim.

          " Restore screen size and position
          " Courtesy of Steve Hall [ digitect@... ]
          " Modified by David Fishburn to base it on gvim servername
          if has("gui_running")
          function! Screen_init()
          " - Remembers and restores winposition, columns and lines stored in
          " global variables written to viminfo
          " - Must follow font settings so that columns and lines are accurate
          " based on font size.

          " initialize
          if !exists("g:COLS_".v:servername)
          let g:COLS_{v:servername} = &columns
          endif
          if !exists("g:LINES_".v:servername)
          let g:LINES_{v:servername} = &lines
          endif
          if !exists("g:WINPOSX_".v:servername)
          " don't set to 0, let window manager decide
          let g:WINPOSX_{v:servername} = ""
          endif
          if !exists("g:WINPOSY_".v:servername)
          " don't set to 0, let window manager decide
          let g:WINPOSY_{v:servername} = ""
          endif

          " set
          execute "set columns=".g:COLS_{v:servername}
          execute "set lines=".g:LINES_{v:servername}
          execute "winpos ".g:WINPOSX_{v:servername}."
          ".g:WINPOSY_{v:servername}

          endfunction

          function! Screen_get()
          " used on exit to retain window position and size

          let g:COLS_{v:servername} = &columns
          let g:LINES_{v:servername} = &lines

          let g:WINPOSX_{v:servername} = getwinposx()
          " filter negative error condition
          if g:WINPOSX_{v:servername} < 0
          let g:WINPOSX_{v:servername} = 0
          endif

          let g:WINPOSY_{v:servername} = getwinposy()
          " filter negative error condition
          if g:WINPOSY_{v:servername} < 0
          let g:WINPOSY_{v:servername} = 0
          endif

          endfunction

          " autocmd VimEnter * breakadd func Screen_init
          autocmd VimEnter * call Screen_init()
          autocmd VimLeavePre * call Screen_get()
          endif


          HTH,
          Dave

          --
          Do you use Vim to edit SQL?
          <Plug>
          Check the description of these plugins:
          dbext.vim - Provides database access to 10 databases (Oracle, Sybase, SQL
          Server, MySQL,...) (http://www.vim.org/scripts/script.php?script_id=356)
          SQLUtilities - Formatting SQL, generate - columns lists, procedures for
          databases (http://www.vim.org/scripts/script.php?script_id=492)
          sql.vim - SQL indent file for Sybase ASA and Oracle
          (http://www.vim.org/scripts/script.php?script_id=495)
          Intellisense for Vim : SQL, C++, CSharp, Java, JSP, XML, HTML
          (http://www.vim.org/scripts/script.php?script_id=747)
          </Plug>
        Your message has been successfully submitted and would be delivered to recipients shortly.