Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to access vim's command-line arguments in vimscript?

Tags:

vim

I found the answer to this question while writing it, so I've broadened it a little. I wanted to access the --servername argument, in order to create dynamic settings in my .vimrc file.

Through vim's help, I found the v:servername variable, and my script is working. However, now I'm curious if it's possible to access any arbitrary command-line argument. For example, if I wanted to know if vim was in Lisp mode (-l) or Debugging mode (-D), how would I do it? There seems to be no corresponding v: variable for them.

Here are the variables I found by autocompleting :help v:<Tab> enter image description here

Is there a general way to access command-line arguments from vimscript?

like image 942
mwcz Avatar asked Apr 27 '12 20:04

mwcz


People also ask

How do I access command line arguments?

To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments. The value of argc should be non negative. argv(ARGument Vector) is array of character pointers listing all the arguments.

How do you access command line arguments in Ruby?

In your Ruby programs, you can access any command-line arguments passed by the shell with the ARGV special variable. ARGV is an Array variable which holds, as strings, each argument passed by the shell.


1 Answers

Strangely, I think the answer may be "No, there is no direct way to access startup options specified on the command line".

The :args command and argv() can be used to access the filename(s) specified on startup, but that's not what you want.

I see on Vim's forums that someone offered this solution to get the startup command line on Linux:

:exe '!tr "\0" " " </proc/' . getpid() . '/cmdline' 

I assume there's analogous command on Windows. . . .

You can look over that forum thread here:

http://groups.google.com/group/vim_use/browse_thread/thread/43773f27cdc10265/ad17ae8180c0fb6e?show_docid=ad17ae8180c0fb6e

like image 128
Herbert Sitz Avatar answered Oct 11 '22 12:10

Herbert Sitz