Friday, March 22, 2013

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

leo <barbosa.leonardo@gmail.com> 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@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: