On 8月19日, 下午7时11分, Christian Brabandt <cbli...@256bit.org> wrote: > Hi eliweiq001! > > On Do, 19 Aug 2010, eliweiq001 wrote: > > > I am using a portable edition of gVim in windows. > > I have to open gVim and then open a .c file every time,( for learning > > programing ), so I want a function and map a key to it, then I can > > open the file very quickly. > > Maybe It would be better that the function can both run in windows and > > linux. > > Please don't top poste. > > Here is a simple example: > > #v+ > 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. > > regards > Christian
Thanks very much! And exactly I want to open the lastest modified *.c file. How to put this .c into your function? 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] -- 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