Vim (text editor)
From Wikipedia, the free encyclopedia
- To find out how to use Vim with Wikipedia, see Wikipedia:Text editor support.
Vim | |
Graphical Vim under GTK2 |
|
Maintainer: | Bram Moolenaar and others |
Stable release: | 7.0 (2006-05-07) [+/-] |
Preview release: | 7.0.219 (2007-03-17) [+/-] |
OS: | Amiga, Linux, Mac OS X, Windows, OpenVMS, OS/2, Unix |
Use: | Text editor |
License: | GPL-compatible charityware |
Website: | http://www.vim.org/ |
Vim, which stands for Vi IMproved, is an open source, multiplatform text editor extended from vi. It was first released by Bram Moolenaar in 1991. Since then, numerous features have been added to Vim, many of which are helpful in editing program source code. Vim and vi are the most popular editors for programmers and users of Unix-like operating systems, and Emacs was rated third in a 2003 readers choice survey.[1]
Contents |
[edit] Learning to use Vim
For many users Vim may have a steep learning curve, meaning learning is slow initially but once the user gets a grasp of the basics they progress quickly and their editing becomes more efficient.[2] To facilitate this, there is the Vim tutorial for beginners, usually invoked by typing "vimtutor
" on the Unix command line or clicking on the Vim tutor icon on the Windows desktop. There is also the Vim Users' Manual that details the basic and more advanced Vim features which can be read by typing ":help user-manual
" within Vim.
New users should also learn how to navigate and understand the conventions of the Vim help system by reading the main help file by typing ":help
" without any arguments.
[edit] Modal editing
As a descendant of vi, Vim is modal—a design choice which tends to confuse new users. All editors are modal in the general sense of having to distinguish insert and command inputs, but most others implement that modality through very different methods: command menus (mouse or keyboard driven), meta keys (simultaneous use of multiple keys, usually involving control key (CTRL) or alt key (ALT)), and mouse input. Vim, following vi, is unique in that the entire keyboard is switched into and out of these modes. This allows, but does not require, one to perform all editing functions with no use of the mouse or menus and minimal use of meta keys. For touch-typists and those averse to the mouse, this can be a great benefit in power and efficiency.
Vim has six basic modes and five variants of the basic modes:[3]
[edit] Normal
In normal mode one can enter all the editor commands such as cursor movement, text deletion, etc. Vim starts in this mode by default. This is contrary to what many new users expect.
Vim's power derives primarily from its extensive normal mode commands, many of them requiring an operator to complete. For example, the normal mode command "dd
" deletes the line the cursor is currently on, but "d
" can be followed by a motion command instead of another "d
" such as the line down key ("j
") to delete the current and the next line. A count can also be provided; "2dd
" (repeat 'dd' twice) does the same thing as "dj
". Once the user learns various movement/jump commands and other normal mode editing commands and how they can be combined, their editing often becomes much more efficient than users of "modeless" editors.
From normal mode one can enter insert mode any number of ways; the most common are to press "a
" (append) or "i
" (insert).
[edit] Operator-pending
In this sub-mode of normal mode an operator command has been started and Vim is waiting for a "motion" to complete it. Vim also supports special "text objects" in place of motions in operator-pending mode, which can include "aw
" for a word, "as
" for a sentence, "ap
" for a paragraph, etc.
For example, "d2as
" in normal mode deletes the current sentence and the next, and in visual mode, "apU
" converts the current paragraph to uppercase.
[edit] Insert Normal
This mode is entered when control-o is pressed in insert mode. It behaves like normal mode but only lets the editor execute a single command before Vim returns to insert mode.
[edit] Visual
This behaves much like normal mode, but the movement commands extend highlighted text. The highlighting can be by characters, lines, or a block of text. When a non-movement command is used it is performed on the highlighted area. Vim's "text objects" can be used in this mode as motion commands as well.
[edit] Insert Visual
This is entered from insert normal mode by pressing control-o then starting a visual selection. After the visual selection ends Vim returns to insert mode.
[edit] Select
This is similar to modeless editors—one can highlight text with the mouse and the cursor keys, but typing a character causes Vim to replace the highlighted area with the typed character and enter insert mode.
[edit] Insert Select
This mode is usually entered by dragging the mouse or using a shifted arrow key in insert mode. After the selection ends Vim returns to insert mode.
[edit] Insert
In this mode most keys on the keyboard insert text into the buffer. Most new users expect text editors to maintain this behavior throughout the editing session.
From insert mode one can go back to normal mode by pressing the escape key (ESC).
[edit] Replace
This is a special insert mode where one can do the same things as one would do in insert mode, but each character typed overwrites an existing character in the buffer.
[edit] Command-line
In command-line mode one can enter one line which is interpreted as a command (":
" key), search ("/
" and "?
" keys), or a filter command ("!
" key). Afterward Vim returns to the previous mode it was in, which is usually Normal mode.
[edit] Ex mode
This is like command-line mode, but one can enter multiple commands; one leaves 'ex mode' by typing "visual
".
[edit] Evim
Evim is a special GUI mode that tries to behave more like a "modeless" editor where the editor starts and stays in insert mode and the user has to use the menus, mouse, and keyboard control keys, such as the arrow keys. This mode can be enabled by typing "evim
" or "vim -y
" on the command line. In Windows there is usually an Evim icon on the desktop.
[edit] Customization
Part of Vim's power is that it can be extensively customized. For example the basic interface can be controlled by the many options available (":help options
"). Additionally the user can define personalized key mappings—often called macros—to automate sequences of keystrokes, or even call internal or user defined functions (":help map.txt
").
[edit] Vim script
There are many plugins available that will extend or add new functionality to Vim. These complex scripts are usually written in Vim's internal scripting language (":help vim-script-intro
"), but they can also be implemented using the Perl, Python, Ruby, Tcl, etc. interfaces that can be included in Vim at compile time.
[edit] Features and improvements over vi
Some of the main features of Vim and improvements of Vim over vi:[3]
- Free, Open-Source software; the original BSD vi was derived from the Unix ed editor and therefore was available (in binary and source form) only to licencees of Unix. However, the 2.xBSD version has since been relicenced and is also freely available.
- Vim is almost fully vi compatible (in compatible mode, which is on by default if a .vimrc doesn't exist)
- Portability: there are versions for:[4]
- Command-line editing and extensive completion
- Comparison of files (vimdiff)
- Comprehensive integrated help system with hypertext via ctags
- Configurable status line
- Editing of compressed files (gzip, bzip2, and zip (Vim 7)) and archive files (tar (Vim 7))
- Extended regular expressions
- Extended scripting and expressions
- Graphical User Interface (GUI) mode
- IDE-like build/review/edit features
- Insert-mode completion
- Mouse sensitive
- Multi-mode folding
- Multiple buffers
- Remote file editing over ssh, FTP, and HTTP
- Scripted plugins
- Session state preservation
- Spell checking
- Split windows—both horizontal and vertical
- Support for Unicode
- Syntax highlighting for hundreds of file types
- Tabbed windows (Vim 7)
- Trans-session history of commands, searches, registers, positions, etc.
- Multi-level undo/redo
- Visual mode selection with character/line/block ranges
[edit] History
Date | Version | Changes and additions |
---|---|---|
1988 | 1.0 | Based on Stevie for the Amiga, named Vi IMitation, never publicly released |
November 2, 1991 | 1.14[5] | First public release for the Amiga on Fred Fish disk #591 |
1992 | 1.22[5] | Port to Unix. Vim now competes with vi. This was when Vim became Vi IMproved |
August 12, 1994 | 3.0[5] | Support for multiple windows |
May 29, 1996 | 4.0[5] | Graphical user interface |
February 19, 1998 | 5.0[5] | Syntax highlighting, basic scripting (user defined functions, commands, etc.) |
April 6, 1998 | 5.1 | Bug fixes, various improvements |
April 27, 1998 | 5.2 | Long line support, file browser, dialogs, popup menu, select mode, session files, user defined functions and commands, tcl interface, etc. |
August 31, 1998 | 5.3 | Bug fixes, etc. |
July 25, 1999 | 5.4 | Basic file encryption, various improvements |
September 19, 1999 | 5.5 | Bug fixes, various improvements |
January 16, 2000 | 5.6 | New syntax files, bug fixes, etc. |
June 24, 2000 | 5.7 | idem |
May 31, 2001 | 5.8 | idem |
September 26, 2001 | 6.0[5] | Folding, plugins, multi-language, etc. |
March 24, 2002 | 6.1 | Bug fixes |
June 1, 2003 | 6.2 | GTK2, Arabic language support, :try command, minor features, bug fixes |
June 7, 2004 | 6.3 | Bug fixes, translation updates, mark improvements |
October 15, 2005 | 6.4 | Bug fixes, updates to Perl, Python, and Ruby support |
May 7, 2006 | 7.0 | Spell checking, code completion, document tabs, current line and column highlighting, undo branches, and more |
(Note that some dates are approximate,[6] development releases are not listed, and many minor version releases are not yet included in this list.)
[edit] See also
- List of text editors
- Comparison of text editors
- Editor war
- Cream – Configuration of the Vim text editor for Windows and GNU/Linux
- List of Unix programs
[edit] References
- ^ Linux Journal: 2003 Readers' Choice Awards (2003-11-01). Retrieved on May 24, 2006.
Linux Journal: 2004 Readers' Choice Awards (2004-11-01). Retrieved on May 24, 2006.
Linux Journal: 2005 Readers' Choice Awards (2005-09-28). Retrieved on May 24, 2006. - ^ Oualline, Steve (April 2001). Vi IMproved (VIM). Sams. ISBN 0-7357-1001-5.
- ^ a b Vim help system (type "
:help
" within vim) - ^ "
:help sys-file-list
"
Vim Online: Downloads. Retrieved on January 7, 2007. - ^ a b c d e f Moolenaar, Bram (2002-01-15). Vim, an open-source text editor. Retrieved on October 24, 2005.
- ^ Dates were taken from the official Vim FTP site.
[edit] External links
- Vim home page – Includes a script archive, tips, community and download links, etc.
- Vimdoc – Online Vim documentation
- Vim FTP site