9.2. Command-Line Syntax

 < Day Day Up > 

The three most common ways of starting a vi session are:

 vi [options] file vi [options] +num file vi [options] +/pattern file

You can open file for editing, optionally at line num or at the first line matching pattern. If no file is specified, vi opens with an empty buffer.

9.2.1. Command-Line Options

Because vi and ex are the same program, they share the same options. However, some options only make sense for one version of the program. Options specific to vim are so marked.


+[ num]

Start editing at line number num, or the last line of the file if num is omitted.


+/ pattern

Start editing at the first line matching pattern. (For ex, this fails if nowrapscan is set in your .exrc startup file, since ex starts editing at the last line of a file.)


-b

Edit the file in binary mode. {vim}


-c command

Run the given ex command upon startup. Only one -c option is permitted for vi; vim accepts up to 10. An older form of this option, +command, is still supported.


--cmd command

Like -c, but execute the command before any resource files are read. {vim}


-C

Solaris vi: Same as -x, but assume the file is encrypted already.

vim: Start the editor in vi-compatible mode.


-d

Run in diff mode. Works like vimdiff. (See vimdiff in Chapter 2.) {vim}


-D

Debugging mode for use with scripts. {vim}


-e

Run as ex (line editing rather than full-screen mode).


-h

Print help message, then exit. {vim}


-i file

Use the specified file instead of the default (~/.viminfo) to save or restore vim's state. {vim}


-l

Enter Lisp mode for running Lisp programs (not supported in all versions).


-L

List files that were saved due to an aborted editor session or system crash (not supported in all versions). For vim, this option is the same as -r.


-m

Start the editor with the write option turned off so that the user cannot write to files. {vim}


-M

Do not allow text in files to be modified. {vim}


-n

Do not use a swap file; record changes in memory only. {vim}


--noplugin

Do not load any plug-ins. {vim}


-N

Run vim in a non-vi-compatible mode. {vim}


-o[ num]

Start vim with num open windows. The default is to open one window for each file. {vim}


-O[ num]

Start vim with num open windows arranged horizontally (split vertically) on the screen. {vim}


-r [ file]

Recovery mode; recover and resume editing on file after an aborted editor session or system crash. Without file, list files available for recovery.


-R

Edit files read-only.


-s

Silent; do not display prompts. Useful when running a script. This behavior also can be set through the older - option. For vim, only applies when used together with -e.


-s scriptfile

Read and execute commands given in the specified scriptfile as if they were typed in from the keyboard. {vim}


-S commandfile

Read and execute commands given in commandfile after loading any files for editing specified on the command line. Shorthand for vim -c 'source commandfile'. {vim}


-t tag

Edit the file containing tag and position the cursor at its definition. (See ctags in Chapter 2 for more information.)


-T type

Set the terminal type. This value overrides the $TERM environment variable. {vim}


-u file

Read configuration information from the specified resource file instead of default .vimrc resource file. If the file argument is NONE, vim will read no resource files, load no plug-ins, and run in compatible mode. If the argument is NORC, it will read no resource files but it will load plug-ins. {vim}


-v

Run in full-screen mode (default for vi).


--version

Print version information, then exit. {vim}


-V[ num]

Verbose mode; print messages about what options are being set and what files are being read or written. You can set a level of verbosity to increase or decrease the number of messages received. The default value is 10 for high verbosity. {vim}


-w rows

Set the window size so rows lines at a time are displayed; useful when editing over a slow dial-up line (or long distance Internet connection). Older versions of vi do not permit a space between the option and its argument. vim does not support this option.


-W scriptfile

Write all typed commands from the current session to the specified scriptfile. The file created can be used with the -s command. {vim}


-x

Prompt for a key that will be used to try to encrypt or decrypt a file using crypt (not supported in all versions).[*]

[*] The crypt command's encryption is weak. Don't use it for serious secrets.


-y

Modeless vi; run vim in insert mode only, without a command mode. This is the same as invoking vim as evim. (See evim in Chapter 2.) {vim}


-Z

Start vim in restricted mode. Do not allow shell commands or suspension of the editor. {vim}

While most people know ex commands only by their use within vi, the editor also exists as a separate program and can be invoked from the shell (for instance, to edit files as part of a script). Within ex, you can enter the vi or visual command to start vi. Similarly, within vi, you can enter Q to quit the vi editor and enter ex.

You can exit ex in several ways:

:x

Exit (save changes and quit).

:q!

Quit without saving changes.

:vi

Enter the vi editor.


     < Day Day Up > 


    Unix in a Nutshell
    Unix in a Nutshell, Fourth Edition
    ISBN: 0596100299
    EAN: 2147483647
    Year: 2005
    Pages: 201

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net