Back to the command reference

vim

EditorsFundamentals In real Linux

Powerful text editor (vi improved)

Name: vim = Vi IMproved

This command needs a real Linux system; you can practise it in real Linux mode.

Full man page

Description

vim is a powerful modal editor: in normal mode keys are commands (move, delete, copy), in insert mode they type text, and Esc switches between them. That design lets practised users edit very efficiently without leaving the keyboard.

To start, remember: i to type, Esc for normal mode, :wq to save and quit, :q! to quit without saving. Run vimtutor to learn the basics.

Syntax

vim [OPTION]... [FILE]...

Common options

iEnter insert mode
EscBack to normal mode
:w / :q / :wqSave / quit / save and quit
:q!Quit without saving
u / Ctrl+RUndo / redo
dd / yy / pDelete line / copy line / paste
v / VVisual mode by character / line; then d deletes, y copies
/wordSearch for word; n for the next match
:%s/old/new/gReplace old with new everywhere (add c to confirm each)
gg / G / :NGo to the first line / the last / line N
:set nuShow line numbers (:set nonu hides them)
-ROpen read-only (a command-line option)
-dCompare two files (as vimdiff)
-OOpen several files side by side

Examples

  • $ vim notes.txt

    Edit a file

    Explain
  • $ vim +10 app.py

    Open at line 10

    Explain
  • $ vimtutor

    A 30-minute interactive tutorial

    Explain

Related