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

Set the cursor position in vim functions

Expand Messages
  • François Désarménien
    Hello, you all, I ve been searching for hours (so I suppose I m stupid as nobody asked it before) : I m writing a function in vim. I finally get a specific
    Message 1 of 10 , Apr 30, 2002
    • 0 Attachment
      Hello, you all,

      I've been searching for hours (so I suppose
      I'm stupid as nobody asked it before) :

      I'm writing a function in vim. I finally get
      a specific position withing the window I want
      the cursor to be moved to.

      I found a way to jump to the correct line as :

      exec lineno

      but I cannot figure how I can move the cursor
      to the column I want.

      Anyone, any idea ?

      Thanks for your time,

      François

      PS: if it is trivial, forgive me...
    • Colin Keith
      ... Colin.
      Message 2 of 10 , Apr 30, 2002
      • 0 Attachment
        On Tue, Apr 30, 2002 at 09:26:58PM +0200, François Désarménien wrote:
        > but I cannot figure how I can move the cursor
        > to the column I want.
        >
        > Anyone, any idea ?

        :help cursor()

        Colin.
      • Hari Krishna Dara
        ... You can use the normal command | to move to a column position, such as 10| to move to column 10. If you want to do this from your function and if the
        Message 3 of 10 , Apr 30, 2002
        • 0 Attachment
          --- Fran�ois D�sarm�nien <francois@...> wrote:
          > Hello, you all,
          >
          > I've been searching for hours (so I suppose
          > I'm stupid as nobody asked it before) :
          >
          > I'm writing a function in vim. I finally get
          > a specific position withing the window I want
          > the cursor to be moved to.
          >
          > I found a way to jump to the correct line as :
          >
          > exec lineno
          >
          > but I cannot figure how I can move the cursor
          > to the column I want.
          >
          > Anyone, any idea ?
          >

          You can use the normal command | to move to a column position, such as

          10|

          to move to column 10. If you want to do this from your function and if the
          column number is in a variable, then you can use exec as,

          exec "normal " . colNo . "|"

          :h bar

          HTH,
          Hari

          __________________________________________________
          Do You Yahoo!?
          Yahoo! Health - your guide to health and wellness
          http://health.yahoo.com
        • Gary Holloway
          Try exe normal . column . | ... -g / FROM: François Désarménien , Apr 30 21:26 2002 ... END: François Désarménien
          Message 4 of 10 , Apr 30, 2002
          • 0 Attachment
            Try

            exe 'normal ' . column . '|'

            :help |

            -g

            / FROM: Fran�ois D�sarm�nien <francois@...>, Apr 30 21:26 2002
            | ABOUT: Set the cursor position in vim functions
            |
            | Hello, you all,
            |
            | I've been searching for hours (so I suppose
            | I'm stupid as nobody asked it before) :
            |
            | I'm writing a function in vim. I finally get
            | a specific position withing the window I want
            | the cursor to be moved to.
            |
            | I found a way to jump to the correct line as :
            |
            | exec lineno
            |
            | but I cannot figure how I can move the cursor
            | to the column I want.
            |
            | Anyone, any idea ?
            |
            | Thanks for your time,
            |
            | Fran�ois
            |
            | PS: if it is trivial, forgive me...
            |
            \ END: Fran�ois D�sarm�nien
          • Hari Krishna Dara
            ... I didn t know this built-in function. It is very interesting because, the help says it doesn t change the jump list, which is very good for scripts to move
            Message 5 of 10 , Apr 30, 2002
            • 0 Attachment
              --- Colin Keith <vim@...> wrote:
              >
              > On Tue, Apr 30, 2002 at 09:26:58PM +0200, Fran�ois D�sarm�nien wrote:
              > > but I cannot figure how I can move the cursor
              > > to the column I want.
              > >
              > > Anyone, any idea ?
              >
              > :help cursor()
              >
              > Colin.

              I didn't know this built-in function. It is very interesting because, the help
              says it doesn't change the jump list, which is very good for scripts to move
              cursor. I will modify my scripts immediately to use this function instead of
              using separate line and column commands.

              Thanks for the reference,
              Hari

              __________________________________________________
              Do You Yahoo!?
              Yahoo! Health - your guide to health and wellness
              http://health.yahoo.com
            • Charles E. Campbell
              ... exe norm! .linenum. G .colnum. | Regards, Chip Campbell -- Charles E Campbell, Jr, PhD _ __ __ Goddard Space Flight Center /
              Message 6 of 10 , Apr 30, 2002
              • 0 Attachment
                Thus saith Fran�ois D�sarm�nien:
                > but I cannot figure how I can move the cursor
                > to the column I want.

                exe 'norm! '.linenum.'G'.colnum.'|'

                Regards,
                Chip Campbell

                --
                Charles E Campbell, Jr, PhD _ __ __
                Goddard Space Flight Center / /_/\_\_/ /
                cec@... /_/ \/_//_/
                PGP public key: http://www.erols.com/astronaut/pgp.html
              • Brett Pershing Stahlman
                Try ... The prototype for the cursor function is as follows: cursor({lnum}, {col}) lnum is 1 based line number, and col is 1-based column number. From within a
                Message 7 of 10 , Apr 30, 2002
                • 0 Attachment
                  Try
                  :help cursor()

                  The prototype for the cursor function is as follows:
                  cursor({lnum}, {col})
                  lnum is 1 based line number, and col is 1-based column number.

                  From within a function, you would invoke the function as follows:
                  call cursor(lnum, col)

                  Hope this helps.

                  Brett S.

                  ----- Original Message -----
                  From: FranXois DXsarmXnien <francois@...>
                  To: <vim@...>
                  Sent: Tuesday, April 30, 2002 2:26 PM
                  Subject: Set the cursor position in vim functions


                  Hello, you all,

                  I've been searching for hours (so I suppose
                  I'm stupid as nobody asked it before) :

                  I'm writing a function in vim. I finally get
                  a specific position withing the window I want
                  the cursor to be moved to.

                  I found a way to jump to the correct line as :

                  exec lineno

                  but I cannot figure how I can move the cursor
                  to the column I want.

                  Anyone, any idea ?

                  Thanks for your time,

                  François

                  PS: if it is trivial, forgive me...
                • Francois Desarmenien
                  Le Tue, 30 Apr 2002 12:35:39 -0700 ... I was just missing the normal prepended, but still wonder what does it stands for... Many thanks, François
                  Message 8 of 10 , May 1, 2002
                  • 0 Attachment
                    Le Tue, 30 Apr 2002 12:35:39 -0700
                    gary@... (Gary Holloway) a ecrit:

                    > Try
                    >
                    > exe 'normal ' . column . '|'

                    I was just missing the "normal " prepended, but
                    still wonder what does it stands for...

                    Many thanks,

                    François
                  • Brett Pershing Stahlman
                    Francois, The reason that ... worked is that when in ex mode (command-line mode), a command consisting of a single number means go to the line indicated by the
                    Message 9 of 10 , May 1, 2002
                    • 0 Attachment
                      Francois,
                      The reason that
                      :exec lineno
                      worked is that when in ex mode (command-line mode), a command consisting of
                      a single number means go to the line indicated by the number. All lines in a
                      vim script represent commands executed on the command line, so if you want
                      to do a normal mode command -
                      e.g., N|, to go to column N from within a vim script, you have to tell vim
                      that the keystrokes are to be executed in normal mode rather than ex mode.
                      The way you do this is to use the normal command.
                      e.g., to go to column 10, you would type

                      :normal 10|

                      Since the arguments to "normal" command are taken literally (i.e., no
                      variable substitution takes place), you must build up the normal command as
                      a string that can be passed to execute command if the column position is a
                      variable.
                      e.g.,
                      :let str = "normal " . col . '|'
                      :execute str

                      or, to do it in one line,
                      :execute "normal " . col . '|'

                      Hope this helps explain it...

                      Brett S.

                      ----- Original Message -----
                      From: Francois Desarmenien <francois@...>
                      To: Gary Holloway <gary@...>
                      Cc: <vim@...>
                      Sent: Wednesday, May 01, 2002 4:22 AM
                      Subject: Re: Set the cursor position in vim functions


                      Le Tue, 30 Apr 2002 12:35:39 -0700
                      gary@... (Gary Holloway) a ecrit:

                      > Try
                      >
                      > exe 'normal ' . column . '|'

                      I was just missing the "normal " prepended, but
                      still wonder what does it stands for...

                      Many thanks,

                      François
                    • Francois Desarmenien
                      Le Wed, 1 May 2002 08:36:07 -0500 ... Yes, it does: now I begin to catch a glimpse of the vim programming philosophy which is quite disconcerting at first
                      Message 10 of 10 , May 1, 2002
                      • 0 Attachment
                        Le Wed, 1 May 2002 08:36:07 -0500
                        "Brett Pershing Stahlman" <brett.stahlman@...> a ecrit:

                        > Hope this helps explain it...

                        Yes, it does: now I begin to catch a glimpse of the vim programming
                        philosophy which is quite disconcerting at first sight... as is its
                        huge documentation, without any critisism in mind.

                        Many thanks for your time and patience, to you and all the others
                        from the list, too.

                        François
                      Your message has been successfully submitted and would be delivered to recipients shortly.