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

$ in a function

Expand Messages
  • Philippe Saux Picart
    Hello ! I am a new vimer and I am amazed by a strange behavior. If foo is file and if I give the command split foo | $ I get a new window displaying foo and
    Message 1 of 3 , May 18 9:28 AM
    • 0 Attachment
      Hello !

      I am a new vimer and I am amazed by a strange behavior. If foo is
      file and if I give the command

      split foo | $

      I get a new window displaying foo and the cursor on the last line. All
      is OK.

      Now, I write the function ff1() :
      fun! ff1()
      split foo | $
      endfunction

      What do I get when the function ff1() is called ? A new window with foo
      in it, as expected; but the cursor remains on the first line. Why ?

      What can I do to fixe the problem ?
      (I use vim under solaris, and gvim with macOsX.3)

      Thanks for your help.
    • Benji Fisher
      ... Function names should start with capital letters, so I tried FF() instead of ff1(). It worked fine for me. Try ... and see if an autocommand is
      Message 2 of 3 , May 18 9:39 AM
      • 0 Attachment
        On Tue, May 18, 2004 at 06:28:51PM +0200, Philippe Saux Picart wrote:
        > Hello !
        >
        > I am a new vimer and I am amazed by a strange behavior. If foo is
        > file and if I give the command
        >
        > split foo | $
        >
        > I get a new window displaying foo and the cursor on the last line. All
        > is OK.
        >
        > Now, I write the function ff1() :
        > fun! ff1()
        > split foo | $
        > endfunction
        >
        > What do I get when the function ff1() is called ? A new window with foo
        > in it, as expected; but the cursor remains on the first line. Why ?

        Function names should start with capital letters, so I tried FF()
        instead of ff1(). It worked fine for me. Try

        :set verbose=10
        :call FF1()

        and see if an autocommand is repositioning the cursor. No, that would
        not explain why it only happens when called from a function....try it
        anyway.... You do not have any breakpoints defined, do you? What
        version of vim are you using?

        HTH --Benji Fisher
      • Benji Fisher
        ... Please send follow-ups to the list. There may be lurkers who are interested in the answer to your question, and there may be helpful people who want to
        Message 3 of 3 , May 19 6:50 AM
        • 0 Attachment
          On Wed, May 19, 2004 at 10:43:14AM +0200, Philippe Saux Picart wrote:
          > Benji Fisher a écrit :
          >
          > >On Tue, May 18, 2004 at 06:28:51PM +0200, Philippe Saux Picart wrote:
          > >
          > >>Hello !
          > >>
          > >>I am a new vimer and I am amazed by a strange behavior. If foo is
          > >>file and if I give the command
          > >>
          > >> split foo | $
          > >>
          > >>I get a new window displaying foo and the cursor on the last line. All
          > >>is OK.
          > >>
          > >>Now, I write the function ff1() :
          > >> fun! ff1()
          > >> split foo | $
          > >> endfunction
          > >>
          > >>What do I get when the function ff1() is called ? A new window with foo
          > >>in it, as expected; but the cursor remains on the first line. Why ?
          > >
          > >
          > > Function names should start with capital letters, so I tried FF()
          > >instead of ff1(). It worked fine for me. Try
          > >
          > >:set verbose=10
          > >:call FF1()
          > >
          > yes I use FF1(). Sorry for the misspelling.
          > It works fine with ":call FF1()".
          >
          > But the difference with your line is that I give the command
          > :exe FF1()
          > and in this case the cursor remains on the first line.

          Please send follow-ups to the list. There may be lurkers who are
          interested in the answer to your question, and there may be helpful
          people who want to know whether the problem has been resolved.

          That explains it, then. By default, a function returns 0. After
          the function does its work, including going to the last line, you
          perform

          :execute 0

          and this jumps to the first line.

          :help :call
          :help :execute

          HTH --Benji Fisher
        Your message has been successfully submitted and would be delivered to recipients shortly.