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

Extended version of file:line script

Expand Messages
  • Dr. David Alan Gilbert
    Hi Victor, (and vim list cc d) I posted a script similar to your file:line script to vim@vim.org and Christian Brabandt was good enough to point me at your
    Message 1 of 10 , Jan 2, 2011
    • 0 Attachment
      Hi Victor, (and vim list cc'd)
      I posted a script similar to your file:line script to vim@...
      and Christian Brabandt was good enough to point me at your file:line plugin
      here:
      http://www.vim.org/scripts/script.php?script_id=2184

      My script also deals with file:line: and file:line:column and file:line:column:
      but the original version wasn't as tidy as yours and hadn't taken into account
      things like folding and deleting the original buffer like yours had.

      So please find below a modified version of your script that adds the file:line:column
      varient and allows a : at the end.

      ------------------------------------------------------------------------------
      function! s:gotoline()
      let file = bufname("%")

      if file =~ ':$'
      let file = substitute(file, ':$', "", "")
      endif

      " Lets try with name:line:column
      let names = matchlist( file, '\(.*\):\(\d\+\):\(\d\+\)')
      if len(names) == 0
      " OK, lets try just name:line
      let names = matchlist( file, '\(.*\):\(\d\+\)')
      endif


      if len(names) != 0 && filereadable(names[1])
      let l:bufn = bufnr("%")
      exec ":e " . names[1]
      exec ":" . names[2]
      exec ":bdelete " . l:bufn
      if foldlevel(names[2]) > 0
      exec ":foldopen!"
      endif

      if (names[3])
      exe "normal " . names[3] . "|"
      endif
      endif

      endfunction

      autocmd! BufNewFile *:* nested call s:gotoline()

      ------------------------------------------------------------------------------
      --
      -----Open up your eyes, open up your mind, open up your code -------
      / Dr. David Alan Gilbert | Running GNU/Linux | Happy \
      \ gro.gilbert @ treblig.org | | In Hex /
      \ _________________________|_____ http://www.treblig.org |_______/

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Yegappan Lakshmanan
      Hi, ... The above code using matchlist() can be replaced by the following: let names = split(file, : ) - Yegappan ... -- You received this message from the
      Message 2 of 10 , Jan 2, 2011
      • 0 Attachment
        Hi,

        >
        >        " Lets try with name:line:column
        >        let names =  matchlist( file, '\(.*\):\(\d\+\):\(\d\+\)')
        >        if len(names) == 0
        >                " OK, lets try just name:line
        >                let names =  matchlist( file, '\(.*\):\(\d\+\)')
        >        endif
        >

        The above code using matchlist() can be replaced by the following:

        let names = split(file, ':')

        - Yegappan


        On Sun, Jan 2, 2011 at 4:40 PM, Dr. David Alan Gilbert <dave@...> wrote:
        > Hi Victor, (and vim list cc'd)
        >  I posted a script similar to your file:line script to vim@...
        > and Christian Brabandt was good enough to point me at your file:line plugin
        > here:
        >  http://www.vim.org/scripts/script.php?script_id=2184
        >
        > My script also deals with file:line: and file:line:column and file:line:column:
        > but the original version wasn't as tidy as yours and hadn't taken into account
        > things like folding and deleting the original buffer like yours had.
        >
        > So please find below a modified version of your script that adds the file:line:column
        > varient and allows a : at the end.
        >
        > ------------------------------------------------------------------------------
        > function! s:gotoline()
        >        let file = bufname("%")
        >
        >        if file =~ ':$'
        >                let file = substitute(file, ':$', "", "")
        >        endif
        >
        >        " Lets try with name:line:column
        >        let names =  matchlist( file, '\(.*\):\(\d\+\):\(\d\+\)')
        >        if len(names) == 0
        >                " OK, lets try just name:line
        >                let names =  matchlist( file, '\(.*\):\(\d\+\)')
        >        endif
        >
        >        if len(names) != 0 && filereadable(names[1])
        >                let l:bufn = bufnr("%")
        >                exec ":e " . names[1]
        >                exec ":" . names[2]
        >                exec ":bdelete " . l:bufn
        >                if foldlevel(names[2]) > 0
        >                        exec ":foldopen!"
        >                endif
        >
        >                if (names[3])
        >                        exe "normal " . names[3] . "|"
        >                endif
        >        endif
        >
        > endfunction
        >
        > autocmd! BufNewFile *:* nested call s:gotoline()
        >
        > ------------------------------------------------------------------------------
        > --
        >  -----Open up your eyes, open up your mind, open up your code -------
        > / Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \
        > \ gro.gilbert @ treblig.org |                               | In Hex /
        >  \ _________________________|_____ http://www.treblig.org   |_______/
        >
        > --
        > You received this message from the "vim_use" maillist.
        > Do not top-post! Type your reply below the text you are replying to.
        > For more information, visit http://www.vim.org/maillist.php
        >

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Christian Brabandt
        Hi ... It probably doesn t matter in this case, but in general you should always use :normal! regards, Christian -- You received this message from the
        Message 3 of 10 , Jan 3, 2011
        • 0 Attachment
          Hi

          On Mo, 03 Jan 2011, Dr. David Alan Gilbert wrote:
          > if (names[3])
          > exe "normal " . names[3] . "|"
          > endif

          It probably doesn't matter in this case, but in general you should
          always use :normal!

          regards,
          Christian

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Dr. David Alan Gilbert
          ... Dave -- ... / Dr. David Alan Gilbert | Running GNU/Linux | Happy gro.gilbert @ treblig.org | | In Hex /
          Message 4 of 10 , Jan 3, 2011
          • 0 Attachment
            * Yegappan Lakshmanan (yegappanl@...) wrote:
            > Hi,
            >
            > >
            > >        " Lets try with name:line:column
            > >        let names =  matchlist( file, '\(.*\):\(\d\+\):\(\d\+\)')
            > >        if len(names) == 0
            > >                " OK, lets try just name:line
            > >                let names =  matchlist( file, '\(.*\):\(\d\+\)')
            > >        endif
            > >
            >
            > The above code using matchlist() can be replaced by the following:
            >
            > let names = split(file, ':')

            I think that would break where the filename contained a :

            > - Yegappan

            Dave
            --
            -----Open up your eyes, open up your mind, open up your code -------
            / Dr. David Alan Gilbert | Running GNU/Linux | Happy \
            \ gro.gilbert @ treblig.org | | In Hex /
            \ _________________________|_____ http://www.treblig.org |_______/

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Dr. David Alan Gilbert
            ... Why - what does that do for me? Dave -- ... / Dr. David Alan Gilbert | Running GNU/Linux | Happy gro.gilbert @ treblig.org |
            Message 5 of 10 , Jan 3, 2011
            • 0 Attachment
              * Christian Brabandt (cblists@...) wrote:
              > Hi
              >
              > On Mo, 03 Jan 2011, Dr. David Alan Gilbert wrote:
              > > if (names[3])
              > > exe "normal " . names[3] . "|"
              > > endif
              >
              > It probably doesn't matter in this case, but in general you should
              > always use :normal!

              Why - what does that do for me?

              Dave
              --
              -----Open up your eyes, open up your mind, open up your code -------
              / Dr. David Alan Gilbert | Running GNU/Linux | Happy \
              \ gro.gilbert @ treblig.org | | In Hex /
              \ _________________________|_____ http://www.treblig.org |_______/

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • ZyX
              Reply to message «Re: Extended version of file:line script», sent 17:02:09 03 January 2011, Monday ... For you - nothing, at least now. It just makes your
              Message 6 of 10 , Jan 3, 2011
              • 0 Attachment
                Reply to message «Re: Extended version of file:line script»,
                sent 17:02:09 03 January 2011, Monday
                by Dr. David Alan Gilbert:


                > * Christian Brabandt (cblists@...) wrote:
                > > Hi
                > >
                > > On Mo, 03 Jan 2011, Dr. David Alan Gilbert wrote:
                > > > if (names[3])
                > > >
                > > > exe "normal " . names[3] . "|"
                > > >
                > > > endif
                > >
                > > It probably doesn't matter in this case, but in general you should
                > > always use :normal!
                >
                > Why - what does that do for me?
                For you - nothing, at least now. It just makes your script independent of user
                mappings: pretend that user has remapped `|' to `gg' for some reason. In this
                case ``normal 10|'' will bring you to 10th line, but ``normal! 10|'' will work
                as expected.
              • Dr. David Alan Gilbert
                ... Thanks! Dave -- ... / Dr. David Alan Gilbert | Running GNU/Linux | Happy gro.gilbert @ treblig.org | | In
                Message 7 of 10 , Jan 3, 2011
                • 0 Attachment
                  * ZyX (zyx.vim@...) wrote:
                  > Reply to message «Re: Extended version of file:line script»,
                  > sent 17:02:09 03 January 2011, Monday
                  > by Dr. David Alan Gilbert:
                  >
                  > > Why - what does that do for me?
                  > For you - nothing, at least now. It just makes your script independent of user
                  > mappings: pretend that user has remapped `|' to `gg' for some reason. In this
                  > case ``normal 10|'' will bring you to 10th line, but ``normal! 10|'' will work
                  > as expected.

                  Thanks!

                  Dave


                  --
                  -----Open up your eyes, open up your mind, open up your code -------
                  / Dr. David Alan Gilbert | Running GNU/Linux | Happy \
                  \ gro.gilbert @ treblig.org | | In Hex /
                  \ _________________________|_____ http://www.treblig.org |_______/

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