Why some commands in vim require a colon while some don't?

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 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:

  • perform administrative tasks (writing to disk, switching buffers, opening files…)
  • use cool editing commands like :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

  1. Normal mode
  2. Visual mode
  3. Select mode
  4. Insert mode
  5. cmdLine mode
  6. Ex mode

In Normal mode you don't require to type :, this mode can be reached by pressing Esc.

Tags:

Vim