11.2. Important Command-Line Arguments

vim looks at how it was invoked to decide how it should behave. If invoked as ex, it will operate as a line editor. It also allows the Q command from vi mode to switch into ex mode. If invoked as view, it will start in vi mode, but mark each file initially as being read-only.

When invoked as gvim or gview, vim will start the GUI version, under X Windows or in whatever other graphical interface is appropriate. If a leading r is prepended to any of the names, vim enters "restricted" mode, where certain actions are disabled.

vim has a large number of command-line options. The most useful are described here:

-c command

Execute command upon startup. This is the POSIX version of the historical +command syntax, but vim is not limited to positioning commands. (The old syntax is also accepted.) You can give up to ten -c commands.

-R

Start in read-only mode, setting the readonly option.

-r

Recover specified files, or if no files are listed on the command line, list all the files that can be recovered.

-s

Enter batch (script) mode. This is only for ex, and is intended for running editing scripts. This is the POSIX version of the historic "-" argument.

-b

Start in binary mode. This sets a few options that make it possible to edit a binary file.

-f

For the GUI version, stay in the foreground. This should be used by programs that invoke vim and wait for it to finish, such as mail handling programs.

-g

Start the GUI version of vim, if it has been ...

Get Learning the vi Editor, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.