Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get command line arguments from VimL?

Tags:

vim

argv

argc

How can I access the arguments that were given to Vim on the command line under Windows?

I'm looking for the the equivalent to argv[] in C.

Under linux you can read /proc/self/cmdline. Example:

vim -c ":echo split( readfile( \"/proc/self/cmdline\", 1 )[0], \"\n\" )"

print

[
  'vim',
  '-c',
  ':echo split( readfile( "/proc/self/cmdline", 1 )[0], "\n" )'
]

argc() and argv() don't work. They just return number of files. Example:

vim -c ':echo "argc:" . argc() . ", argv:" . string( argv() )' file1 file2

print

argc:2, argv:['file1', 'file2']
like image 836
Rovire Pugerou Avatar asked Mar 23 '23 17:03

Rovire Pugerou


1 Answers

:help argc()
:help argv()
:help argidx()

And maybe also :help argument-list, just to be sure.

Simple example:

for arg in argv()
  echo arg
endfor
like image 61
mhinz Avatar answered Apr 06 '23 12:04

mhinz