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

Re: Left-align after separator on status line?

Expand Messages
  • Gary Johnson
    ... It s been a while since I wrote this, so I don t remember off-hand what all the format specifiers mean, but this statusline looks like the default
    Message 1 of 3 , May 1, 2010
    • 0 Attachment
      On 2010-04-30, Nathan Neff wrote:
      > Currently, I have the status line displaying Vim's
      > current working directory.
      >
      > I like having the cwd on the right side of the status line.
      >
      > I would like to align the cwd as far left to the separator
      > as possible, so that it doesn't shift around when I navigate
      > from column 1 to column 10, (likewise row 1 to row 10).
      >
      > I've tried many variations of the sprintf syntax, and can't get
      > the current working directory not to shift around depending on the
      > line # and col # that I'm on.
      >
      > Any ideas?
      >
      > function! MyStatusLine()
      > let l:statline = '%=' "left/right separator
      > let l:statline = l:statline . '%-20{" | " . fnamemodify(getcwd(),
      > ":t") . " | "}'
      > let l:statline = l:statline . '%l, %v of %L' "cursor line/total lines
      > return l:statline
      > endfunction
      >
      > " Status Line
      > set laststatus=2
      > set statusline=%!MyStatusLine()

      It's been a while since I wrote this, so I don't remember off-hand
      what all the format specifiers mean, but this 'statusline' looks
      like the default 'statusline' with 'ruler' set and with the addition
      of the name of the current function displayed at the right side of
      the status line, just left of the line and column numbers. The
      function name--the return value of TagName()--does not shift when
      the line and column numbers change. You should be able to replace
      TagName() with a function that returns the cwd and get the behavior
      you want.

      let &statusline='%<%f %(%h%m%r %)%=%{TagName()} %-15.15(%l,%c%V%)%P'

      Regards,
      Gary

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Nathan Neff
      ... Thank you very much -- this works exactly like I want! The foo in my status bar stays in the same column in both the situations below: foo line 100
      Message 2 of 3 , May 1, 2010
      • 0 Attachment
        On Sat, May 1, 2010 at 2:32 AM, Gary Johnson <garyjohn@...> wrote:
        > On 2010-04-30, Nathan Neff wrote:
        >> Currently, I have the status line displaying Vim's
        >> current working directory.
        >>
        >> I like having the cwd on the right side of the status line.
        >>
        >> I would like to align the cwd as far left to the separator
        >> as possible, so that it doesn't shift around when I navigate
        >> from column 1 to column 10, (likewise row 1 to row 10).
        >>
        >> I've tried many variations of the sprintf syntax, and can't get
        >> the current working directory not to shift around depending on the
        >> line # and col # that I'm on.
        >>
        >> Any ideas?
        >>
        >> function! MyStatusLine()
        >>     let l:statline = '%='                     "left/right separator
        >>     let l:statline = l:statline . '%-20{" | " . fnamemodify(getcwd(),
        >> ":t") . " | "}'
        >>     let l:statline = l:statline . '%l, %v of %L'      "cursor line/total lines
        >>     return l:statline
        >> endfunction
        >>
        >> " Status Line
        >> set laststatus=2
        >> set statusline=%!MyStatusLine()
        >
        > It's been a while since I wrote this, so I don't remember off-hand
        > what all the format specifiers mean, but this 'statusline' looks
        > like the default 'statusline' with 'ruler' set and with the addition
        > of the name of the current function displayed at the right side of
        > the status line, just left of the line and column numbers.  The
        > function name--the return value of TagName()--does not shift when
        > the line and column numbers change.  You should be able to replace
        > TagName() with a function that returns the cwd and get the behavior
        > you want.
        >
        >    let &statusline='%<%f %(%h%m%r %)%=%{TagName()} %-15.15(%l,%c%V%)%P'
        >
        > Regards,
        > Gary

        Thank you very much -- this works exactly like I want!

        The 'foo' in my status bar stays in the same column
        in both the situations below:

        foo line 100 column 200
        foo line 1 column 1

        Thanks again,
        --Nate

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      Your message has been successfully submitted and would be delivered to recipients shortly.