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

SUGGESTION: make "undo/redo" commands also show the "modified" status of the file?

Expand Messages
  • Jeffrey 'jf' Lim
    Not too sure whether this is a common use case or not, but I think the following would really be useful... And at most, it ll only take up one extra character*
    Message 1 of 10 , Sep 20, 2007
      Not too sure whether this is a common use case or not, but I think the
      following would really be useful... And at most, it'll only take up
      one extra character* in the "status message" (eg. "1 change; before
      #187 11:52:49") that you see whenever you do an undo, or a redo...

      I find myself having to constantly do a <C-g> when going through a
      file's history in order to find out the state in which the file was
      saved (was it saved 3 undo's back? or 5 undo's back?). If we could add
      a small little marker at the front (or the back - whatever) of the
      status message, that would be useful... Something like '[+]' for
      modified, and (???) '[]' for "non-modified"?

      Do you think this would be useful?


      *(well, maybe 3!!!)

      -jf

      --
      In the meantime, here is your PSA:
      "It's so hard to write a graphics driver that open-sourcing it would not help."
      -- Andrew Fear, Software Product Manager, NVIDIA Corporation
      http://kerneltrap.org/node/7228

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... With ... the status line will always be visible, even when there is only one window. When the buffer is modified , there is a [+] mark on the default
      Message 2 of 10 , Sep 20, 2007
        Jeffrey 'jf' Lim wrote:
        > Not too sure whether this is a common use case or not, but I think the
        > following would really be useful... And at most, it'll only take up
        > one extra character* in the "status message" (eg. "1 change; before
        > #187 11:52:49") that you see whenever you do an undo, or a redo...
        >
        > I find myself having to constantly do a <C-g> when going through a
        > file's history in order to find out the state in which the file was
        > saved (was it saved 3 undo's back? or 5 undo's back?). If we could add
        > a small little marker at the front (or the back - whatever) of the
        > status message, that would be useful... Something like '[+]' for
        > modified, and (???) '[]' for "non-modified"?
        >
        > Do you think this would be useful?
        >
        >
        > *(well, maybe 3!!!)
        >
        > -jf

        With

        :set laststatus=2

        the status line will always be visible, even when there is only one window.
        When the buffer is 'modified', there is a [+] mark on the default status line
        (and nothing for not modified).


        Best regards,
        Tony.
        --
        hundred-and-one symptoms of being an internet addict:
        12. You turn off your modem and get this awful empty feeling, like you just
        pulled the plug on a loved one.

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Cyril Slobin
        ... I found that [+] mark is too unnoticeable: my eye just doesn t catch it. So I put a simple autocommand in my _vimrc that changes the background color of
        Message 3 of 10 , Sep 21, 2007
          On 9/21/07, Tony Mechelynck <antoine.mechelynck@...> wrote:

          > When the buffer is 'modified', there is a [+] mark on the default status
          > line (and nothing for not modified).

          I found that [+] mark is too unnoticeable: my eye just doesn't catch
          it. So I put a simple autocommand in my _vimrc that changes the
          background color of the statusline itself from black to darkblue and
          back depending of "modified" state. Life became much better for me!

          --
          Cyril Slobin <slobin@...> `When I use a word,' Humpty Dumpty said,
          http://wagner.pp.ru/~slobin/ `it means just what I choose it to mean'

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Jeffrey 'jf' Lim
          ... thanks, guys!!! You truly are awesome. I don t know what I was doing before this - using vim (and being such a dedicated vim user at that!!!), and not
          Message 4 of 10 , Sep 21, 2007
            On 9/21/07, Cyril Slobin <slobin@...> wrote:
            >
            > On 9/21/07, Tony Mechelynck <antoine.mechelynck@...> wrote:
            >
            > > When the buffer is 'modified', there is a [+] mark on the default status
            > > line (and nothing for not modified).
            >
            > I found that [+] mark is too unnoticeable: my eye just doesn't catch
            > it. So I put a simple autocommand in my _vimrc that changes the
            > background color of the statusline itself from black to darkblue and
            > back depending of "modified" state. Life became much better for me!
            >

            thanks, guys!!! You truly are awesome. I don't know what I was doing
            before this - using vim (and being such a dedicated vim user at
            that!!!), and not subscribing to this list at all....

            say, Cyril, care to share that autocommand here?

            thanks...
            -jf

            --
            In the meantime, here is your PSA:
            "It's so hard to write a graphics driver that open-sourcing it would not help."
            -- Andrew Fear, Software Product Manager, NVIDIA Corporation
            http://kerneltrap.org/node/7228

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Cyril Slobin
            ... For WhenModified function let was_modified = 1 (skip) Called automagically in various conditions, set statusline color depending of &modified state
            Message 5 of 10 , Sep 21, 2007
              On 9/21/07, Jeffrey 'jf' Lim <jfs.world@...> wrote:

              > say, Cyril, care to share that autocommand here?

              " For WhenModified function
              let was_modified = 1

              (skip)

              " Called automagically in various conditions, set statusline color
              " depending of &modified state
              function! WhenModified()
              if &modified
              if !g:was_modified
              hi StatusLine ctermbg=DarkCyan guifg=DarkBlue
              hi StatusLineNC ctermbg=DarkCyan guifg=DarkBlue
              let g:was_modified = 1
              endif
              else
              if g:was_modified
              hi StatusLine ctermbg=NONE guifg=NONE
              hi StatusLineNC ctermbg=NONE guifg=NONE
              let g:was_modified = 0
              endif
              endif
              endfunction

              (skip)

              autocmd BufReadPost,BufWritePost,CursorMoved,CursorMovedI,WinEnter *
              \ call WhenModified()

              These three pieces of code are actually in three different spots of my
              _vimrc, but they are logically the parts of one meaningful sequence.

              If you have noticed that I set FOREground for gui but BACKground for
              a text terminal: this is a workaround for what seems to be a bug in
              dos32 version of Vim. If you are not using dos32, you probably need
              to set ctermfg instead for ctermbg -- but I have not tested this!

              If someone is curious: my whole _vimrc is at:

              http://wagner.pp.ru/~slobin/vim/_vimrc.html

              --
              Cyril Slobin <slobin@...> `When I use a word,' Humpty Dumpty said,
              http://wagner.pp.ru/~slobin/ `it means just what I choose it to mean'

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Jeffrey 'jf' Lim
              ... this seems to be a problem as well on Linux? cterm bg , and cterm fg are switched around.... Thanks for the code though, btw! -jf -- In the meantime, here
              Message 6 of 10 , Sep 23, 2007
                On 9/22/07, Cyril Slobin <slobin@...> wrote:
                >
                > " Called automagically in various conditions, set statusline color
                > " depending of &modified state
                > function! WhenModified()
                > if &modified
                > if !g:was_modified
                > hi StatusLine ctermbg=DarkCyan guifg=DarkBlue
                > hi StatusLineNC ctermbg=DarkCyan guifg=DarkBlue
                > let g:was_modified = 1
                > endif
                > else
                > if g:was_modified
                > hi StatusLine ctermbg=NONE guifg=NONE
                > hi StatusLineNC ctermbg=NONE guifg=NONE
                > let g:was_modified = 0
                > endif
                > endif
                > endfunction
                >
                > (skip)
                >
                > autocmd BufReadPost,BufWritePost,CursorMoved,CursorMovedI,WinEnter *
                > \ call WhenModified()
                >
                > These three pieces of code are actually in three different spots of my
                > _vimrc, but they are logically the parts of one meaningful sequence.
                >
                > If you have noticed that I set FOREground for gui but BACKground for
                > a text terminal: this is a workaround for what seems to be a bug in
                > dos32 version of Vim. If you are not using dos32, you probably need
                > to set ctermfg instead for ctermbg -- but I have not tested this!
                >

                this seems to be a problem as well on Linux? cterm"bg", and cterm"fg"
                are switched around.... Thanks for the code though, btw!

                -jf

                --
                In the meantime, here is your PSA:
                "It's so hard to write a graphics driver that open-sourcing it would not help."
                -- Andrew Fear, Software Product Manager, NVIDIA Corporation
                http://kerneltrap.org/node/7228

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Jeffrey 'jf' Lim
                ... oh, and btw - I realize this doesn t work as expected with multiple buffers open? The change in the statusline seems to only affect the current buffer
                Message 7 of 10 , Sep 23, 2007
                  On 9/24/07, Jeffrey 'jf' Lim <jfs.world@...> wrote:
                  > On 9/22/07, Cyril Slobin <slobin@...> wrote:
                  > >
                  > > " Called automagically in various conditions, set statusline color
                  > > " depending of &modified state
                  > > function! WhenModified()
                  > > if &modified
                  > > if !g:was_modified
                  > > hi StatusLine ctermbg=DarkCyan guifg=DarkBlue
                  > > hi StatusLineNC ctermbg=DarkCyan guifg=DarkBlue
                  > > let g:was_modified = 1
                  > > endif
                  > > else
                  > > if g:was_modified
                  > > hi StatusLine ctermbg=NONE guifg=NONE
                  > > hi StatusLineNC ctermbg=NONE guifg=NONE
                  > > let g:was_modified = 0
                  > > endif
                  > > endif
                  > > endfunction
                  > >
                  > > (skip)
                  > >
                  > > autocmd BufReadPost,BufWritePost,CursorMoved,CursorMovedI,WinEnter *
                  > > \ call WhenModified()
                  > >
                  > > These three pieces of code are actually in three different spots of my
                  > > _vimrc, but they are logically the parts of one meaningful sequence.
                  > >
                  > > If you have noticed that I set FOREground for gui but BACKground for
                  > > a text terminal: this is a workaround for what seems to be a bug in
                  > > dos32 version of Vim. If you are not using dos32, you probably need
                  > > to set ctermfg instead for ctermbg -- but I have not tested this!
                  > >
                  >
                  > this seems to be a problem as well on Linux? cterm"bg", and cterm"fg"
                  > are switched around.... Thanks for the code though, btw!
                  >

                  oh, and btw - I realize this doesn't work as expected with multiple
                  buffers open? The change in the statusline seems to only affect the
                  "current" buffer which the cursor is in... So it's not possible in
                  that sense, to have a "quick overview" of which buffers have changed
                  based on the statusline color...

                  -jf

                  --
                  In the meantime, here is your PSA:
                  "It's so hard to write a graphics driver that open-sourcing it would not help."
                  -- Andrew Fear, Software Product Manager, NVIDIA Corporation
                  http://kerneltrap.org/node/7228

                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Tony Mechelynck
                  ... You would need a custom statusline then. Maybe grab the User1 highlight group to highlight the [+] differently than the rest in the status line
                  Message 8 of 10 , Sep 23, 2007
                    Jeffrey 'jf' Lim wrote:
                    > On 9/24/07, Jeffrey 'jf' Lim <jfs.world@...> wrote:
                    >> On 9/22/07, Cyril Slobin <slobin@...> wrote:
                    >>> " Called automagically in various conditions, set statusline color
                    >>> " depending of &modified state
                    >>> function! WhenModified()
                    >>> if &modified
                    >>> if !g:was_modified
                    >>> hi StatusLine ctermbg=DarkCyan guifg=DarkBlue
                    >>> hi StatusLineNC ctermbg=DarkCyan guifg=DarkBlue
                    >>> let g:was_modified = 1
                    >>> endif
                    >>> else
                    >>> if g:was_modified
                    >>> hi StatusLine ctermbg=NONE guifg=NONE
                    >>> hi StatusLineNC ctermbg=NONE guifg=NONE
                    >>> let g:was_modified = 0
                    >>> endif
                    >>> endif
                    >>> endfunction
                    >>>
                    >>> (skip)
                    >>>
                    >>> autocmd BufReadPost,BufWritePost,CursorMoved,CursorMovedI,WinEnter *
                    >>> \ call WhenModified()
                    >>>
                    >>> These three pieces of code are actually in three different spots of my
                    >>> _vimrc, but they are logically the parts of one meaningful sequence.
                    >>>
                    >>> If you have noticed that I set FOREground for gui but BACKground for
                    >>> a text terminal: this is a workaround for what seems to be a bug in
                    >>> dos32 version of Vim. If you are not using dos32, you probably need
                    >>> to set ctermfg instead for ctermbg -- but I have not tested this!
                    >>>
                    >> this seems to be a problem as well on Linux? cterm"bg", and cterm"fg"
                    >> are switched around.... Thanks for the code though, btw!
                    >>
                    >
                    > oh, and btw - I realize this doesn't work as expected with multiple
                    > buffers open? The change in the statusline seems to only affect the
                    > "current" buffer which the cursor is in... So it's not possible in
                    > that sense, to have a "quick overview" of which buffers have changed
                    > based on the statusline color...
                    >
                    > -jf

                    You would need a custom 'statusline' then. Maybe grab the User1 highlight
                    group to highlight the [+] differently than the rest in the status line
                    regardless of whether the buffer is current or not. I happen to have a custom
                    status line which is only slightly "enhanced" compared to the default; let's
                    try adding this feature to it:


                    if has('statusline')
                    set statusline=%<%f\ %h%1*%m%*%r%=%k[%{(&fenc\ ==\
                    \"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %-12.(%l,%c%V%)\ %P
                    hi User1 cterm=NONE,bold ctermbg=red gui=NONE,bold guibg=red
                    endif



                    The ":set" line is one long line even if your mailer or mine added spurious
                    linebreaks. The relevant part is %1*%m%*


                    Best regards,
                    Tony.
                    --
                    "That must be wonderful! I don't understand it at all."

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • Cyril Slobin
                    ... Three months passed, and I have done this at last! Tony s suggestion is not very useful for me: I want the whole statusline to change color, not the [+]
                    Message 9 of 10 , Dec 31, 2007
                      Tony Mechelynck wrote:
                      > When the buffer is 'modified', there is a [+] mark on the default
                      > status line (and nothing for not modified).

                      Cyril Slobin wrote:
                      > I found that [+] mark is too unnoticeable: my eye just doesn't catch
                      > it. So I put a simple autocommand in my _vimrc that changes the
                      > background color of the statusline itself from black to darkblue and
                      > back depending of "modified" state. Life became much better for me!

                      Jeffrey 'jf' Lim wrote:
                      > oh, and btw - I realize this doesn't work as expected with multiple
                      > buffers open? The change in the statusline seems to only affect the
                      > "current" buffer which the cursor is in... So it's not possible in
                      > that sense, to have a "quick overview" of which buffers have changed
                      > based on the statusline color...

                      Tony Mechelynck wrote:
                      > You would need a custom 'statusline' then. Maybe grab the User1
                      > highlight group to highlight the [+] differently than the rest
                      > in the status line regardless of whether the buffer is current
                      > or not.

                      Three months passed, and I have done this at last! Tony's suggestion is
                      not very useful for me: I want the whole statusline to change color, not
                      the [+] flag only. The solution is to make `statusline` option local and
                      to change it on the fly. Here is a quotation from my _vimrc file:

                      " Modified statusline color and default status
                      hi User1 ctermbg=DarkCyan ctermfg=Black gui=Bold guibg=DarkBlue guifg=White
                      let was_modified = 1

                      " Called automagically in various conditions, set statusline color
                      " depending of &modified state
                      function! WhenModified()
                      if &modified
                      if !g:was_modified
                      setlocal statusline=%1*%t\ %L\ %y%r[%{&tw}]%=\ (%{phase})\ %{Lang()}
                      \\ %{Icon()}\ %{&fenc}\ %m\ %-15(%{HexDec()}%)%-10(%l,%v%)%P
                      let g:was_modified = 1
                      endif
                      else
                      if g:was_modified
                      setlocal statusline=%0*%t\ %L\ %y%r[%{&tw}]%=\ (%{phase})\ %{Lang()}
                      \\ %{Icon()}\ %{&fenc}\ %m\ %-15(%{HexDec()}%)%-10(%l,%v%)%P
                      let g:was_modified = 0
                      endif
                      endif
                      endfunction

                      " Magic autocommands installed here
                      autocmd!
                      autocmd BufReadPost,BufWritePost,CursorMoved,CursorMovedI,WinEnter *
                      \ call WhenModified()

                      Some lines may be wrapped by your (or mine) mailer, I hope you can
                      guess where to join them back. My statusline is rather kinky, you
                      don't need to copy it in whole: only %1* and %0* at the very beginning
                      are relevant here.

                      Vim hacking is a nice thing at the New Year night! ;-)

                      --
                      Cyril Slobin <slobin@...> `When I use a word,' Humpty Dumpty said,
                      http://wagner.pp.ru/~slobin/ `it means just what I choose it to mean'

                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • A.Politz
                      ... This might be a good place for the %! operator. ... hi User1 ctermbg=DarkCyan ctermfg=Black gui=Bold guibg=DarkBlue guifg=White au BufNewFile,BufRead *
                      Message 10 of 10 , Jan 1, 2008
                        Cyril Slobin wrote:

                        >Tony Mechelynck wrote:
                        >
                        >
                        >>When the buffer is 'modified', there is a [+] mark on the default
                        >>status line (and nothing for not modified).
                        >>
                        >>
                        >
                        >Cyril Slobin wrote:
                        >
                        >
                        >>I found that [+] mark is too unnoticeable: my eye just doesn't catch
                        >>it. So I put a simple autocommand in my _vimrc that changes the
                        >>background color of the statusline itself from black to darkblue and
                        >>back depending of "modified" state. Life became much better for me!
                        >>
                        >>
                        >
                        >Jeffrey 'jf' Lim wrote:
                        >
                        >
                        >>oh, and btw - I realize this doesn't work as expected with multiple
                        >>buffers open? The change in the statusline seems to only affect the
                        >>"current" buffer which the cursor is in... So it's not possible in
                        >>that sense, to have a "quick overview" of which buffers have changed
                        >>based on the statusline color...
                        >>
                        >>
                        >
                        >Tony Mechelynck wrote:
                        >
                        >
                        >>You would need a custom 'statusline' then. Maybe grab the User1
                        >>highlight group to highlight the [+] differently than the rest
                        >>in the status line regardless of whether the buffer is current
                        >>or not.
                        >>
                        >>
                        >
                        >Three months passed, and I have done this at last! Tony's suggestion is
                        >not very useful for me: I want the whole statusline to change color, not
                        >the [+] flag only. The solution is to make `statusline` option local and
                        >to change it on the fly. Here is a quotation from my _vimrc file:
                        >
                        >" Modified statusline color and default status
                        >hi User1 ctermbg=DarkCyan ctermfg=Black gui=Bold guibg=DarkBlue guifg=White
                        >let was_modified = 1
                        >
                        >" Called automagically in various conditions, set statusline color
                        >" depending of &modified state
                        >function! WhenModified()
                        > if &modified
                        > if !g:was_modified
                        > setlocal statusline=%1*%t\ %L\ %y%r[%{&tw}]%=\ (%{phase})\ %{Lang()}
                        > \\ %{Icon()}\ %{&fenc}\ %m\ %-15(%{HexDec()}%)%-10(%l,%v%)%P
                        > let g:was_modified = 1
                        > endif
                        > else
                        > if g:was_modified
                        > setlocal statusline=%0*%t\ %L\ %y%r[%{&tw}]%=\ (%{phase})\ %{Lang()}
                        > \\ %{Icon()}\ %{&fenc}\ %m\ %-15(%{HexDec()}%)%-10(%l,%v%)%P
                        > let g:was_modified = 0
                        > endif
                        > endif
                        >endfunction
                        >
                        >" Magic autocommands installed here
                        >autocmd!
                        >autocmd BufReadPost,BufWritePost,CursorMoved,CursorMovedI,WinEnter *
                        > \ call WhenModified()
                        >
                        >Some lines may be wrapped by your (or mine) mailer, I hope you can
                        >guess where to join them back. My statusline is rather kinky, you
                        >don't need to copy it in whole: only %1* and %0* at the very beginning
                        >are relevant here.
                        >
                        >Vim hacking is a nice thing at the New Year night! ;-)
                        >
                        >
                        >

                        This might be a good place for the '%!' operator.

                        --------------%<------------------
                        hi User1 ctermbg=DarkCyan ctermfg=Black gui=Bold guibg=DarkBlue guifg=White
                        au BufNewFile,BufRead * exec "setl
                        stl=%!'%'.(getbufvar(".expand('<abuf>').",'&modified')).'*Modified?'"
                        --------------%<------------------

                        Though the three fold evaluation looks a bit scary.
                        Note : It won't work in versions older than a couple of months, because
                        of a bug.

                        -ap


                        --
                        Ich hab geträumt, der Krieg wär vorbei.


                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_use" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      Your message has been successfully submitted and would be delivered to recipients shortly.