and the other clones,
editing functionality is "hardwired"
into the editor. The association between command characters and
what they do is built into the code. For example,
's editing model, derived from emacs
through MicroEMACS, is different.
The editor has defined, named functions, each of which performs a single
editing task, such as
Changing bindings is very easy to do. You use the
bind-key incremental-search / bind-key reverse-incremental-search ?
These commands change the
In addition to pre-defined functions, vile contains a simple programming language that allows you to write procedures. You may then bind the command for executing a procedure to a keystroke sequence. GNU emacs uses a variant of Lisp for its language, which is extremely powerful. vile has a somewhat simpler, less general-purpose language.
Also, as in emacs , the vile command line is very interactive. Many commands display a default value for their operand, which you can edit if not appropriate, or select by hitting [RETURN] . As you type vi mode editing commands, such as those that change or delete characters, you will see feedback about the operation in the status line.
The "amazing" ex
mode that Paul
referred to earlier is best reflected in the behavior of the
As an example, let's assume
you wish to change all instances of perl
everywhere in your file.
In the other editors, you'd simply type
The last prompt line is broken for readability. vile prints it all on one line.
follows through with this style of behavior
on all appropriate ex
commands. For example, the
read command (
is weaker than in the other editors.
For example, you cannot use search patterns to specify
line ranges (
A major mode is a collection of option settings that apply when editing a certain class of file. Many of these options apply on a per-buffer basis, such as the tab-stop settings. The major mode concept was first introduced in vile 7.2, and is more fully developed in 7.4 and 8.0.
has one pre-defined major mode,
Using major modes, you can apply the same features to programs
written in other languages. This example, courtesy of
Tom Dickey, defines a new major mode,
define-mode sh set shsuf "\.sh$" set shpre "^#!\\s*\/.*sh\\>$" define-submode sh comment-prefix "^\\s*/[:#]" define-submode sh comments "^\\s*/\\?[:#]\\s+/\\?\\s*$" define-submode sh fence-if "^\\s*\\<if\\>" define-submode sh fence-elif "^\\s*\\<elif\\>" define-submode sh fence-else "^\\s*\\<else\\>" define-submode sh fence-fi "^\\s*\\<fi\\>"
's procedure language is almost
unchanged from that of MicroEMACS.
Comments begin with a semi-colon or a double quote character.
Environment variable names (editor options) start with a
~if &sequal %curplace "timespace vortex" insert-string "First, rematerialize\n" ~endif ~if &sequal %planet "earth" ;If we have landed on earth... ~if &sequal %time "late 20th century" ;and we are then write-message "Contact U.N.I.T." ~else insert-string "Investigate the situation....\n" insert-string "(SAY 'stay here Sara')\n" ~endif ~elseif &sequal %planet "luna" ;If we have landed on our neighbor... write-message "Keep the door closed" ~else setv %conditions @"Atmosphere conditions outside? " ~if &sequal %conditions "safe" insert-string &cat "Go outside......" "\n" insert-string "lock the door\n" ~else insert-string "Dematerialize..try somewhen else" newline ~endif ~endif
You can store these procedures into a numbered macro, or give them names that can be bound to keystrokes. The above procedure is most useful when using the Tardis vile port. :-)
This more realistic example from Paul Fox
, searching for the word under the cursor in all C
source files. It then puts the results in a buffer named after the word,
and sets things up so that the built-in error finder (
14 store-macro set-variable %grepfor $identifier edit-file &cat "!egrep -n " &cat %grepfor " *.[ch]" ~force rename-buffer %grepfor error-buffer $cbufname ~endm bind-key execute-macro-14 ^A-g
The language is quite capable, including flow control and comparison features, and variables that provide access to a large amount of vile 's internal state. The macros.doc file in the vile distribution describes the language in detail.
Several other, smaller features are worth mentioning:
vile has many other features. The vi finger-feel makes it easy to move to. The programmability provides flexibility, and its interactive nature and use of defaults is perhaps friendlier for the novice than traditional vi .