I am going to write a program which can be run from the command line, at least on *nix systems. I considered using Python or Perl, but why not Vimscript?
Has anybody done this?
What is the best practice for writing this kind of application?
Is there a bootstrap or library?
User interaction will be minimal in my case. The input will be provided as arguments to the executable, and Vim will display text output and do some processing.
My initial attempt
Outputs this when run:
$ ./my_new_app arg1 "broken word" arg3 Retrieved arguments: arg1 broken word arg3 Press ENTER or type command to continue Argument 0 is: arg1 Press ENTER or type command to continue Argument 1 is: broken Press ENTER or type command to continue Argument 2 is: word Press ENTER or type command to continue Argument 3 is: arg3 Press ENTER or type command to continue
There are three issues:
- It breaks the second argument into two arguments due to the space.
- Every time I print something, I must Press ENTER.
- If I pipe the result as in
./myapp 1 2 3 > output.filethen I get "Warning: Output is not to a terminal", and I can't see the Press ENTER prompts, although I still need to fulfil them.
my_new_app (executable file)
#!/bin/bash # Pass the arguments to Vim in a variable, and exec my_new_app.vim vim -c ":let g:arguments_string='$*'" -c ":so $0.vim"
function! s:Print(str) exec '!echo "' . a:str . '"' " This doesn't work so well: I only see the first line. "call system('echo "' . a:str . '"') endfunction call s:Print("Retrieved arguments: " . g:arguments_string) let s:args = split(g:arguments_string, ' ') for i in range(0, len(s:args)) call s:Print("Argument " . i . " is: " . s:args[i]) endfor exit