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

The :next command with directories (bug?)

Expand Messages
  • Manpreet Singh
    Hi, I created this simple function/command to help me open more than 10 files or directories passed in at the vim command line in tabs since vim limits me to
    Message 1 of 4 , May 15, 2013
    • 0 Attachment
      Hi,
      I created this simple function/command to help me open more than 10 files or directories passed in at the vim command line in tabs since vim limits me to maximum 10 with the -p option. It is basically, looping argc() times issuing :tabnew and next commands every time.

      -------------------------------------------------------
      function! TabNewNext(...)
      augroup temptnn
      autocmd!

      " When opening files which may be open elsewhere, open them in read only
      " mode
      au SwapExists * :let v:swapchoice='o'
      augroup end
      try
      if a:0
      let l:limit = abs(a:1)
      else
      let l:limit = 0
      endif
      let i = 0
      " for all files or directories on the (g)vim command line
      " open a new tab and issue the :next command
      while i < argc() && (l:limit == 0 || i < l:limit)
      tabnew
      try
      next
      catch /E16[35]/
      " E163 - There is only one file to edit
      " E165 - Cannot go beyond last file
      tabclose
      exe ':tabp ' . (i + 1)
      break
      endtry
      let i = i + 1
      endwhile
      finally
      augroup! temptnn
      endtry
      endfunction

      com! -nargs=? NT :call TabNewNext(<args>)
      --------------------------------------------------

      This works fine with files, but this fails in weird ways with directories when I do this:

      % mkdir tk11
      % mkdir tk22
      % mkdir tk33
      % mkdir tk44
      % vim tk??

      And then once inside vim

      :NT

      This opens tk11, tk22, tk22, tk33 and tk33 instead ok the usual tk11, tk22, tk33 and tk44 sequence. I've reproduced this with Vim 7.3 on Mac and FreeBSD (and probably Ubuntu also) and see the same behavior everywhere, with or without plugins disabled. What am I doing wrong here or is it a bug?
      Also, vim -p tk?? works just fine.

      Any clues appreciated.

      Thanks
      Manpreet

      --
      --
      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 because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Manpreet Singh
      Bump. Adding vim_dev also. ... -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying
      Message 2 of 4 , May 19, 2013
      • 0 Attachment
        Bump. Adding vim_dev also.

        On Wednesday, May 15, 2013 7:07:08 PM UTC-7, Manpreet Singh wrote:
        > Hi,
        > I created this simple function/command to help me open more than 10 files or directories passed in at the vim command line in tabs since vim limits me to maximum 10 with the -p option. It is basically, looping argc() times issuing :tabnew and next commands every time.
        >
        > -------------------------------------------------------
        > function! TabNewNext(...)
        > augroup temptnn
        > autocmd!
        >
        > " When opening files which may be open elsewhere, open them in read only
        > " mode
        > au SwapExists * :let v:swapchoice='o'
        > augroup end
        > try
        > if a:0
        > let l:limit = abs(a:1)
        > else
        > let l:limit = 0
        > endif
        > let i = 0
        > " for all files or directories on the (g)vim command line
        > " open a new tab and issue the :next command
        > while i < argc() && (l:limit == 0 || i < l:limit)
        > tabnew
        > try
        > next
        > catch /E16[35]/
        > " E163 - There is only one file to edit
        > " E165 - Cannot go beyond last file
        > tabclose
        > exe ':tabp ' . (i + 1)
        > break
        > endtry
        > let i = i + 1
        > endwhile
        > finally
        > augroup! temptnn
        > endtry
        > endfunction
        >
        > com! -nargs=? NT :call TabNewNext()
        > --------------------------------------------------
        >
        > This works fine with files, but this fails in weird ways with directories when I do this:
        >
        > % mkdir tk11
        > % mkdir tk22
        > % mkdir tk33
        > % mkdir tk44
        > % vim tk??
        >
        > And then once inside vim
        >
        > :NT
        >
        > This opens tk11, tk22, tk22, tk33 and tk33 instead ok the usual tk11, tk22, tk33 and tk44 sequence. I've reproduced this with Vim 7.3 on Mac and FreeBSD (and probably Ubuntu also) and see the same behavior everywhere, with or without plugins disabled. What am I doing wrong here or is it a bug?
        > Also, vim -p tk?? works just fine.
        >
        > Any clues appreciated.
        >
        > Thanks
        > Manpreet

        --
        --
        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 because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Ben Fritz
        ... I don t know why it s not working, and I don t have time to try debugging the script, but I do know that Vim doesn t really edit directories at all. There
        Message 3 of 4 , May 19, 2013
        • 0 Attachment
          On Sunday, May 19, 2013 11:06:36 AM UTC-5, Manpreet Singh wrote:
          >
          > > This works fine with files, but this fails in weird ways with directories when I do this:
          >
          > >
          >
          > > % mkdir tk11
          >
          > > % mkdir tk22
          >
          > > % mkdir tk33
          >
          > > % mkdir tk44
          >
          > > % vim tk??
          >
          > >
          >
          > > And then once inside vim
          >
          > >
          >
          > > :NT
          >
          > >
          >
          > > This opens tk11, tk22, tk22, tk33 and tk33 instead ok the usual tk11, tk22, tk33 and tk44 sequence. I've reproduced this with Vim 7.3 on Mac and FreeBSD (and probably Ubuntu also) and see the same behavior everywhere, with or without plugins disabled. What am I doing wrong here or is it a bug?
          >
          > > Also, vim -p tk?? works just fine.
          >

          I don't know why it's not working, and I don't have time to try debugging the script, but I do know that Vim doesn't really edit directories at all.

          There is a standard plugin distributed with Vim called netrw which hooks into Vim to allow it to :edit a directory by calling netrw's :Explore command instead. Or at least, that's how i understand it...I may be wrong. Without netrw or a similar plugin, editing a directory gives an error.

          You can try invoking :Explore or :Sexplore or :Texplore directly from your script, if isdirectory() is true for the file path. I'm not sure whether that would work better or not.

          --
          --
          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 because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Manpreet Singh
          ... Thanks for that Ben. Using :Sexplore worked just fine. Thanks Manpreet -- -- You received this message from the vim_use maillist. Do not top-post! Type
          Message 4 of 4 , May 19, 2013
          • 0 Attachment
            On 5/19/13 7:04 PM, Ben Fritz wrote:
            > On Sunday, May 19, 2013 11:06:36 AM UTC-5, Manpreet Singh wrote:
            >>
            >>> This works fine with files, but this fails in weird ways with directories when I do this:
            >>
            >>>
            >>
            >>> % mkdir tk11
            >>
            >>> % mkdir tk22
            >>
            >>> % mkdir tk33
            >>
            >>> % mkdir tk44
            >>
            >>> % vim tk??
            >>
            >>>
            >>
            >>> And then once inside vim
            >>
            >>>
            >>
            >>> :NT
            >>
            >>>
            >>
            >>> This opens tk11, tk22, tk22, tk33 and tk33 instead ok the usual tk11, tk22, tk33 and tk44 sequence. I've reproduced this with Vim 7.3 on Mac and FreeBSD (and probably Ubuntu also) and see the same behavior everywhere, with or without plugins disabled. What am I doing wrong here or is it a bug?
            >>
            >>> Also, vim -p tk?? works just fine.
            >>
            >
            > I don't know why it's not working, and I don't have time to try debugging the script, but I do know that Vim doesn't really edit directories at all.
            >
            > There is a standard plugin distributed with Vim called netrw which hooks into Vim to allow it to :edit a directory by calling netrw's :Explore command instead. Or at least, that's how i understand it...I may be wrong. Without netrw or a similar plugin, editing a directory gives an error.
            >
            > You can try invoking :Explore or :Sexplore or :Texplore directly from your script, if isdirectory() is true for the file path. I'm not sure whether that would work better or not.
            >

            Thanks for that Ben. Using :Sexplore worked just fine.

            Thanks
            Manpreet

            --
            --
            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 because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          Your message has been successfully submitted and would be delivered to recipients shortly.