views:

68

answers:

2

The useful command

:r!date

is not so useful in gVim for Windows (not cygwin's gVim) because Windows has its own date function which does not do what I want.

so, something like

:r!c:\cygwin\bin\date

would be great. But that's a lot to type. And considering that I might want to call a few things this way, it would be nice to write a function, which I could pass an argument foo and it would run

:r!c:\cygwin\bin\foo

What's the best way to do this? It should be 1) Permanent (stored in vimrc or some startup file) 2) Executed with as few keystrokes as possible. Any suggestions for good places to create mappings are appreciated.

Thanks!

+1  A: 

:h strftime() ?

Otherwise, a longtime ago I wrote system() wrappers in order to execute external programs from vim either on *nix, or on win32-gvim with cygwin's bash or $COMSPEC as &shell.

Luc Hermitte
Specifically, something like `:exe "normal! o" . strftime("%c") . "\\e"` would be equivalent, unless you know a better way?
ephemient
Oh, I guess `o<C-R>=strftime("%c")<CR><ESC>` is shorter. I forgot about that...
ephemient
+2  A: 

I think, a simpler solution for day-to-day use (especially if you interest only one of many system-like commands) would be creating your own synonym-command:

:command! -nargs=1 -range=% RR <line1>,<line2>read! c:\cygwin\bin\<args>

This tells Vim to create a new command named RR that accepts range and one (mandatory) argument. New command just passes arguments to read! prepending c:\cygwin\bin\ to the argument.

You could even provide file completion for files in c:\cygwin\bin\ directory. All you need is to create complete-list function like this:

function! RRComplete(A, L, P)
    return system('dir /b /l c:\cygwin\bin')
endfunction

and then specify name of this function, when creating command:

:command! -nargs=1 -complete=custom,RRComplete -range=% RR <line1>,<line2>read! c:\cygwin\bin\<args>
ib