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

Re: :edit - how to prioritize listed files by their extension?

Expand Messages
  • Paul Isambert
    ... Not that I know of; wildmenu doesn’t allow custom completion (that would be a nice feature request). What you can do is write your own command with
    Message 1 of 5 , Mar 22, 2013
    • 0 Attachment
      leo <barbosa.leonardo@...> a écrit:
      > Hi,
      >
      > Is there a way of prioritize the listed files by their extension after a ":e<tab>"? I mean, like in zsh completion system?

      Not that I know of; 'wildmenu' doesn’t allow custom completion (that
      would be a nice feature request).

      What you can do is write your own command with custom completion;
      admittedly not really practical. As an example (not really tested):

      com! -nargs=? -bang -complete=customlist,s:Complete Edit edit<bang> <args>

      function! s:Complete (A, L, P)
      if a:A =~ '\*$'
      let A = a:A
      else
      let A = a:A . '*'
      endif
      let l = split(glob(A), '\n')
      let i = 0
      while i < len(l)
      if isdirectory(l[i])
      let l[i] .= "/"
      endif
      let i += 1
      endwhile
      return sort(l, "s:sort")
      endfunction

      function! s:sort (a, b)
      " Sorts dirs before files.
      if a:a =~ "/$" && a:b !~ "/$"
      return -1
      elseif a:a !~ "/$" && a:b =~ "/$"
      return 1
      else
      " Items are of the same type.
      let [f1, e1] = matchlist(a:a, '\([^.]*\)\.\?\(.*\)')[1:2]
      let [f2, e2] = matchlist(a:b, '\([^.]*\)\.\?\(.*\)')[1:2]
      " Sorts by extension.
      if e1 < e2
      return -1
      elseif e1 > e2
      return 1
      " Sorts by filename.
      elseif f1 < f2
      return -1
      elseif f1 > f2
      return 1
      endif
      endif
      endfunction

      Best,
      Paul

      --
      --
      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.
    • Tim Chase
      ... I don t know how zsh does it, but the suffixes option allows you to specify extensions of a lower-priority so that they get shown afterward. My .vimrc
      Message 2 of 5 , Mar 22, 2013
      • 0 Attachment
        On 2013-03-21 12:49, leo wrote:
        > Is there a way of prioritize the listed files by their extension
        > after a ":e<tab>"? I mean, like in zsh completion system?

        I don't know how zsh does it, but the 'suffixes' option allows you to
        specify extensions of a lower-priority so that they get shown
        afterward. My .vimrc on my work machine has

        set suffixes+=.pyc
        set suffixes+=.pyo

        to prevent vim from suggesting Python's compiled output before the
        actual .py source file.

        -tim


        --
        --
        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.
      • Leonardo Barbosa
        The set suffixes indeed order, but it doens t suggest the first element of the list, which requires me to press twice. (I know that sounds i m
        Message 3 of 5 , Mar 22, 2013
        • 0 Attachment
          The "set suffixes" indeed order, but it doens't suggest the first
          element of the list, which requires me to press <tab> twice. (I know
          that sounds i'm completely lazy...). Perhaps 'set wildignore' is the
          best vi can do at this moment.

          Thanks anyway.



          On Fri, Mar 22, 2013 at 7:23 AM, Tim Chase <vim@...> wrote:
          > On 2013-03-21 12:49, leo wrote:
          >> Is there a way of prioritize the listed files by their extension
          >> after a ":e<tab>"? I mean, like in zsh completion system?
          >
          > I don't know how zsh does it, but the 'suffixes' option allows you to
          > specify extensions of a lower-priority so that they get shown
          > afterward. My .vimrc on my work machine has
          >
          > set suffixes+=.pyc
          > set suffixes+=.pyo
          >
          > to prevent vim from suggesting Python's compiled output before the
          > actual .py source file.
          >
          > -tim
          >
          >

          --
          --
          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.
        • Tim Chase
          ... Perhaps you misunderstand the purpose of suffixes ? It s a way of designating less-than-interesting files, so they always get shifted to the end of the
          Message 4 of 5 , Mar 22, 2013
          • 0 Attachment
            On 2013-03-22 13:24, Leonardo Barbosa wrote:
            > The "set suffixes" indeed order, but it doens't suggest the first
            > element of the list, which requires me to press <tab> twice.

            Perhaps you misunderstand the purpose of 'suffixes'? It's a way of
            designating less-than-interesting files, so they always get shifted
            to the end of the list you <tab> through. So if you want certain
            suffixes prioritized (so you only have to <tab> once), then you
            should put the extension(s) that you *don't* want into 'suffixes'.

            Not messing with zsh, I may be completely misunderstanding you, in
            which case feel free to ignore this :-)

            -tim


            --
            --
            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.