Next: Text Handling, Previous: Commands, Up: Commands

### 4.1 Groundwork

The VI command set is based on the idea of combining motion commands with other commands. The motion command is used as a text region specifier for other commands. We classify motion commands into point commands and line commands.

The point commands are:

> `h`, `l`, `0`, `$`, `w`, `W`, `b`, `B`, `e`, `E`, `(`, `)`, `/`, `?`, ```, `f`, `F`, `t`, `T`, `%`, `;`, `,`, `^`

The line commands are:

> `j`, `k`, `+`, `-`, `H`, `M`, `L`, `{`, `}`, `G`, `'`, `[[`, `]]`, `[]`

Text Deletion Commands (see Deleting Text), Change commands (see Changing Text), even Shell Commands (see Shell Commands) use these commands to describe a region of text to operate on.

Viper adds two region descriptors, `r` and `R`. These describe the Emacs regions (see Basics), but they are not movement commands.

The command description uses angle brackets ‘`<>`’ to indicate metasyntactic variables, since the normal conventions of using simple text can be confusing with Viper where the commands themselves are characters. Watch out where `<` shift commands and `<count>` are mentioned together!!!

‘`<move>`’ refers to the above movement commands, and ‘`<a-z>`’ refers to registers or textmarkers from ‘`a`’ to ‘`z`’. Note that the ‘`<move>`’ is described by full move commands, that is to say they will take counts, and otherwise behave like normal move commands. ‘`<address>`’ refers to Ex line addresses, which include

`. <No address>`
  Current line
`.+n .-n`
  Add or subtract for current line
`number`
  Actual line number, use `.=` to get the line number
`'<a-z>`
  Textmarker
`$`
  Last line
`x,y`
  Where x and y are one of the above
`%`
  For the whole file, same as (1,$).
`/<pat>/`
`?<pat>?`
  Next or previous line with pattern <pat>.

  Note that the pattern is allowed to contain newline character (inserted as `C-qC-j`). Therefore, one can search for patterns that span several lines.

Note that ‘`%`’ is used in Ex commands `:e` and `:r <shell-cmd>` to mean current file. If you want a ‘`%`’ in your command, it must be escaped as ‘`\%`’. Note that `:w` and the regular `:r <file>` command doesn't support the meta symbols ‘`%`’ and ‘`#`’, because file history is a better mechanism. Similarly, ‘`#`’ expands to the previous file. The previous file is the first file in `:args` listing. This defaults to previous window in the VI sense if you have one window only.

Others like ‘`<args> -- arguments`’, ‘`<cmd> -- command`’ etc. should be fairly obvious.

Common characters referred to include:

`<sp>`
  Space
`<ht>`
  Tab
`<lf>`
  Linefeed
`<esc>`
  Escape
`<cr>`
  Return, Enter

We also use ‘`word`’ for alphanumeric/non-alphanumeric words, and ‘`WORD`’ for whitespace delimited words. ‘`char`’ refers to any ASCII character, ‘`CHAR`’ to non-whitespace character. Brackets ‘`[]`’ indicate optional parameters; ‘`<count>`’ also optional, usually defaulting to 1. Brackets are elided for ‘`<count>`’ to eschew obfuscation.

Viper's idea of Vi's words is slightly different from Vi. First, Viper words understand Emacs symbol tables. Therefore, all symbols declared to be alphanumeric in a symbol table can automatically be made part of the Viper word. This is useful when, for instance, editing text containing European, Cyrillic, Japanese, etc., texts.

Second, Viper lets you depart from Vi's idea of a word by changing the a syntax preference via the customization widget (the variable `viper-syntax-preference`) or by executing `viper-set-syntax-preference` interactively.

By default, Viper syntax preference is `reformed-vi`, which means that Viper considers only those symbols to be part of a word that are specified as word-symbols by the current Emacs syntax table (which may be different for different major modes) plus the underscore symbol `_`, minus the symbols that are not considered words in Vi (e.g., `,',;, etc.), but may be considered as word-symbols by various Emacs major modes. Reformed-Vi works very close to Vi, and it also recognizes words in other alphabets. Therefore, this is the most appropriate mode for editing text and is likely to fit all your needs.

You can also set Viper syntax preference to `strict-vi`, which would cause Viper to view all non-English letters as non-word-symbols.

You can also specify `emacs` as your preference, which would make Viper use exactly the same notion of a word as Emacs does. In particular, the underscore may not be part of a word in some major modes.

Finally, if `viper-syntax-preference` is set to `extended`, Viper words would consist of characters that are classified as alphanumeric or as parts of symbols. This is convenient for editing programs.

`viper-syntax-preference` is a local variable, so it can have different values for different major modes. For instance, in programming modes it can have the value `extended`. In text modes where words contain special characters, such as European (non-English) letters, Cyrillic letters, etc., the value can be `reformed-vi` or `emacs`. If you consider using different syntactic preferences for different major modes, you should execute, for example,

         (viper-set-syntax-preference nil "extended")

in the appropriate major mode hooks.

The above discussion concerns only the movement commands. In regular expressions, words remain the same as in Emacs. That is, the expressions `\w`, `\>`, `\<`, etc., use Emacs' idea of what is a word, and they don't look into the value of variable `viper-syntax-preference`. This is because Viper avoids changing syntax tables in order to not thwart the various major modes that set these tables.

The usual Emacs convention is used to indicate Control Characters, i.e C-h for Control-h. Do not confuse this with a sequence of separate characters C, -, h!!! The `^` is itself, never used to indicate a Control character.

Finally, we note that Viper's Ex-style commands can be made to work on the current Emacs region. This is done by typing a digit argument before `:`. For instance, typing `1:` will prompt you with something like :123,135, assuming that the current region starts at line 123 and ends at line 135. There is no need to type the line numbers, since Viper inserts them automatically in front of the Ex command.