Re: How to open the latest modified file
On 8月23日, 上午10时16分, Benjamin R. Haskell v...@benizi.com wrote: On Sun, 22 Aug 2010, eliweiq001 wrote: I want to ask you something else. :exe OpenLastModified(q-args) You see, OpenLastModified is a function, but, why we can only use :exe but not :call ? I've tried :call but it won't work. OpenLastModified returns a string-form command to be executed. This works well with expr mappings. See: :help :map-expression You should be able to ':echo OpenLastModified(arguments-here)', if you're testing to see what it would execute. Otherwise, what I said above is the reason ':call' doesn't work (You can't execute a string directly). -- Best, Ben Oh! I see ! Thanks! -- 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
Re: How to open the latest modified file
Hi Christian ! On 8月20日, 下午7时19分, Christian Brabandt cbli...@256bit.org wrote: Hi eliweiq001! On Fr, 20 Aug 2010, eliweiq001 wrote: On 8月20日, 下午4时35分, Christian Brabandt cbli...@256bit.org wrote: Hi eliweiq001! 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 Because I don't understand the function, I just copy it and use it. When I type :call OpenL and press Tab, it will change to :call OpenLastModified( another Tab, it will change to:call OpenLastModified(1() one more Tab, it will be:call OpenLastModified(10() one more Tab, it will be:call OpenLastModified(100() one more Tab, it will be:call OpenLastModified(101( .. So I don't know what does it mean. If I :call OpenLastModified() it will say that Undefined variable: a:1 . If I put a directory to be the parameter, it will say Undefined variable too. Such as :call OpenLastModified(D:\) in windows, it will say E121: Undefined variable: D: E116: Invalid arguments for function OpenLastModified Then I try :call OpenLastModified(.\) , it will say E15: Invalid expression: .\) E116: Invalid arguments for function OpenLastModified I see. There was 1 small problem. Use this slightly changed version (which only selects C-files): fun! OpenLastModified(...) let path=(!empty(a:1) ? a:1 : getcwd() ) let files=split(glob(path . '/*.c', 1), '\n') call filter(files, '!isdirectory(v:val)') call sort(files, CompareLastModified) if !empty(files) return :tabe . files[-1] else return :echoerr 'No files found' endif 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 OpenLastModified(q-args) So please in the command prompt type :EditLastModified followed by Carriage Return. This will open the last modified file from the current working directory (basically the directory that :pwd returns). You can however optionally open the last modified file from a different directory. Therefore you type: :EditLastModified followed by a space followed by a directory, e.g. D:\ followed by a return, e.g: :EditLastModified D:\ When using the 2nd form, you can use your Tab key to complete a directory. Sorry for the confusion. regards, Christian I want to ask you something else. :exe OpenLastModified(q-args) You see, OpenLastModified is a function, but, why we can only use :exe but not :call ? I've tried :call but it won't work. regards. eliweiq001 -- 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
Re: How to open the latest modified file
On Sun, 22 Aug 2010, eliweiq001 wrote: I want to ask you something else. :exe OpenLastModified(q-args) You see, OpenLastModified is a function, but, why we can only use :exe but not :call ? I've tried :call but it won't work. OpenLastModified returns a string-form command to be executed. This works well with expr mappings. See: :help :map-expression You should be able to ':echo OpenLastModified(arguments-here)', if you're testing to see what it would execute. Otherwise, what I said above is the reason ':call' doesn't work (You can't execute a string directly). -- Best, Ben -- 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
Re: How to open the latest modified file
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
Re: How to open the latest modified file
On 8月20日, 下午4时35分, Christian Brabandt cbli...@256bit.org wrote: Hi eliweiq001! 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 Because I don't understand the function, I just copy it and use it. When I type :call OpenL and press Tab, it will change to :call OpenLastModified( another Tab, it will change to:call OpenLastModified(1() one more Tab, it will be:call OpenLastModified(10() one more Tab, it will be:call OpenLastModified(100() one more Tab, it will be:call OpenLastModified(101( .. So I don't know what does it mean. If I :call OpenLastModified() it will say that Undefined variable: a:1 . If I put a directory to be the parameter, it will say Undefined variable too. Such as :call OpenLastModified(D:\) in windows, it will say E121: Undefined variable: D: E116: Invalid arguments for function OpenLastModified Then I try :call OpenLastModified(.\) , it will say E15: Invalid expression: .\) E116: Invalid arguments for function OpenLastModified -- 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
Re: How to open the latest modified file
By looking at message-id of your emails, it seems you actually sent this and also other posts several times. May I ask what was the reason? -- regards, GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 -- 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
Re: How to open the latest modified file
On 8月20日, 下午6时30分, bill lam cbill@gmail.com wrote: By looking at message-id of your emails, it seems you actually sent this and also other posts several times. May I ask what was the reason? -- regards, GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 Yes, I am using google groups to post. I have two posts which has been posted repeatedly for several ones. The first post is because of the network problem, but later I delete them. (How can you see them?) The second time is because , what I have posted looks not so good, I want to compose it, but it seems that I can't edit it after posting. So I posted a new one and delete the older one. -- 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
Re: How to open the latest modified file
Hi eliweiq001! On Fr, 20 Aug 2010, eliweiq001 wrote: On 8月20日, 下午4时35分, Christian Brabandt cbli...@256bit.org wrote: Hi eliweiq001! 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 Because I don't understand the function, I just copy it and use it. When I type :call OpenL and press Tab, it will change to :call OpenLastModified( another Tab, it will change to:call OpenLastModified(1() one more Tab, it will be:call OpenLastModified(10() one more Tab, it will be:call OpenLastModified(100() one more Tab, it will be:call OpenLastModified(101( .. So I don't know what does it mean. If I :call OpenLastModified() it will say that Undefined variable: a:1 . If I put a directory to be the parameter, it will say Undefined variable too. Such as :call OpenLastModified(D:\) in windows, it will say E121: Undefined variable: D: E116: Invalid arguments for function OpenLastModified Then I try :call OpenLastModified(.\) , it will say E15: Invalid expression: .\) E116: Invalid arguments for function OpenLastModified I see. There was 1 small problem. Use this slightly changed version (which only selects C-files): fun! OpenLastModified(...) let path=(!empty(a:1) ? a:1 : getcwd() ) let files=split(glob(path . '/*.c', 1), '\n') call filter(files, '!isdirectory(v:val)') call sort(files, CompareLastModified) if !empty(files) return :tabe . files[-1] else return :echoerr 'No files found' endif 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 OpenLastModified(q-args) So please in the command prompt type :EditLastModified followed by Carriage Return. This will open the last modified file from the current working directory (basically the directory that :pwd returns). You can however optionally open the last modified file from a different directory. Therefore you type: :EditLastModified followed by a space followed by a directory, e.g. D:\ followed by a return, e.g: :EditLastModified D:\ When using the 2nd form, you can use your Tab key to complete a directory. Sorry for the confusion. 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
Re: How to open the latest modified file
Hi Christian ! On 8月20日, 下午7时19分, Christian Brabandt cbli...@256bit.org wrote: Hi eliweiq001! I see. There was 1 small problem. Use this slightly changed version (which only selects C-files): fun! OpenLastModified(...) let path=(!empty(a:1) ? a:1 : getcwd() ) let files=split(glob(path . '/*.c', 1), '\n') call filter(files, '!isdirectory(v:val)') call sort(files, CompareLastModified) if !empty(files) return :tabe . files[-1] else return :echoerr 'No files found' endif 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 OpenLastModified(q-args) So please in the command prompt type :EditLastModified followed by Carriage Return. This will open the last modified file from the current working directory (basically the directory that :pwd returns). You can however optionally open the last modified file from a different directory. Therefore you type: :EditLastModified followed by a space followed by a directory, e.g. D:\ followed by a return, e.g: :EditLastModified D:\ When using the 2nd form, you can use your Tab key to complete a directory. Sorry for the confusion. regards, Christian It work! I am so happy! Thank you so much!! -- 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
Re: How to open the latest modified file
* eliweiq001 eliweiq...@gmail.com [2010-08-19 09:51]: I want to write a function in vimrc that can open the lastest modified file in the current directory, Is it easy to do it? How to write it? what is your goal? does it have to be a function within vim? is this a test for programming in vim? because most good shells will easily allow to specify it. Sven -- 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
Re: How to open the latest modified file
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. On 8月19日, 下午3时54分, Sven Guckes guc...@guckes.net wrote: * eliweiq001 eliweiq...@gmail.com [2010-08-19 09:51]: I want to write a function in vimrc that can open the lastest modified file in the current directory, Is it easy to do it? How to write it? what is your goal? does it have to be a function within vim? is this a test for programming in vim? because most good shells will easily allow to specify it. Sven -- 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
Re: How to open the latest modified file
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 -- 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
Re: How to open the latest modified file
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! I will try it. And exactly I want to open the lastest modified *.c file. How to put this .c into your function? -- 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
Re: How to open the latest modified file
Чтв, 19 Авг 2010, eliweiq001 писал(а): On 8月19日, 下午7时11分, Christian Brabandt cbli...@256bit.org wrote: [---=| Quote block shrunk by t-prot: 27 lines snipped |=---] 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! I will try it. And exactly I want to open the lastest modified *.c file. How to put this .c into your function? If you want to open the latest modified file by vim, you the use the RecentFiles.vim plugin (there are some others, but I cannot recall their names), which can display a list of most recently used files. -- regards, GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 -- 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
Re: How to open the latest modified file
On 8月19日, 下午10时13分, bill lam cbill@gmail.com wrote: Чтв, 19 Авг 2010, eliweiq001 писал(а): If you want to open the latest modified file by vim, you the use the RecentFiles.vim plugin (there are some others, but I cannot recall their names), which can display a list of most recently used files. -- regards, GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 I know, but I just want to open the latest modified *.c file in different dir. So the RecentPlugin can't do it. -- 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
Re: How to open the latest modified file
On 8月19日, 下午10时13分, bill lam cbill@gmail.com wrote: Чтв, 19 Авг 2010, eliweiq001 писал(а): If you want to open the latest modified file by vim, you the use the RecentFiles.vim plugin (there are some others, but I cannot recall their names), which can display a list of most recently used files. -- regards, GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 I know, but I just want to open the latest modified *.c file in different dir. So the RecentPlugin can't do it. -- 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
Re: How to open the latest modified file
On 8月19日, 下午10时13分, bill lam cbill@gmail.com wrote: Чтв, 19 Авг 2010, eliweiq001 писал(а): If you want to open the latest modified file by vim, you the use the RecentFiles.vim plugin (there are some others, but I cannot recall their names), which can display a list of most recently used files. -- regards, GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 I know, but I just want to open the latest modified *.c file in different dir. So the RecentPlugin can't do it. -- 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
Re: How to open the latest modified file
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