Vim (or "Vi IMproved") is a console-based multi-mode (modal) text editor. It is widely used and available by default on all Unix, Linux, and Apple OS X systems. Vim has a large active community and a wide user base. The editor supports all popular programming languages, and many plugins are available to extend its features.
Developers like the editor for its speed, many configuration options, and powerful expression based editing. In "command" mode the editor is controlled by keyboard commands, so the user is not distracted by a GUI or mouse pointer.
Vim is based on the earlier Unix "vi" editor created in the seventies and it has been in continuous development since 1991. With macros and plugins the editor offers most of the features of a modern IDE. It is also uniquely capable of processing large amounts of text with its scripting language (vimscript) and regular expressions.
Main Topics:
When called from the command line, multiple files can be provided in the argument and vim will create one split for each file. When called from ex mode, only one file can be opened per invocation of the command.
To increment and decrement things like 11:59AM
, 3rd
, and XVIII
, use the plugin vim-speeddating
See vimcast 1 video
This automatic reload will only happen if you edit your vimrc
in a version full version of vim which supports autocmd
.
A plugin is a script or set of scripts that changes Vim's default behavior, either by adding non-existing features or by extending existing features.
Often added "non-existing features" include:
Often extended "existing features" include:
Folding causes multiple lines of text to be collapsed and displayed as a single line. It is useful for hiding portions of a document considered unimportant for the current task. Folding is purely a visual change to the document: the folded lines are still present, unchanged.
A fold is persistent. Once created, a fold can be opened and closed without needing to re-create it. When closed, folds can be moved over or yanked and put as if they were a single line, even though the underlying operation will operate on all of the text underneath the fold
The ^M
character stands for a carriage return in Vim (<c-m>
or just <CR>
). Vim displays this character when at least on line in the file uses LF
line endings. In other words, when Vim consider a file to have fileformat=unix
but some lines do have carriage returns (CR
), the carriage returns are displayed as ^M
.
A file that has a single line with LF
line ending and several lines with CRLF
line endings is most often created by wrongly editing a file created on a MSDOS based system. For example, by creating a file under an MSDOS operating system, copying it to a UNIX based system, and then prepending a hash-bang sting (e.g. #!/bin/sh
) using tools on the UNIX based operating system.
Vim's "global" command is used to apply an ex command to every line where a regex matches.
A text object in Vim is another way to specify a chunk of text to operate on. They can be used with operators or in visual mode, instead of motions.
Surround autocmd
commands
autocmd
is an additive command, and you probably don't want this behaviour by default.
For example, if you re-source your .vimrc
a few times while editing it, vim can slow down.
Here's proof:
:autocmd BufWritePost * if &diff | diffupdate | endif " update diff after save
:autocmd BufWritePost * if &diff | diffupdate | endif " update diff after save
If you now type :autocmd BufWritePost *
, you'll see both lines in the output, not just one. Both get executed.
To avoid this behaviour, surround all your autocmd
s as follows:
if has ('autocmd') " Remain compatible with vi which doesn't have autocmd
augroup MyDiffUpdate " A unique name for the group. DO NOT use the same name twice!
autocmd! " Clears the old autocommands for this group name
autocmd BufWritePost * if &diff | diffupdate | endif " Update diff after save
" ... etc ...
augroup END
endif
Command-line mode is entered through normal mode. You will know you are in command-line mode when there is a :
in the bottom left corner of your terminal window.
Normal mode is the default mode of vi/vim and can be switched to by pressing the ESC.
Vi/Vim have built-in checks to prevent unsaved work from being lost and other useful features. To bypass these checks, use the override !
in your command.
In Vi/Vim it is possible to have more than one file displayed (in different windows) at the same time. Use a
to close all the opened windows.
The commands in a Vimscript file are executed in command mode
by default. Therefore all non-command mode
directives should be prefixed.
See sorting in the vim manual for the canonical explanation
This Topic is about Source Code mirrors, Books, Vim-Wikis. It is NOT about Blog entries, Wikipedia, Tutorials. The resources should not be opinion based.
execute :h pattern
to see a lot of regex related information