Hi eliweiq001! On Do, 19 Aug 2010, eliweiq001 wrote:
> On 8月19日, 下午7时11分, Christian Brabandt <cbli...@256bit.org> wrote: > > fun! OpenLastModified(...) > > let path=(a:1 ? a:1 : getcwd() ) > > let files=split(glob(path . '/*', 1), '\n') > > call filter(files, '!isdirectory(v:val)') > > call sort(files, "CompareLastModified") > > return files[-1] > > endfun > > > > func! CompareLastModified(a,b) > > return getftime(a:a) == getftime(a:b) ? 0 : getftime(a:a) > getftime > > (a:b) ? 1 : -1 > > endfunc > > > > com! -complete=dir -nargs=? EditLastModified :exe ':tabe ' . > > OpenLastModified(<q-args>) > > #v- > > > > Use :OpenLastModified to open the last modified file in your current > > working directory or optionally use tab completion to use any other > > directory. > > > > Thanks very much! > And exactly I want to open the lastest modified *.c file. > How to put this .c into your function? Search for the * and replace it by *.c > And besides, when I > :call OpenLastModified(1) > > there is an error: > > Error detected while processing function OpenLastModified: > Line 5: > E684: list index out of range: -1 > E15: Invalid expression: files[-1] > What make you think, you were supposed to call it with the parameter 1? The optionally parameter to that function is supposed to be a path. Therefore the command :OpenLastModified was provided, that allows for tabcompleting a directory optionally. 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