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

前端 未结 4 678
栀梦
栀梦 2021-02-03 19:58

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

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-03 20:37

    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.

提交回复
热议问题