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

Re: Window Size in gVim

Expand Messages
  • Steve Hall
    From: Dempsey Darrow, Oct 24, 2003 4:34 PM ... Below is an (untested) abbreviation of something I use. Just make sure ! is included in your viminfo (:help
    Message 1 of 5 , Oct 24 2:58 PM
      From: Dempsey Darrow, Oct 24, 2003 4:34 PM
      >
      > Is there a way to have the product remember its GUI window size so
      > that the next time it's opened the window is the same size as when I
      > last exited gVim?

      Below is an (untested) abbreviation of something I use. Just make sure
      "!" is included in your viminfo (:help 'viminfo) so the globals get
      retained across sessions.

      HTH.

      --
      Steve Hall [ digitect@... ]

      ---------------------------------------------------------------------
      function! Screen_init()
      " o Remembers and restores winposition, columns and lines stored in
      " global variables written to viminfo
      " o Must follow font settings so that columns and lines are accurate
      " based on font size.

      " initialize
      if !exists("g:COLS")
      let g:COLS = 80
      endif
      if !exists("g:LINES")
      let g:LINES = 30
      endif
      if !exists("g:WINPOSX")
      " don't set to 0, let window manager decide
      let g:WINPOSX = ""
      endif
      if !exists("g:WINPOSY")
      " don't set to 0, let window manager decide
      let g:WINPOSY = ""
      endif

      " set
      execute "set columns=" . g:COLS
      execute "set lines=" . g:LINES
      execute "winpos " . g:WINPOSX . " " . g:WINPOSY

      endfunction

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

      let g:COLS = &columns
      let g:LINES = &lines

      let g:WINPOSX = getwinposx()
      " filter negative error condition
      if g:WINPOSX < 0
      let g:WINPOSX = 0
      endif

      let g:WINPOSY = getwinposy()
      " filter negative error condition
      if g:WINPOSY < 0
      let g:WINPOSY = 0
      endif

      endfunction

      autocmd VimEnter * call Screen_init()
      autocmd VimLeavePre * call Screen_get()
      ---------------------------------------------------------------------
    • David Fishburn
      Steve, I am pretty sure I can make good use of these functions, thank you. I have also updated them. I often name my gvim sessions, so that I open related
      Message 2 of 5 , Oct 31 11:35 AM
        Steve,

        I am pretty sure I can make good use of these functions, thank you.

        I have also updated them.

        I often name my gvim sessions, so that I open related files in 1 vim (ie
        all the files for one project, or newsgroup postings, or email, ...).

        So I wanted to be able to store / recall the position of the gvim window
        based on the NAME of the gvim session.
        For people already using these functions they should see no difference
        (except if they use multiple gvims.

        These modified versions work this way.
        Also instead of hard coding defaults, I let the defaults be the current
        &lines and &columns.

        *******************
        " Courtesy of Steve Hall [ digitect@... ]
        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()
        ******************


        Dave
      Your message has been successfully submitted and would be delivered to recipients shortly.