LinuxCommandLibrary

vim

Edit text files

TLDR

Open a file

$ vim [path/to/file]
copy

Open a file at a specified line number
$ vim +[line_number] [path/to/file]
copy

View Vim's help manual
$ <:>help<Enter>
copy

Save and quit the current buffer
$ [<Esc><Z><Z>|<Esc><:>x<Enter>|<Esc><:>wq<Enter>]
copy

Enter normal mode and undo the last operation
$ <Esc><u>
copy

Search for a pattern in the file (press / to go to next/previous match)
$ </>[search_pattern]<Enter>
copy

Perform a regular expression substitution in the whole file
$ <:>%s/[regular_expression]/[replacement]/g<Enter>
copy

Display the line numbers
$ <:>set nu<Enter>
copy

SYNOPSIS

vim [options] [file ...]

PARAMETERS

+[num]
    Start editing at line num.

+/pattern
    Start editing at the first occurrence of pattern.

-b
    Binary mode.

-d
    Diff mode. Open specified files side-by-side for comparison.

-o[N]
    Open N windows (default: one for each file).

-O[N]
    Like -o but split vertically.

-R
    Read-only mode.

-r
    List swap files and recover crashed sessions.

-u {vimrc}
    Use specific vimrc file instead of default.

-v
    Verbose mode.

-w {scriptout}
    Append all the commands typed to the file scriptout.

-W {scriptout}
    Write all the commands typed to the file scriptout.

DESCRIPTION

Vim is a highly configurable text editor built to enable efficient text editing. It's an improved version of the classic vi editor, popular among programmers and system administrators due to its versatility and extensive customization options. Vim operates in various modes, including normal mode (for commands), insert mode (for typing text), and visual mode (for selecting text). It supports syntax highlighting, code completion, and numerous plugins to enhance functionality. Vim is known for its steep learning curve but offers significant productivity gains once mastered. It's available on most Unix-like systems and is often the default editor.
Vim uses a modal editing paradigm where different keys serve different purposes, depending on the current mode. This allows experienced users to edit files faster than in a modeless editor.
Due to it's footprint, it's available in most linux distributions and can be used in environments, where other editors aren't an option.

CAVEATS

Learning Vim effectively requires time and dedication. Its modal nature can be initially confusing.
Vim uses the .swp files to save the state of the buffer, make sure to have permissions to write in the folder.

MODES OF OPERATION

Vim operates in three main modes:
Normal mode: Used for commands to manipulate text and navigate the file.
Insert mode: Used for inserting and editing text.
Visual mode: Used for selecting text for operations like cut, copy, and paste.

CONFIGURATION

Vim's behavior is highly configurable through the .vimrc file located in the user's home directory. This file allows users to customize key mappings, set options, and load plugins.

HISTORY

Vim (Vi IMproved) was originally developed by Bram Moolenaar in 1991 as an enhancement to the existing vi editor. It quickly gained popularity due to its expanded feature set, including multiple undo levels, syntax highlighting, and plugin support. Over the years, Vim has become one of the most widely used text editors in the Unix and Linux world, known for its efficient editing capabilities and extensive customization options. Development continues with regular updates and improvements driven by a large and active community.

SEE ALSO

vi(1), nano(1)

Copied to clipboard