Some of the commands in vim are given by first typing a colon (:) eg . :wq for saving a file and quitting . While some of the commands don\'t require a colon for example the Rep
The commands that "don't require" a colon are called "normal (mode) commands".
The commands that "require" a colon are called "Ex commands".
Vim, being a modal editor, has many commands that are contextual to the mode you are in. The most obvious effect is that hitting the same key in different contexts may produce different results.
In insert mode, most keys on your keyboard are used to actually input characters into your document.
You have to switch to normal mode to yank, put, delete, move your cursor around… normal mode is where you do the laser-focused editing Vim is famous for and use commands like dcggsi/.*
and so on.
You enter command-line mode by hitting :
in normal/*visual* mode. It is typically used for two things:
:m10
or :t1
or :g/foo/d
…The many commands that you can use in this mode are (very powerful) remnants of Vim's past and are called Ex commands.
In short, neither normal mode commands nor Ex commands start with a colon. The colon is simply used to change modes.
You are in different modes of vim
. There are 6 basic modes in vim
. They are
In Normal
mode you don't require to type :
, this mode can be reached by pressing Esc.
You have to look into the history of vi, the predecessor of Vim, for an explanation. A long time ago, when text editing had to be done with a keyboard and attached printer (called a terminal), there was no mouse, no display other than the paper, and therefore, little interactivity. Editing consisted of short, mnemonic commands via an editor called ex. You issued a command addressing one or several lines (e.g. :substitute/foo/bar
), and the editor obeyed. In case you were not sure about the command's effects, you could :print
some lines.
Time passed, video terminals appeared, and the vi editor incorporated the ex commands (because they were useful and the programmers were used to them), but introduced more interactive commands like delete (x
), insert (i
), and so on. The ex commands are still available in command-line mode, which is started with :
, and concluded with Enter.
Vi and Vim are special in this regard, because they have these different modes where the same keys mean different things depending on which mode one is in. To become proficient in Vim, you have to learn about the different modes, and how to best use them to achieve your editing goals.
:help vim-modes
gives you a starting point into the excellent and comprehensive help facilities.
The most important difference (IMHO) is that the colon commands are treated as words, not individual letters, and they aren't interpreted until you hit enter.
Commands in normal mode are treated as individual letters, each letter has a defined meaning, and they are executed as soon as vim knows what to do with them.
For instance, typing 'de' in normal mode, will delete everything up until the end of the word. But 'de' isn't really a command; it's two commands. "e" moves you to the end of a word, and "d" means "delete something; wait for the next key press to tell you how much to delete." When you type 'd', it waits for you to complete the instruction. As soon as you press 'e', the command executes (without waiting to see if you want to type anything more).
That means in normal mode, you can't have an instruction like "define" or "deliver" or "describe". You'd get as far as typing 'de', and vim would execute the 'de' instruction. By the time you got to the 'f' in define, you'd be starting a new instruction.
But in command line (colon) mode, the commands are treated as words. There could be a command called 'define' and another command called 'describe'. (There isn't, but there could be).
'w' could have been created as a normal mode command, if all it did was save the current file under the current filename. But ':w' does more than that. You can also do ":w new_filename", and you get a 'save as' function. That wouldn't work in normal mode. In normal mode "w new_filename" would save the file ('w'), do nothing (space), try to find the next search term ('n'), move to the next end-of-word position ('e')... and so on.