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

Setting window center line in autocommands

Expand Messages
  • Haakon Riiser
    I use BufNewFile autocommands to read in skeletons for several types of files, and I often like to place the cursor on a particular line initially. This is
    Message 1 of 28 , Dec 7, 2003
    • 0 Attachment
      I use BufNewFile autocommands to read in skeletons for several
      types of files, and I often like to place the cursor on a
      particular line initially. This is easily accomplished using a
      simple :<number> command. However, I would also prefer to have
      this line be the center line in the window, not the bottom line
      as is often the case. I thought I could solve it by putting

      normal zz

      after the :<number> command, but it has no effect. :-(
      Any suggestions? Thanks in advance!

      --
      Haakon
    • Benji Fisher
      ... I just tried ... and it worked as expected. Maybe we need more details about your autocommands. Or maybe you can figureo out the problem yourself with
      Message 2 of 28 , Dec 7, 2003
      • 0 Attachment
        On Sun, Dec 07, 2003 at 12:38:08PM +0100, Haakon Riiser wrote:
        > I use BufNewFile autocommands to read in skeletons for several
        > types of files, and I often like to place the cursor on a
        > particular line initially. This is easily accomplished using a
        > simple :<number> command. However, I would also prefer to have
        > this line be the center line in the window, not the bottom line
        > as is often the case. I thought I could solve it by putting
        >
        > normal zz
        >
        > after the :<number> command, but it has no effect. :-(
        > Any suggestions? Thanks in advance!

        I just tried

        :au BufNewFile *.vim r ~/.vimrc | 66 | normal zz
        :e temp.vim

        and it worked as expected. Maybe we need more details about your
        autocommands. Or maybe you can figureo out the problem yourself with

        :set verbose=9
        :help 'verbose'

        HTH --Benji Fisher
      • Haakon Riiser
        [Benji Fisher] ... I did some testing, and it looks like it depends on the number of lines in the skeleton file. Using a long file, the command appears to
        Message 3 of 28 , Dec 7, 2003
        • 0 Attachment
          [Benji Fisher]

          > I just tried
          >
          > :au BufNewFile *.vim r ~/.vimrc | 66 | normal zz
          > :e temp.vim
          >
          > and it worked as expected. Maybe we need more details about your
          > autocommands.

          I did some testing, and it looks like it depends on the number of
          lines in the skeleton file. Using a long file, the command appears
          to work. The following example triggers the bug here: Create a
          25 line skeleton file (~/test.skel), and use the following autocmd:

          au BufNewFile *.xxx r ~/test.skel | 22 | normal zz

          The cursor line is not centered on Vim v6.2.154

          > Or maybe you can figureo out the problem yourself with
          >
          > :set verbose=9
          > :help 'verbose'

          I skimmed through it, but couldn't find anything. I'll do it more
          thoroughly if I can't figure it out.

          --
          Haakon
        • Antoine J. Mechelynck
          ... This is 3 lines above the end-of-file. I would then expect the last lline of the file to appear on the last file of the window. Similarly, replace | 22 |
          Message 4 of 28 , Dec 7, 2003
          • 0 Attachment
            Haakon Riiser <haakon.riiser@...> wrote:
            > [Benji Fisher]
            >
            > > I just tried
            > >
            > > > au BufNewFile *.vim r ~/.vimrc | 66 | normal zz
            > > > e temp.vim
            > >
            > > and it worked as expected. Maybe we need more details about your
            > > autocommands.
            >
            > I did some testing, and it looks like it depends on the number of
            > lines in the skeleton file. Using a long file, the command appears
            > to work. The following example triggers the bug here: Create a
            > 25 line skeleton file (~/test.skel), and use the following autocmd:
            >
            > au BufNewFile *.xxx r ~/test.skel | 22 | normal zz
            >
            > The cursor line is not centered on Vim v6.2.154

            This is 3 lines above the end-of-file. I would then expect the last lline of
            the file to appear on the last file of the window.

            Similarly, replace | 22 | by | 3 | in your example, and the cursor will
            appear on the 3rd line, not centered in the file window.

            Regards,
            Tony.
          • Haakon Riiser
            [Antoine J. Mechelynck] ... No, that s not how the zz command behaves when used interactively. The cursor line should still be centered, and the lines below
            Message 5 of 28 , Dec 7, 2003
            • 0 Attachment
              [Antoine J. Mechelynck]

              >> The following example triggers the bug here: Create a
              >> 25 line skeleton file (~/test.skel), and use the following autocmd:
              >>
              >> au BufNewFile *.xxx r ~/test.skel | 22 | normal zz
              >>
              >> The cursor line is not centered on Vim v6.2.154
              >
              > This is 3 lines above the end-of-file. I would then expect the
              > last lline of the file to appear on the last file of the window.

              No, that's not how the zz command behaves when used interactively.

              The cursor line should still be centered, and the lines below
              the actual contents of the buffer should be '~'s highlighted
              as NonText. I'm sure you have already seen this. Read on.

              > Similarly, replace | 22 | by | 3 | in your example, and the
              > cursor will appear on the 3rd line, not centered in the file
              > window.

              That's different. Vim never shows NonText above the buffer, but
              it HAS to handle this below the buffer. When a buffer contains
              fewer lines than the height of the window, it has to fill the
              rest with something. As mentioned above, this is exactly how it is
              handled in interactive mode, so why doesn't it work when the command
              is issued from an autocommand?

              --
              Haakon
            • Benji Fisher
              ... [snip] Yes, I expect to see some lines of NonText, and that is what I do see. I used the same autocommand, except that I changed the name of the skeleton
              Message 6 of 28 , Dec 7, 2003
              • 0 Attachment
                On Mon, Dec 08, 2003 at 12:29:36AM +0100, Haakon Riiser wrote:
                > [Antoine J. Mechelynck]
                >
                > >> The following example triggers the bug here: Create a
                > >> 25 line skeleton file (~/test.skel), and use the following autocmd:
                > >>
                > >> au BufNewFile *.xxx r ~/test.skel | 22 | normal zz
                > >>
                > >> The cursor line is not centered on Vim v6.2.154
                > >
                > > This is 3 lines above the end-of-file. I would then expect the
                > > last lline of the file to appear on the last file of the window.
                >
                > No, that's not how the zz command behaves when used interactively.
                >
                > The cursor line should still be centered, and the lines below
                > the actual contents of the buffer should be '~'s highlighted
                > as NonText. I'm sure you have already seen this. Read on.
                [snip]

                Yes, I expect to see some lines of NonText, and that is what I do
                see. I used the same autocommand, except that I changed the name of the
                skeleton file.

                I do notice two oddities. First, despite the :r command, the
                'modified' option is not set. I am not sure if this is supposed to
                happen or not, but I would expect the buffer to be marked as modified.
                If I undo ("u" in Normal mode) then the lines from the skeleton file
                are removed, and 'modified' is still not set. I can then redo (<C-R>)
                and undo and ... and it is still not set.

                I figured out the second oddity: ":22 |" prints the 22nd line in
                the status area. If you remove the second | from the autocommand, it
                works a little more smoothly.

                --Benji Fisher
              • Haakon Riiser
                [Benji Fisher] ... Strange, that s not what happens for me. Using the 25-line skeleton file, the cursor line is always the bottom line in the window, even
                Message 7 of 28 , Dec 8, 2003
                • 0 Attachment
                  [Benji Fisher]

                  > On Mon, Dec 08, 2003 at 12:29:36AM +0100, Haakon Riiser wrote:
                  >>
                  >> The cursor line should still be centered, and the lines below
                  >> the actual contents of the buffer should be '~'s highlighted
                  >> as NonText.
                  >
                  > Yes, I expect to see some lines of NonText, and that is what I do
                  > see. I used the same autocommand, except that I changed the name of the
                  > skeleton file.

                  Strange, that's not what happens for me. Using the 25-line
                  skeleton file, the cursor line is always the bottom line in the
                  window, even when the autocmd ends with :normal zz

                  > I do notice two oddities. First, despite the :r command, the
                  > 'modified' option is not set. I am not sure if this is supposed to
                  > happen or not, but I would expect the buffer to be marked as modified.
                  > If I undo ("u" in Normal mode) then the lines from the skeleton file
                  > are removed, and 'modified' is still not set. I can then redo (<C-R>)
                  > and undo and ... and it is still not set.

                  I have noticed many strange things while trying to set up these
                  skeleton files. :-) For one, there's the bug I described in
                  vim-dev where :append, :insert and :change always insert an
                  extra blank line when the buffer is empty (the case for :append
                  and :insert) or when it contains less than two lines (:change).
                  Also, when you take a buffer consisting of multiple lines, delete
                  all lines but the first, and :change the last remaining line,
                  Vim inserts a blank line below the new text that is displayed
                  as NonText. In other words, it LOOKS like NonText, but BEHAVES
                  like a blank line (lets you move your cursor over it for example).

                  And something else that seems weird is that when I modify
                  the contents of the buffer with a substitute command in the
                  autocommand,

                  :%s/foo/bar/g

                  the undo history does not register this event. If I undo one
                  time, the substitute command is not undone, but the entire buffer
                  is emptied.

                  > I figured out the second oddity: ":22 |" prints the 22nd line in
                  > the status area. If you remove the second | from the autocommand, it
                  > works a little more smoothly.

                  When I first read this, I thought I didn't understand what you
                  were saying. Then I tried it out, and saw that you were right.
                  I also see this -- really strange though. The :<line-number>
                  command does not print anything in the status area when used
                  interactively, and the manual does not, as far as I can see,
                  mention any of this. Furthermore, why does it even _work_
                  when you remove the second '|'? It does not work that way in
                  interactive mode. Try typing

                  :22 normal zz

                  In interactive mode, Vim just says 'E16: Invalid range'.

                  --
                  Haakon
                • Benji Fisher
                  ... I agree that the problems I snipped look like bugs. I hope that Bram does not miss that note when he gets back from vacation. ... I cannot find an
                  Message 8 of 28 , Dec 8, 2003
                  • 0 Attachment
                    On Mon, Dec 08, 2003 at 12:09:19PM +0100, Haakon Riiser wrote:
                    > [Benji Fisher]

                    I agree that the problems I snipped look like bugs. I hope that
                    Bram does not miss that note when he gets back from vacation.

                    > > I figured out the second oddity: ":22 |" prints the 22nd line in
                    > > the status area. If you remove the second | from the autocommand, it
                    > > works a little more smoothly.
                    >
                    > When I first read this, I thought I didn't understand what you
                    > were saying. Then I tried it out, and saw that you were right.
                    > I also see this -- really strange though. The :<line-number>
                    > command does not print anything in the status area when used
                    > interactively, and the manual does not, as far as I can see,
                    > mention any of this.

                    I cannot find an explanation in the docs, but interactively,

                    :22 |

                    prints the 22'nd line in the status area.

                    > Furthermore, why does it even _work_
                    > when you remove the second '|'? It does not work that way in
                    > interactive mode. Try typing
                    >
                    > :22 normal zz
                    >
                    > In interactive mode, Vim just says 'E16: Invalid range'.

                    The :normal command is supposed to accept a range, and I do not get
                    an error message. Did you try that in a buffer with fewer than 22
                    lines?

                    :help :normal-range

                    HTH --Benji Fisher
                  • Keith Roberts
                    ... Did any one try: au BufNewFile *.xxx r ~/test.skel | normal 22zz or au BufNewFile *.xxx r ~/test.skel | normal 22z.
                    Message 9 of 28 , Dec 8, 2003
                    • 0 Attachment
                      >-----Original Message-----
                      >From: Haakon Riiser [mailto:haakon.riiser@...]
                      >Sent: Sunday, December 07, 2003 3:06 PM
                      >To: vim@...
                      >Subject: Re: Setting window center line in autocommands
                      >
                      >[snip]
                      >I did some testing, and it looks like it depends on the number of
                      >lines in the skeleton file. Using a long file, the command appears
                      >to work. The following example triggers the bug here: Create a
                      >25 line skeleton file (~/test.skel), and use the following autocmd:
                      >
                      > au BufNewFile *.xxx r ~/test.skel | 22 | normal zz
                      >
                      >The cursor line is not centered on Vim v6.2.154
                      >
                      >I skimmed through it, but couldn't find anything. I'll do it more
                      >thoroughly if I can't figure it out.

                      Did any one try:
                      au BufNewFile *.xxx r ~/test.skel | normal 22zz
                      or
                      au BufNewFile *.xxx r ~/test.skel | normal 22z.
                    • Benji Fisher
                      ... I did. All the variants I tried worked pretty much the same: the ... the modified flag. I do not know why it behaves differently for Haakon Riiser.
                      Message 10 of 28 , Dec 8, 2003
                      • 0 Attachment
                        On Mon, Dec 08, 2003 at 11:04:10AM -0800, Keith Roberts wrote:
                        > >-----Original Message-----
                        > >From: Haakon Riiser [mailto:haakon.riiser@...]
                        > >Sent: Sunday, December 07, 2003 3:06 PM
                        > >To: vim@...
                        > >Subject: Re: Setting window center line in autocommands
                        > >
                        > >[snip]
                        > >I did some testing, and it looks like it depends on the number of
                        > >lines in the skeleton file. Using a long file, the command appears
                        > >to work. The following example triggers the bug here: Create a
                        > >25 line skeleton file (~/test.skel), and use the following autocmd:
                        > >
                        > > au BufNewFile *.xxx r ~/test.skel | 22 | normal zz
                        > >
                        > >The cursor line is not centered on Vim v6.2.154
                        > >
                        > >I skimmed through it, but couldn't find anything. I'll do it more
                        > >thoroughly if I can't figure it out.
                        >
                        > Did any one try:
                        > au BufNewFile *.xxx r ~/test.skel | normal 22zz
                        > or
                        > au BufNewFile *.xxx r ~/test.skel | normal 22z.

                        I did. All the variants I tried worked pretty much the same: the
                        :normal command behaved as expected, but there were some oddities with
                        the 'modified' flag. I do not know why it behaves differently for
                        Haakon Riiser.

                        --Benji Fisher
                      • Christian J. Robinson
                        ... It s there, just not easy to spot. Do :help :bar and search for print . ... - Christian -- The old make the rules, the young make up the exceptions.
                        Message 11 of 28 , Dec 8, 2003
                        • 0 Attachment
                          Today (Mon, 8 Dec 2003), Benji Fisher wrote:

                          > I cannot find an explanation in the docs, but interactively,
                          >
                          > :22 |
                          >
                          > prints the 22'nd line in the status area.

                          It's there, just not easy to spot.

                          Do ":help :bar" and search for "print".

                          Because of Vi compatibility the following strange commands are supported:
                          :| print current line (like ":p")
                          :3| print line 3 (like ":3p")
                          :3 goto line 3

                          - Christian

                          --
                          The old make the rules, the young make up the exceptions.
                          Christian J. Robinson <infynity@...> http://infynity.spodzone.com/
                          PGP key: 0x893B0EAF / 0xFB698360 http://infynity.spodzone.com/pgp
                        • Haakon Riiser
                          [Benji Fisher] ... I also tried the above commands, and they make no difference. I have discovered more on this problem though. I think I found out why only I
                          Message 12 of 28 , Dec 9, 2003
                          • 0 Attachment
                            [Benji Fisher]

                            > On Mon, Dec 08, 2003 at 11:04:10AM -0800, Keith Roberts wrote:
                            >>
                            >> Did any one try:
                            >> au BufNewFile *.xxx r ~/test.skel | normal 22zz
                            >> or
                            >> au BufNewFile *.xxx r ~/test.skel | normal 22z.
                            >
                            > I did. All the variants I tried worked pretty much the same: the
                            > :normal command behaved as expected, but there were some oddities with
                            > the 'modified' flag. I do not know why it behaves differently for
                            > Haakon Riiser.

                            I also tried the above commands, and they make no difference.
                            I have discovered more on this problem though. I think I found
                            out why only I can't get the centering command to work -- the bug
                            only happens when the autocommand is executed while Vim is started
                            (Vim manages to center the line when I type ":e test.xxx"), and
                            you must say "filetype on" in your vimrc, after the autocommand.

                            Here's a minimal configuration that hopefully will reproduce it for
                            others as well:

                            - Make sure that ~/.vim/filetype.vim does NOT exist, or is empty

                            - Create a ~/.vimrc that contains only the following two lines,
                            (the filetype command MUST come after the autocommand):

                            au BufNewFile *.xxx r ~/test.skel | 22 normal zz
                            filetype on

                            Now, make ~/test.skel a long file (I was wrong earlier about the
                            length of the file affecting this -- my current ~/test.skel is 644
                            lines long, and I can still reproduce the bug).

                            Start Vim on a standard 24-line terminal (this is important):

                            vim test.xxx (as I said, ":e test.xxx" does _not_ trigger
                            the bug, so you must edit test.xxx on startup)

                            Result: the 22nd line is selected, but the cursor line is not in
                            the middle of the window. It looks like Vim tries to keep the
                            first line in the buffer visible, if possible. This means that
                            if you were to replace the arbitrary number "22" with something
                            bigger than the number of lines in your window, like 100, the
                            center command works. I'm guessing this is because it's not
                            possible to show the first line while at the same time displaying
                            the cursor line.

                            Am I still the only one seeing this?

                            --
                            Haakon
                          • Benji Fisher
                            ... Thanks. I did try :help :| but I did not read quite far enough. I guess this is related to :p being the default command for the :global command. --Benji
                            Message 13 of 28 , Dec 9, 2003
                            • 0 Attachment
                              On Mon, Dec 08, 2003 at 02:29:36PM -0700, Christian J. Robinson wrote:
                              > Today (Mon, 8 Dec 2003), Benji Fisher wrote:
                              >
                              > > I cannot find an explanation in the docs, but interactively,
                              > >
                              > > :22 |
                              > >
                              > > prints the 22'nd line in the status area.
                              >
                              > It's there, just not easy to spot.
                              >
                              > Do ":help :bar" and search for "print".
                              >
                              > Because of Vi compatibility the following strange commands are supported:
                              > :| print current line (like ":p")
                              > :3| print line 3 (like ":3p")
                              > :3 goto line 3
                              >
                              > - Christian

                              Thanks. I did try ":help :|" but I did not read quite far enough.
                              I guess this is related to :p being the default command for the :global
                              command.

                              --Benji Fisher
                            • Benji Fisher
                              ... No, I can now reproduce this. As you say, the order of the two lines in the vimrc file is important. Presumably, one of the default autocommands messes
                              Message 14 of 28 , Dec 9, 2003
                              • 0 Attachment
                                On Tue, Dec 09, 2003 at 07:27:32PM +0100, Haakon Riiser wrote:
                                >
                                > I also tried the above commands, and they make no difference.
                                > I have discovered more on this problem though. I think I found
                                > out why only I can't get the centering command to work -- the bug
                                > only happens when the autocommand is executed while Vim is started
                                > (Vim manages to center the line when I type ":e test.xxx"), and
                                > you must say "filetype on" in your vimrc, after the autocommand.
                                >
                                > Here's a minimal configuration that hopefully will reproduce it for
                                > others as well:
                                >
                                > - Make sure that ~/.vim/filetype.vim does NOT exist, or is empty
                                >
                                > - Create a ~/.vimrc that contains only the following two lines,
                                > (the filetype command MUST come after the autocommand):
                                >
                                > au BufNewFile *.xxx r ~/test.skel | 22 normal zz
                                > filetype on
                                >
                                > Now, make ~/test.skel a long file (I was wrong earlier about the
                                > length of the file affecting this -- my current ~/test.skel is 644
                                > lines long, and I can still reproduce the bug).
                                >
                                > Start Vim on a standard 24-line terminal (this is important):
                                >
                                > vim test.xxx (as I said, ":e test.xxx" does _not_ trigger
                                > the bug, so you must edit test.xxx on startup)
                                >
                                > Result: the 22nd line is selected, but the cursor line is not in
                                > the middle of the window. It looks like Vim tries to keep the
                                > first line in the buffer visible, if possible. This means that
                                > if you were to replace the arbitrary number "22" with something
                                > bigger than the number of lines in your window, like 100, the
                                > center command works. I'm guessing this is because it's not
                                > possible to show the first line while at the same time displaying
                                > the cursor line.
                                >
                                > Am I still the only one seeing this?

                                No, I can now reproduce this. As you say, the order of the two
                                lines in the vimrc file is important. Presumably, one of the
                                default autocommands messes things up. I do not have time to look at
                                this now, but you can try with

                                $ vim -u test.vimrc test.xxx
                                :redir END
                                :set verbose&
                                :e ~/vimlog.txt

                                where test.vimrc is the following file:

                                set nocp nomore verbose=20
                                au BufNewFile *.xxx r ~/test.skel | 22 normal zz
                                filetype on
                                redir! > ~/vimlog.txt

                                HTH --Benji Fisher
                              • Charles E. Campbell, Jr.
                                ... Nope -- I see it too. However, for what its worth, if you use M instead of zz it works... Regards, Chip Campbell
                                Message 15 of 28 , Dec 9, 2003
                                • 0 Attachment
                                  Haakon Riiser wrote:

                                  >Result: the 22nd line is selected, but the cursor line is not in
                                  >the middle of the window. It looks like Vim tries to keep the
                                  >first line in the buffer visible, if possible. This means that
                                  >if you were to replace the arbitrary number "22" with something
                                  >bigger than the number of lines in your window, like 100, the
                                  >center command works. I'm guessing this is because it's not
                                  >possible to show the first line while at the same time displaying
                                  >the cursor line.
                                  >
                                  >Am I still the only one seeing this?
                                  >
                                  >

                                  Nope -- I see it too. However, for what its worth, if you use M instead
                                  of zz
                                  it works...

                                  Regards,
                                  Chip Campbell
                                • Haakon Riiser
                                  [Benji Fisher] ... Thanks, I didn t know about the :redir command. This makes it much more comfortable to dig through the massive amount of messages produced
                                  Message 16 of 28 , Dec 10, 2003
                                  • 0 Attachment
                                    [Benji Fisher]

                                    > On Tue, Dec 09, 2003 at 07:27:32PM +0100, Haakon Riiser wrote:
                                    >>
                                    >> Am I still the only one seeing this?
                                    >
                                    > No, I can now reproduce this. As you say, the order of the two
                                    > lines in the vimrc file is important. Presumably, one of the
                                    > default autocommands messes things up. I do not have time to look at
                                    > this now, but you can try with
                                    >
                                    > $ vim -u test.vimrc test.xxx
                                    > :redir END
                                    > :set verbose&
                                    > :e ~/vimlog.txt
                                    >
                                    > where test.vimrc is the following file:
                                    >
                                    > set nocp nomore verbose=20
                                    > au BufNewFile *.xxx r ~/test.skel | 22 normal zz
                                    > filetype on
                                    > redir! > ~/vimlog.txt

                                    Thanks, I didn't know about the :redir command. This makes
                                    it much more comfortable to dig through the massive amount of
                                    messages produced in verbose mode. I'll look into it and post
                                    the results here if I learn anything.

                                    --
                                    Haakon
                                  • Haakon Riiser
                                    [Charles E. Campbell, Jr.] ... It makes the cursor line centered, yes, but it does not solve the other part, which is to place the cursor on a specific line
                                    Message 17 of 28 , Dec 10, 2003
                                    • 0 Attachment
                                      [Charles E. Campbell, Jr.]

                                      > Haakon Riiser wrote:
                                      >
                                      >> Result: the 22nd line is selected, but the cursor line is not in
                                      >> the middle of the window. It looks like Vim tries to keep the
                                      >> first line in the buffer visible, if possible. This means that
                                      >> if you were to replace the arbitrary number "22" with something
                                      >> bigger than the number of lines in your window, like 100, the
                                      >> center command works. I'm guessing this is because it's not
                                      >> possible to show the first line while at the same time displaying
                                      >> the cursor line.
                                      >>
                                      >> Am I still the only one seeing this?
                                      >
                                      > Nope -- I see it too. However, for what its worth, if you use
                                      > M instead of zz it works...

                                      It makes the cursor line centered, yes, but it does not solve
                                      the other part, which is to place the cursor on a specific line
                                      (line 22 in my examples).

                                      --
                                      Haakon
                                    • Charles E. Campbell, Jr.
                                      ... au BufNewFile *.xxx r ~/test.skel | norm! 22z.M Regards, Chip Campbell
                                      Message 18 of 28 , Dec 10, 2003
                                      • 0 Attachment
                                        Charles E. Campbell, Jr. wrote:
                                        >Nope -- I see it too. However, for what its worth, if you use
                                        >M instead of zz it works...

                                        Haakon Riiser wrote:
                                        >It makes the cursor line centered, yes, but it does not solve
                                        >the other part, which is to place the cursor on a specific line
                                        >(line 22 in my examples).
                                        ---------------------------------------------------------------------

                                        au BufNewFile *.xxx r ~/test.skel | norm! 22z.M

                                        Regards,
                                        Chip Campbell
                                      • Charles E. Campbell, Jr.
                                        ... I retract this suggestion. By the way, zt is even stranger in behavior than z. . Regards, Chip Campbell,
                                        Message 19 of 28 , Dec 10, 2003
                                        • 0 Attachment
                                          Charles E. Campbell, Jr. wrote:

                                          >
                                          > Nope -- I see it too. However, for what its worth, if you use M
                                          > instead of zz
                                          > it works...


                                          I retract this suggestion. By the way, zt is even stranger in behavior
                                          than z. .

                                          Regards,
                                          Chip Campbell,
                                        • Haakon Riiser
                                          [Charles E. Campbell, Jr.] ... This gives me exactly the same result as the same command without the M at the end -- the cursor line is not centered. -- Haakon
                                          Message 20 of 28 , Dec 10, 2003
                                          • 0 Attachment
                                            [Charles E. Campbell, Jr.]

                                            > Haakon Riiser wrote:
                                            >>
                                            >> It makes the cursor line centered, yes, but it does not solve
                                            >> the other part, which is to place the cursor on a specific line
                                            >> (line 22 in my examples).
                                            >
                                            > au BufNewFile *.xxx r ~/test.skel | norm! 22z.M

                                            This gives me exactly the same result as the same command without
                                            the M at the end -- the cursor line is not centered.

                                            --
                                            Haakon
                                          • Haakon Riiser
                                            [Charles E. Campbell, Jr.] ... Unlike those other commands, zt was supposed to make the cursor line the top line of the window. I replaced zz/z. with zt in
                                            Message 21 of 28 , Dec 10, 2003
                                            • 0 Attachment
                                              [Charles E. Campbell, Jr.]

                                              > Charles E. Campbell, Jr. wrote:
                                              >>
                                              >> Nope -- I see it too. However, for what its worth, if you use M
                                              >> instead of zz
                                              >> it works...
                                              >
                                              > I retract this suggestion. By the way, zt is even stranger in behavior
                                              > than z. .

                                              Unlike those other commands, zt was supposed to make the cursor
                                              line the top line of the window. I replaced zz/z. with zt in the
                                              cases where zz/z. do not work, and saw that zt actually produces
                                              the exact same result as zz and z. Do you see something else?

                                              By the way, does anyone know when Bram is back from his vacation? :-)

                                              --
                                              Haakon
                                            • Charles E. Campbell, Jr.
                                              ... Hello! I ve narrowed the problem down a bit; it turns out that setting cpo causes the problem. cpo gets set in (lines 27 and 294). Commenting
                                              Message 22 of 28 , Dec 10, 2003
                                              • 0 Attachment
                                                Haakon Riiser once wrote:
                                                > Result: the 22nd line is selected, but the cursor line is not in
                                                > the middle of the window...

                                                Hello!

                                                I've narrowed the problem down a bit; it turns out that setting cpo
                                                causes the problem. cpo gets set in <scripts.vim> (lines 27 and 294).
                                                Commenting out both lines allows the expected behavior. Even setting
                                                cpo to its own initial value ("aABceFs") causes the problem.

                                                Regards,
                                                Chip Campbell
                                              • Haakon Riiser
                                                [Charles E. Campbell, Jr.] ... Thanks for doing this! I hadn t even started on it yet. :-) The next step would probably be stepping through the source code
                                                Message 23 of 28 , Dec 10, 2003
                                                • 0 Attachment
                                                  [Charles E. Campbell, Jr.]

                                                  > Haakon Riiser once wrote:
                                                  >>
                                                  >> Result: the 22nd line is selected, but the cursor line is not in
                                                  >> the middle of the window...
                                                  >
                                                  > Hello!
                                                  >
                                                  > I've narrowed the problem down a bit; it turns out that setting cpo
                                                  > causes the problem. cpo gets set in <scripts.vim> (lines 27 and 294).
                                                  > Commenting out both lines allows the expected behavior. Even setting
                                                  > cpo to its own initial value ("aABceFs") causes the problem.

                                                  Thanks for doing this! I hadn't even started on it yet. :-) The
                                                  next step would probably be stepping through the source code
                                                  with a debugger, but I'll wait until Bram can comment on it.
                                                  He might know offhand where the problem lies, and how to fix it.

                                                  --
                                                  Haakon
                                                • Bram Moolenaar
                                                  ... I haven t seen something that looks like a bug in this thread. Note that there are some strange Vi-compatibility issues involved with Ex commands that
                                                  Message 24 of 28 , Dec 23, 2003
                                                  • 0 Attachment
                                                    Benji Fisher wrote:

                                                    > I agree that the problems I snipped look like bugs. I hope that
                                                    > Bram does not miss that note when he gets back from vacation.

                                                    I haven't seen something that looks like a bug in this thread. Note
                                                    that there are some strange Vi-compatibility issues involved with Ex
                                                    commands that might be involved here.

                                                    Also remember that when the autocommands for reading a buffer are being
                                                    executed the text isn't displayed yet, thus changing the view might not
                                                    work. Vim decides about the view on the file after it has been loaded
                                                    and after the autocommands. Moving the cursor should always work though.

                                                    --
                                                    From "know your smileys":
                                                    *<|:-) Santa Claus (Ho Ho Ho)

                                                    /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                                    /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
                                                    \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                                    \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
                                                  • Haakon Riiser
                                                    [Bram Moolenaar] ... My autocommand for loading the skeleton is au BufNewFile test.c runtime skel/ctest.vim so I tried adding exe au BufWinEnter .
                                                    Message 25 of 28 , Dec 23, 2003
                                                    • 0 Attachment
                                                      [Bram Moolenaar]

                                                      > Also remember that when the autocommands for reading a buffer are being
                                                      > executed the text isn't displayed yet, thus changing the view might not
                                                      > work. Vim decides about the view on the file after it has been loaded
                                                      > and after the autocommands. Moving the cursor should always work though.

                                                      My autocommand for loading the skeleton is

                                                      au BufNewFile test.c runtime skel/ctest.vim

                                                      so I tried adding

                                                      exe 'au BufWinEnter ' . expand("<amatch>") . ' norm zz'

                                                      as the last line in skel/ctest.vim (just after moving the cursor),
                                                      and now it works. Btw, is this the recommended way?

                                                      --
                                                      Haakon
                                                    • Bram Moolenaar
                                                      ... Normally that should work. See :help BufWinEnter for when this event is triggered. You could add something to delete the BufWinEnter autocommand after it
                                                      Message 26 of 28 , Dec 23, 2003
                                                      • 0 Attachment
                                                        Haakon Riiser wrote:

                                                        > [Bram Moolenaar]
                                                        >
                                                        > > Also remember that when the autocommands for reading a buffer are being
                                                        > > executed the text isn't displayed yet, thus changing the view might not
                                                        > > work. Vim decides about the view on the file after it has been loaded
                                                        > > and after the autocommands. Moving the cursor should always work though.
                                                        >
                                                        > My autocommand for loading the skeleton is
                                                        >
                                                        > au BufNewFile test.c runtime skel/ctest.vim
                                                        >
                                                        > so I tried adding
                                                        >
                                                        > exe 'au BufWinEnter ' . expand("<amatch>") . ' norm zz'
                                                        >
                                                        > as the last line in skel/ctest.vim (just after moving the cursor),
                                                        > and now it works. Btw, is this the recommended way?

                                                        Normally that should work.
                                                        See ":help BufWinEnter" for when this event is triggered.

                                                        You could add something to delete the BufWinEnter autocommand after it
                                                        has been triggered.

                                                        --
                                                        From "know your smileys":
                                                        *<|:-) Santa Claus (Ho Ho Ho)

                                                        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                                        /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
                                                        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                                        \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
                                                      • Benji Fisher
                                                        ... OK, at the end are some snippets from the thread that still look like bugs to me. There are also some comments from Chip Campbell that I have not
                                                        Message 27 of 28 , Jan 2, 2004
                                                        • 0 Attachment
                                                          On Tue, Dec 23, 2003 at 10:54:00AM +0100, Bram Moolenaar wrote:
                                                          >
                                                          > Benji Fisher wrote:
                                                          >
                                                          > > I agree that the problems I snipped look like bugs. I hope that
                                                          > > Bram does not miss that note when he gets back from vacation.
                                                          >
                                                          > I haven't seen something that looks like a bug in this thread. Note
                                                          > that there are some strange Vi-compatibility issues involved with Ex
                                                          > commands that might be involved here.
                                                          >
                                                          > Also remember that when the autocommands for reading a buffer are being
                                                          > executed the text isn't displayed yet, thus changing the view might not
                                                          > work. Vim decides about the view on the file after it has been loaded
                                                          > and after the autocommands. Moving the cursor should always work though.

                                                          OK, at the end are some snippets from the thread that still look
                                                          like bugs to me. There are also some comments from Chip Campbell that I
                                                          have not verified, and I am not sure whether those questions got
                                                          resolved. I will leave it to him (or maybe someone else) to say whether
                                                          there are still open questions regarding 'cpo' and variations on
                                                          zz/z./M/zt .

                                                          I guess both snippets below refer to the behavior of the 'modified'
                                                          flag when using :r in an autocommand.

                                                          BTW, I am still getting used to mutt+vim . Can anyone with more
                                                          experience suggest a convenient way to gather snippets from several
                                                          saved e-mails?

                                                          --Benji Fisher

                                                          On Sun, Dec 07, 2003 at 11:34:57PM -0500, Benji Fisher wrote:
                                                          > On Mon, Dec 08, 2003 at 12:29:36AM +0100, Haakon Riiser wrote:
                                                          > >
                                                          > > >> The following example triggers the bug here: Create a
                                                          > > >> 25 line skeleton file (~/test.skel), and use the following autocmd:
                                                          > > >>
                                                          > > >> au BufNewFile *.xxx r ~/test.skel | 22 | normal zz
                                                          >
                                                          > I do notice two oddities. First, despite the :r command, the
                                                          > 'modified' option is not set. I am not sure if this is supposed to
                                                          > happen or not, but I would expect the buffer to be marked as modified.
                                                          > If I undo ("u" in Normal mode) then the lines from the skeleton file
                                                          > are removed, and 'modified' is still not set. I can then redo (<C-R>)
                                                          > and undo and ... and it is still not set.

                                                          On Mon, Dec 08, 2003 at 12:09:19PM +0100, Haakon Riiser wrote:
                                                          > I have noticed many strange things while trying to set up these
                                                          > skeleton files. :-) For one, there's the bug I described in
                                                          > vim-dev where :append, :insert and :change always insert an
                                                          > extra blank line when the buffer is empty (the case for :append
                                                          > and :insert) or when it contains less than two lines (:change).
                                                          > Also, when you take a buffer consisting of multiple lines, delete
                                                          > all lines but the first, and :change the last remaining line,
                                                          > Vim inserts a blank line below the new text that is displayed
                                                          > as NonText. In other words, it LOOKS like NonText, but BEHAVES
                                                          > like a blank line (lets you move your cursor over it for example).
                                                          >
                                                          > And something else that seems weird is that when I modify
                                                          > the contents of the buffer with a substitute command in the
                                                          > autocommand,
                                                          >
                                                          > :%s/foo/bar/g
                                                          >
                                                          > the undo history does not register this event. If I undo one
                                                          > time, the substitute command is not undone, but the entire buffer
                                                          > is emptied.
                                                          >
                                                          > --
                                                          > Haakon
                                                        • Bram Moolenaar
                                                          ... When editing a new file the modified flag is not set, so that you can do :quit without trouble. The text you add with the autocommand can be easily
                                                          Message 28 of 28 , Jan 2, 2004
                                                          • 0 Attachment
                                                            Benji Fisher wrote:

                                                            > On Sun, Dec 07, 2003 at 11:34:57PM -0500, Benji Fisher wrote:
                                                            > > On Mon, Dec 08, 2003 at 12:29:36AM +0100, Haakon Riiser wrote:
                                                            > > >
                                                            > > > >> The following example triggers the bug here: Create a
                                                            > > > >> 25 line skeleton file (~/test.skel), and use the following autocmd:
                                                            > > > >>
                                                            > > > >> au BufNewFile *.xxx r ~/test.skel | 22 | normal zz
                                                            > >
                                                            > > I do notice two oddities. First, despite the :r command, the
                                                            > > 'modified' option is not set. I am not sure if this is supposed to
                                                            > > happen or not, but I would expect the buffer to be marked as modified.

                                                            When editing a new file the 'modified' flag is not set, so that you can
                                                            do ":quit" without trouble. The text you add with the autocommand can
                                                            be easily added again, thus that is not a reason to set 'modified'.
                                                            When I would change this I'm sure people will complain that they get a
                                                            "no write since last change" error when using a skeleton.

                                                            If you do want to mark the new buffer as being modified you can set the
                                                            'modified' flag in the autocommand.

                                                            > > If I undo ("u" in Normal mode) then the lines from the skeleton file
                                                            > > are removed, and 'modified' is still not set. I can then redo (<C-R>)
                                                            > > and undo and ... and it is still not set.

                                                            The 'modified' flag is stored and restored with undo and redo commands.

                                                            > On Mon, Dec 08, 2003 at 12:09:19PM +0100, Haakon Riiser wrote:
                                                            > > I have noticed many strange things while trying to set up these
                                                            > > skeleton files. :-) For one, there's the bug I described in
                                                            > > vim-dev where :append, :insert and :change always insert an
                                                            > > extra blank line when the buffer is empty (the case for :append
                                                            > > and :insert) or when it contains less than two lines (:change).
                                                            > > Also, when you take a buffer consisting of multiple lines, delete
                                                            > > all lines but the first, and :change the last remaining line,
                                                            > > Vim inserts a blank line below the new text that is displayed
                                                            > > as NonText. In other words, it LOOKS like NonText, but BEHAVES
                                                            > > like a blank line (lets you move your cursor over it for example).

                                                            I made a remark in the todo list to look into this.

                                                            > > And something else that seems weird is that when I modify
                                                            > > the contents of the buffer with a substitute command in the
                                                            > > autocommand,
                                                            > >
                                                            > > :%s/foo/bar/g
                                                            > >
                                                            > > the undo history does not register this event. If I undo one
                                                            > > time, the substitute command is not undone, but the entire buffer
                                                            > > is emptied.

                                                            I assume this is only when using the BufNewFile autocommand. Starting
                                                            to edit a new file is considered as one action. Thus you can't undo
                                                            part of the autocommands.

                                                            --
                                                            hundred-and-one symptoms of being an internet addict:
                                                            120. You ask a friend, "What's that big shiny thing?" He says, "It's the sun."

                                                            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                                            /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
                                                            \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                                            \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
                                                          Your message has been successfully submitted and would be delivered to recipients shortly.